Skip to content

Instantly share code, notes, and snippets.

@jido
Created December 8, 2022 20:43
Show Gist options
  • Save jido/01ef500c6ed8f6634ff30df9d3fcabad to your computer and use it in GitHub Desktop.
Save jido/01ef500c6ed8f6634ff30df9d3fcabad to your computer and use it in GitHub Desktop.
Advent of Code day 4 solution in Dodo0 language
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