Last active
December 8, 2020 08:00
-
-
Save sullyj3/11fb486a6c3917e7f8780bc1de1d0840 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
letterChar : Char -> Boolean | |
letterChar c = List.contains c <| toCharList "abcdefghijklmnopqrstuvwxyz" | |
groupAnswers : Text -> Map Char Nat | |
groupAnswers gr = | |
combine : Map Char Nat -> Char -> Map Char Nat | |
combine accMap c = | |
if letterChar c then | |
use Nat + | |
putWith (+) c 1 accMap | |
else accMap | |
List.foldLeft combine Map.empty <| toCharList gr | |
List.splitSubSeq : [a] -> [a] -> [[a]] | |
List.splitSubSeq lst sep = | |
go : [a] -> [a] -> [[a]] -> [[a]] | |
go lst' currSeq lists = | |
match stripPrefix sep lst' with | |
Some rest -> go rest [] (lists :+ currSeq) | |
None -> | |
match lst' with | |
x +: xs -> go xs (currSeq :+ x) lists | |
[] -> lists :+ currSeq | |
go lst [] [] | |
Text.splitSubSeq : Text -> Text -> [Text] | |
Text.splitSubSeq s sep = | |
List.map fromCharList (List.splitSubSeq (toCharList s) (toCharList sep)) | |
day6 : Text -> Nat | |
day6 input = | |
use List map | |
groups = Text.splitSubSeq input "\n\n" | |
theGroupAnswers = map groupAnswers groups | |
sum <| map Map.size theGroupAnswers | |
doDay6 : '{IO} () | |
doDay6 = | |
'let | |
f = openFile fp Read | |
contents = getText f | |
printLine (Nat.toText <| day6 contents) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a data point, it seems like
.base.Text.split
, a simpler version of this function, is implemented in terms oftoCharList