s iir ejkucsath alnroetph eri;split\$+;print\$_[\$-++]until(\$-++>\$#_);print\$_[\$---]until(\$---<1); ##```## s iir ejkucsath alnroetph eri;split\$+;print\$_[\$-++]while(\$-++-\$#_);print\$_[\$---]while(\$----()) ##``````## s oohaa ctkseurjogis; s ii rpeehrtlo nisom; +\$ -= + split \$ +; ; print + splice @ ## ; _ => + \$ ---, \$ ++ 1 while + \$ ---- \$ ++ @ _ ##``````## {- Given the number of weighings, prints instructions to solve the following riddle: You have (3^N - 3) / 2 identical looking objects, one of which is lighter or heavier than the others (but you don't know which). In N weighings, determine which is the odd one, and whether it is lighter or heavier. -} module Main where import IO import System.Environment main :: IO () main = do args <- getArgs let w :: Int w = read \$ head args -- number of weighings l = labels w -- list of object labels n = length l -- number of objects you can use putStr \$ " You can find the odd one out of " ++ show n ++ " objects with " ++ show w ++ " weighings, as follows:\n\n"++ " 1. Assign the following \"magic number\" labels to the objects:\n" ++ " " ++ unwords l ++ "\n\n" ++ " 2. Keep track of two strings of numbers, LIGHT and HEAVY.\n\n" ++ " 3. Record weighing results as follows:\n" ++ " If pans balance, append 1 to both LIGHT and HEAVY.\n" ++ " If left side is lighter, append 0 to LIGHT and 2 to HEAVY.\n" ++ " If right side is lighter, append 2 to LIGHT and 0 to HEAVY.\n\n" ++ " 4. Perform weighings in this order:\n" ++ weighingOrder 1 w ++ "\n" ++ " 5. After " ++ show w ++ " weighings, either LIGHT or HEAVY will " ++ "match one of the object labels. That object is the odd one, and " ++ "its fault is shown by whether LIGHT or HEAVY matched.\n" weighingOrder :: Int -> Int -> String weighingOrder current total = " #" ++ show current ++ ":\n" ++ " Left : " ++ unwords (weighing current total '0') ++ "\n" ++ " Right: " ++ unwords (weighing current total '2') ++ "\n" ++ if current == total then "" else weighingOrder (current+1) total weighing i w lr = filter (\l -> l !! (i-1) == lr) \$ labels w labels = filter (isValidLabel) . labelsOfLength -- if entire string is the same character, or it's a bad sequence, -- this label is not valid isValidLabel l = not \$ or [ allSame l, badSequence l ] allSame l@(x:_) = l == (replicate (length l) x) badSequence [] = True badSequence (x:[]) = False badSequence (x:y:ys) = if x == y then badSequence (y:ys) else badChange x y where badChange '0' '1' = False badChange '1' '2' = False badChange '2' '0' = False badChange _ _ = True -- list of all strings of length n consisting of '0', '1', and '2' labelsOfLength n = foldr (\$) [""] ( replicate n \$ cartesia "012" ) -- Gives the cartesion product of a list and a list of lists cartesia :: [a] -> [[a]] -> [[a]] cartesia xs = concat . map ( \ys -> map ( \x -> ys ++ [x] ) xs ) ##``````## body { position: relative; font-family: arial; background: #ddd; } .header { border: solid 0.05em #000; background: #888; color: #ffd; padding: 1em; margin-bottom: 1em; } .main { position: relative; } .content { position: relative; border: solid 0.05em #448; background: #ddf; padding: 1em; margin-left: 8em; } .menu { position: absolute; top: 0; left: 0; border: solid 0.05em #844; background: #fdd; padding: 1em; width: 5em; height: 5em; } .menu a { display: block; } .corner { position: relative; float: left; top: -1.05em; left: -1.05em; border-left-color: transparent; border-top-color: transparent; border-right-color: inherit; border-bottom-color: inherit; border-style: solid; border-width: inherit; background: #ddd; width: 3em; height: 3em; } Website Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus ultricies nonummy nunc. Maecenas sagittis tellus vitae diam. Nam bibendum augue non nulla. Nam vehicula urna vel arcu. Nulla in enim. Donec neque magna, pellentesque non, consequat sit amet, placerat quis, mauris. Integer nec elit ac metus pulvinar tincidunt. Mauris vel elit. Etiam feugiat. Etiam posuere. Integer volutpat nulla eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur eleifend, dolor rhoncus molestie pellentesque, nisl magna eleifend felis, scelerisque sodales leo turpis at enim. Duis sapien nisi, feugiat in, facilisis sed, congue eu, orci. Ut ac sem. Maecenas vel dolor eget eros euismod rutrum. Curabitur sed libero a lectus imperdiet fermentum. Integer eget mi ut ipsum elementum ultrices. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus ac augue. Aenean dapibus pretium sapien. Vivamus orci lorem, tincidunt ut, fringilla ut, placerat viverra, lorem. Cras a augue. Aenean eu lacus eget lectus feugiat lobortis. Nulla ullamcorper rutrum nunc. Phasellus ullamcorper, elit quis sodales facilisis, lectus tortor pharetra turpis, eu luctus risus nisi eu sem. Sed eget neque. Sed viverra. Etiam dapibus, justo sed aliquam tempor, diam sem pulvinar nulla, eu malesuada metus sem ut nibh. Suspendisse ac justo ac neque placerat pharetra. Duis mattis laoreet magna. Etiam metus nulla, interdum sed, elementum in, luctus et, ante. In sodales bibendum risus. Morbi quis diam. Aliquam non lectus. Integer vitae mi. Suspendisse sagittis, ligula at consectetuer ultricies, pede mi rhoncus est, in iaculis mi eros eget felis. Donec dignissim, nisl mollis vehicula tristique, eros mauris sagittis velit, sit amet gravida lacus enim suscipit libero. Donec interdum tempor nulla. Sed aliquet nulla ut massa. In vel augue. Nunc leo nulla, tristique eget, commodo ac, gravida ac, leo. Donec velit nulla, ornare et, varius et, dictum eget, felis. Etiam aliquet odio tincidunt purus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Cras tincidunt. Etiam tortor purus, tristique a, rutrum eu, vestibulum eu, arcu. Quisque sit amet felis non ligula dapibus feugiat. Curabitur at erat nec lacus tempus condimentum. Sed sit amet ipsum. Praesent velit risus, sagittis a, vulputate eu, blandit venenatis, quam. Aenean quis nibh id risus commodo aliquam. Suspendisse nec tellus eu mauris hendrerit pretium. Nullam vitae libero. Etiam mi risus, lobortis a, eleifend id, venenatis nec, felis. Ut blandit vestibulum libero. Nullam ultricies condimentum turpis. Nulla facilisi. Suspendisse tincidunt sagittis arcu. Donec ultrices sem ac felis venenatis egestas. Proin faucibus lectus pharetra ante. Donec egestas, arcu sed luctus egestas, dolor nunc pharetra odio, in laoreet pede lectus eu quam. Quisque vitae dui at leo rutrum sagittis. Nam pretium enim sit amet sem. Maecenas quis nisl. Link One Link Two Link Three Link Four ```