Skip to content

Commit 1020b21

Browse files
committed
2019-04 && instead of List.all
1 parent 987ccb1 commit 1020b21

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

Year2019/Day04.elm

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@ parse2 string =
6262
-- 3. COMPUTE (actually solve the problem)
6363

6464

65-
rules1 : List (List Char -> Bool)
66-
rules1 =
67-
[ twoOrMore
68-
, ruleMonotonic
69-
]
70-
71-
72-
rules2 : List (List Char -> Bool)
73-
rules2 =
74-
[ atLeastOneTwo
75-
, ruleMonotonic
76-
]
77-
78-
7965
twoOrMore : List Char -> Bool
8066
twoOrMore digits =
8167
List.Extra.group digits
@@ -94,8 +80,8 @@ atLeastOneTwo digits =
9480
|> (/=) 0
9581

9682

97-
ruleMonotonic : List Char -> Bool
98-
ruleMonotonic digits =
83+
monotonic : List Char -> Bool
84+
monotonic digits =
9985
List.Extra.groupWhile (<=) digits
10086
|> List.length
10187
|> (==) 1
@@ -116,7 +102,7 @@ compute1 ( low, high ) =
116102
digits =
117103
toChars n
118104
in
119-
if List.all (\rule -> rule digits) rules1 then
105+
if twoOrMore digits && monotonic digits then
120106
Just n
121107

122108
else
@@ -135,7 +121,7 @@ compute2 ( low, high ) =
135121
digits =
136122
toChars n
137123
in
138-
if List.all (\rule -> rule digits) rules2 then
124+
if atLeastOneTwo digits && monotonic digits then
139125
Just n
140126

141127
else

0 commit comments

Comments
 (0)