Advent of Code 2017

And day 15.

Those who know about Streams and especially about the fact that one can create them from thin air and does not need to have an Enumerable.t() to feed them, should be done in no time with this.

What bugs me a little is, that simply generating thus many numbers takes a lot of time.

Part a takes about 30 to 35 seconds and Part b 14 to 16.

Im wondering if handcrafting generator functions would sped up everything at least a little bit. It would remove some of the indirections of Stream, but introduces its own…

By generator function I mean functions that return a tuple with the next value and a function to generate the next tuple, roughly like this one:

iex(1)> defmodule M do
...(1)>   def gen(input \\ 0), do: {input, fn -> gen(input) end}
...(1)> end
iex(2) {_, f} = M.gen()
{0, #Function<...>}
iex(3) {_, f} = f.()
{1, #Function<...>}
iex(4) {_, f} = f.()
{2, #Function<...>}

Solution | Input