Last active
December 20, 2015 08:19
-
-
Save michaelficarra/6099260 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import Data.List (unfoldr) | |
| import Data.Tuple (swap) | |
| import System.IO (hSetBuffering, stdout, BufferMode(..)) | |
| placeValues base = reverse . unfoldr (\x -> if x == 0 then Nothing else Just $ swap $ divMod x base) | |
| persistencePath base x = if x < base then [x] else x : (persistencePath base $ product $ placeValues base x) | |
| persistence base n = length (persistencePath base n) - 1 | |
| lowestNumberSuchThat f = head $ dropWhile (not . f) [0..] | |
| main = do | |
| hSetBuffering stdout NoBuffering | |
| base <- fmap read $ putStr "base: " >> getLine | |
| targetPersistence <- fmap read $ putStr "persistence: " >> getLine | |
| putStrLn $ show $ lowestNumberSuchThat $ \x -> persistence base x == targetPersistence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment