Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 7-Haskell/day1.hs @ 92:6f650dd96685
Minor tweak to prime efficiency
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 17 Jun 2019 20:50:43 +0100 |
parents | d6855f9d7eae |
children |
line wrap: on
line source
module Day1 where -- All even by list comprehension and guard are in all_even.hs my_reverse :: [a] -> [a] my_reverse [] = [] my_reverse (h:t) = reverse t ++ [h] colour_combo :: [String] -> [(String, String)] colour_combo colours = [(colour_1, colour_2) | colour_1 <- colours, colour_2 <- colours, colour_1 < colour_2] timestables :: [(Integer, Integer, Integer)] timestables = [(x, y, x * y) | x <- [1..12], y <- [1..12]] -- Map colouring problem - we don't want adjacent places to be the same colour colours = ["red", "green", "blue"] map_colouring :: [(String, String, String, String, String)] -- This just brute-forces all tuples and applies the rules, BUT it works and it uses Haskell list comprehension -- Although, maybe it won't brute-force ALL of them, because if al == mi then it might skip the rest map_colouring = [(al, mi, ga, tn, fl) | al <- colours, mi <- colours, ga <- colours, tn <- colours, fl <- colours, mi /= tn, mi /= al, al /= tn, al /= mi, al /= ga, al /= fl, ga /= fl, ga /= tn]