1 REM Silly egg puzzle 10 LET floors = 50 20 LET threshold = 1 + INT(RND * floors) 30 LET attempts = 0 40 PRINT "How many floors can an egg drop before it cracks? Find out using two eggs." 100 REM First, try every [stride] floors. 105 LET stride = INT(SQR(floors)) 110 LET throwFrom = 0 115 PRINT "The test building is "; floors; " stories high, so we'll drop the 1st egg every "; stride; " floors." 120 REM loop start 125 LET attempts = attempts + 1 130 IF (throwFrom >= threshold) THEN 150 135 PRINT "1st egg survived floor "; throwFrom; "..." 140 LET throwFrom = throwFrom + stride 145 GOTO 120 150 PRINT "1st egg cracked after being thrown from floor "; throwFrom; "!" 200 LET throwFrom = throwFrom - stride + 1 205 PRINT "Drop 2nd egg every floor, starting at "; throwFrom; "." 210 REM loop start 215 LET attempts = attempts + 1 220 IF (throwFrom >= threshold) THEN 240 225 PRINT "2nd egg survived floor "; throwFrom; "..." 230 LET throwFrom = throwFrom + 1 235 GOTO 210 240 PRINT "2nd egg cracked after being thrown from floor "; throwFrom; "!" 300 PRINT "The threshold was "; threshold; " and it was found in "; attempts ;" attempts." 305 END
Return to Example Index