importPackage ( java. io ) ; importPackage ( java. lang ) ; // your code goes here //egg simulator //BaseNumbers // info for the base numbers came from https://n...content-available-to-author-only...e.com/pgo-egg-hatch-distribution/ var egg2 = 4408 ; var egg5 = 6035 ; var egg10 = 4284 ; //% chance of catching var iggybuff = 0.02346 ; var cleffa = 0.02807 ; var pichu = 0.02 ; var togepi = 0.02 ; var elekid = 0.058 ; var magby = 0.08794 ; var smoochum = 0.07872 ; //required monstors var monstorToCatch = { "iggybuff" : 1 , "cleffa" : 1 , "pichu" : 1 , "togepi" : 1 , "elekid" : 1 , "magby" : 1 , "smoochum" : 1 } ; var simulateNumber = 1000 ; //internal numbers var totalEgg = egg2 + egg5 + egg10 ; var perct2 = egg2 / totalEgg ; var perct5 = ( egg2 + egg5 ) / totalEgg ; var monstorMatrix = { 2 : { "iggybuff" : iggybuff , "cleffa" : cleffa } , 5 : { "pichu" : pichu , "togepi" : togepi } , 10 : { "elekid" : elekid , "magby" : magby , "smoochum" : smoochum } } var runningTotalEggs = 0 ; var runningTotalDistance = 0 ; for ( i = 0 ; i < simulateNumber ; i ++ ) { var monstorClone = JSON. parse ( JSON. stringify ( monstorToCatch ) ) ; var simDetail = catchAllMonsters ( monstorClone ) ; runningTotalEggs = runningTotalEggs + simDetail. eggsTotal ; runningTotalDistance = runningTotalDistance + simDetail. distance ; } print ( "Over " + simulateNumber + " simulations" ) ; print ( "Average required eggs are:" + ( runningTotalEggs / simulateNumber ) ) ; print ( "Average distance is:" + ( runningTotalDistance / simulateNumber ) ) ; function getEggSize ( ) { var myRandom = Math . random ( ) ; if ( myRandom < perct2 ) // 2 k egg return 2 ; else if ( myRandom < perct5 ) // 5 k egg return 5 ; else // 10 k egg return 10 ; } function getMonster ( eggSize ) { var myRandom = Math . random ( ) ; var eggMatrix = monstorMatrix [ eggSize ] var tempPercent = 0 ; for ( var key in eggMatrix ) { tempPercent = tempPercent + eggMatrix [ key ] ; if ( myRandom < tempPercent ) { return key ; } } } function catchAllMonsters ( monsNeeded ) { var eggCounter = { 2 : 0 , 5 : 0 , 10 : 0 } ; var monsterCounter = { } ; for ( var key in monsNeeded ) { if ( monsNeeded [ key ] == 0 ) delete monsNeeded [ key ] ; } while ( Object . keys ( monsNeeded ) . length > 0 ) { var myEggSize = getEggSize ( ) ; var myMonster = getMonster ( myEggSize ) ; eggCounter [ myEggSize ] ++; if ( myMonster != null ) { if ( monsterCounter [ myMonster ] != null ) monsterCounter [ myMonster ] = monsterCounter [ myMonster ] + 1 ; else monsterCounter [ myMonster ] = 1 ; if ( monsNeeded [ myMonster ] != null ) { monsNeeded [ myMonster ] = monsNeeded [ myMonster ] - 1 ; if ( monsNeeded [ myMonster ] == 0 ) delete monsNeeded [ myMonster ] ; } } } var eggsTotal = 0 ; var distance = 0 ; for ( var key in eggCounter ) { eggsTotal = eggsTotal + eggCounter [ key ] ; distance = key * eggCounter [ key ] ; } var myResult = { "eggsDetails" : eggCounter , "allMonsters" : monsterCounter , "eggsTotal" : eggsTotal , "distance" : distance } ; return myResult ; }

aW1wb3J0UGFja2FnZShqYXZhLmlvKTsKaW1wb3J0UGFja2FnZShqYXZhLmxhbmcpOwoKLy8geW91ciBjb2RlIGdvZXMgaGVyZQovL2VnZyBzaW11bGF0b3IKLy9CYXNlTnVtYmVycwovLyBpbmZvIGZvciB0aGUgYmFzZSBudW1iZXJzIGNhbWUgZnJvbSBodHRwczovL24uLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmUuY29tL3Bnby1lZ2ctaGF0Y2gtZGlzdHJpYnV0aW9uLwp2YXIgZWdnMiA9IDQ0MDg7CnZhciBlZ2c1ID0gNjAzNTsKdmFyIGVnZzEwID0gNDI4NDsKCi8vJSBjaGFuY2Ugb2YgY2F0Y2hpbmcgCnZhciBpZ2d5YnVmZiA9IDAuMDIzNDY7CnZhciBjbGVmZmEgPSAwLjAyODA3Owp2YXIgcGljaHUgPSAwLjAyOwp2YXIgdG9nZXBpID0gMC4wMjsKdmFyIGVsZWtpZC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ZG9tIDwgdGVtcFBlcmNlbnQpIHsKICAgICAgICAgICAgcmV0dXJuIGtleTsKICAgICAgICB9CiAgICB9Cgp9CgoKZnVuY3Rpb24gY2F0Y2hBbGxNb25zdGVycyhtb25zTmVlZGVkKSB7CiAgICB2YXIgZWdnQ291bnRlciA9IHsKICAgICAgICAyOiAwLAogICAgICAgIDU6IDAsCiAgICAgICAgMTA6IDAKICAgIH07CiAgICB2YXIgbW9uc3RlckNvdW50ZXIgPSB7fTsKCiAgICBmb3IgKHZhciBrZXkgaW4gbW9uc05lZWRlZCkgewogICAgICAgIGlmIChtb25zTmVlZGVkW2tleV0gPT0gMCkKICAgICAgICAgICAgZGVsZXRlIG1vbnNOZWVkZWRba2V5XTsKICAgIH0KCiAgICB3aGlsZSAoT2JqZWN0LmtleXMobW9uc05lZWRlZCkubGVuZ3RoID4gMCkgewogICAgICAgIHZhciBteUVnZ1NpemUgPSBnZXRFZ2dTaXplKCk7CiAgICAgICAgdmFyIG15TW9uc3RlciA9IGdldE1vbnN0ZXIobXlFZ2dTaXplKTsKICAgICAgICBlZ2dDb3VudGVyW215RWdnU2l6ZV0rKzsKICAgICAgICBpZiAobXlNb25zdGVyICE9IG51bGwpIHsKICAgICAgICAgICAgaWYgKG1vbnN0ZXJDb3VudGVyW215TW9uc3Rlcl0gIT0gbnVsbCkKICAgICAgICAgICAgICAgIG1vbnN0ZXJDb3VudGVyW215TW9uc3Rlcl0gPSBtb25zdGVyQ291bnRlcltteU1vbnN0ZXJdICsgMTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgbW9uc3RlckNvdW50ZXJbbXlNb25zdGVyXSA9IDE7CgogICAgICAgICAgICBpZiAobW9uc05lZWRlZFtteU1vbnN0ZXJdICE9IG51bGwpIHsKICAgICAgICAgICAgICAgIG1vbnNOZWVkZWRbbXlNb25zdGVyXSA9IG1vbnNOZWVkZWRbbXlNb25zdGVyXSAtIDE7CiAgICAgICAgICAgICAgICBpZiAobW9uc05lZWRlZFtteU1vbnN0ZXJdID09IDApCiAgICAgICAgICAgICAgICAgICAgZGVsZXRlIG1vbnNOZWVkZWRbbXlNb25zdGVyXTsKICAgICAgICAgICAgfQoKICAgICAgICB9CiAgICB9CiAgICB2YXIgZWdnc1RvdGFsID0gMDsKICAgIHZhciBkaXN0YW5jZSA9IDA7CgogICAgZm9yICh2YXIga2V5IGluIGVnZ0NvdW50ZXIpIHsKICAgICAgICBlZ2dzVG90YWwgPSBlZ2dzVG90YWwgKyBlZ2dDb3VudGVyW2tleV07CiAgICAgICAgZGlzdGFuY2UgPSBrZXkgKiBlZ2dDb3VudGVyW2tleV07CiAgICB9CgoKICAgIHZhciBteVJlc3VsdCA9IHsKICAgICAgICAiZWdnc0RldGFpbHMiOiBlZ2dDb3VudGVyLAogICAgICAgICJhbGxNb25zdGVycyI6IG1vbnN0ZXJDb3VudGVyLAogICAgICAgICJlZ2dzVG90YWwiOiBlZ2dzVG90YWwsCiAgICAgICAgImRpc3RhbmNlIjogZGlzdGFuY2UKICAgIH07CiAgICByZXR1cm4gbXlSZXN1bHQ7Cn0=