Skip to content

Instantly share code, notes, and snippets.

@oker1
Created November 4, 2012 15:03
Show Gist options
  • Save oker1/4012203 to your computer and use it in GitHub Desktop.
Save oker1/4012203 to your computer and use it in GitHub Desktop.
haskell házi 1
rotate :: String -> [String]
rotate l = rotate_recursive l []
rotate_recursive :: String -> String -> [String]
rotate_recursive [] list = []
rotate_recursive list1 list2 =
let (h1:t1) = list1
in [list1 ++ list2] ++ rotate_recursive t1 (list2 ++ [h1])
-- http://code.google.com/codejam/contest/1460488/dashboard#s=p2
is_recycled :: String -> String -> Bool
is_recycled l1 l2 = length [ x | x <- rotate l1, x /= l1, x == l2] >= 1
recycled_numbers :: Int -> Int -> Int
recycled_numbers from to = length [ (x,y) |
x <- [from..to], y <- [from..to], x < y, is_recycled (show x) (show y) ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment