Created
March 4, 2021 18:01
-
-
Save alexcrist/a4ebde3e6bdb96e5339f70e89d01b9d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foldTo(distance) { | |
// If we're given a bogus distance, return null | |
if (distance < 0) { | |
return null; | |
} | |
// Initial paper thickness and number of folds | |
let paperThickness = 0.0001; | |
let numFolds = 0; | |
// Fold our paper until it is equal to or greater than the given distance | |
while (paperThickness < distance) { | |
paperThickness = paperThickness * 2; | |
numFolds = numFolds + 1; | |
} | |
// Output numFolds | |
return numFolds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment