Skip to content

Instantly share code, notes, and snippets.

@CremboC
Created April 16, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CremboC/29ef80d32b7d597bec5aa634836dd7ff to your computer and use it in GitHub Desktop.
Save CremboC/29ef80d32b7d597bec5aa634836dd7ff to your computer and use it in GitHub Desktop.
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