Created
December 8, 2022 20:43
-
-
Save jido/01ef500c6ed8f6634ff30df9d3fcabad to your computer and use it in GitHub Desktop.
Advent of Code day 4 solution in Dodo0 language
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
clojure('read-line', 0) -> readline | |
clojure('split', 2) -> split | |
clojure('nil?', 1) -> endOfFile | |
clojure('read-string', 1) -> asInt | |
fun loop -> count, break | |
( | |
readline() -> line | |
endOfFile(line) -> eof | |
if (eof) -> | |
break(count) | |
| | |
fun pair -> elf, return | |
( | |
split(elf, "-") -> pair | |
'nth'(pair, 0) -> start | |
'nth'(pair, 1) -> end | |
asInt(start) -> a | |
asInt(end) -> b | |
return(a, b) | |
) | |
| pair | |
split(line, ",") -> elves | |
'nth'(elves, 0) -> first | |
'nth'(elves, 1) -> second | |
pair(first) -> a, b | |
pair(second) -> c, d | |
'-'(c, a) -> sdiff | |
'-'(d, b) -> ediff | |
'*'(sdiff, ediff) -> sign | |
'<='(sign, 0) -> overlap | |
if (overlap) -> | |
( | |
'+'(count, 1) -> count | |
loop(count, break) | |
) | |
| | |
loop(count, break) | |
) | |
| loop | |
loop(0) -> count | |
println(count) -> | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment