Created
April 16, 2017 14:23
-
-
Save CremboC/29ef80d32b7d597bec5aa634836dd7ff 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
module Main where | |
import System.Environment | |
import qualified RotatingQ as Q | |
import RotatingQ (Queue) | |
breadthFirst :: (a -> [a]) -> a -> [a] | |
breadthFirst b r = bf b [r] | |
bf :: (a -> [a]) -> [a] -> [a] | |
bf _ [] = [] | |
bf b (x:xs) = x : bf b (xs ++ b x) | |
bfQ :: (a -> [a]) -> Queue a -> [a] | |
bfQ b q | Q.isEmpty q = [] | |
| otherwise = x : bfQ b (foldl Q.snoc xs (b x)) | |
where (x, xs) = (Q.head q, Q.tail q) | |
main :: IO () | |
main = do | |
print (Q.queue [1, 2, 3] :: Queue Int) | |
[n'] <- map (read :: String -> Int) <$> getArgs | |
let f n = [(2 * n) + 1, 2 * (n + 1)] | |
print $ last . take n' . bfQ f . Q.queue $ [0..] | |
-- print $ last . take n' . bf f $ [0..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment