view 7-Haskell/day1.hs @ 93:39084e2b8744

Add a function for word-aware text wrapping Potentially hugely inefficient because we iterate through the string character by character, but then splitting it first and iterating over words still needs to iterate over the string to know where to split.
author IBBoard <dev@ibboard.co.uk>
date Tue, 18 Jun 2019 21:05:00 +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]