Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,23 @@
defmodule LookAndSay do
def next(n) do
Enum.chunk_by(to_char_list(n), &(&1))
|> Enum.map(fn cl=[h|_] -> Enum.concat(to_char_list(length cl), [h]) end)
|> Enum.concat
|> List.to_integer
end
def sequence_from(n) do
Stream.iterate n, &(next/1)
end
def main([start_str|_]) do
{start_val,_} = Integer.parse(start_str)
IO.inspect sequence_from(start_val) |> Enum.take 9
end
def main([]) do
main(["1"])
end
end
LookAndSay.main(System.argv)

View file

@ -0,0 +1,8 @@
defmodule RC do
def look_and_say(n) do
Regex.replace(~r/(.)\1*/, to_string(n), fn x,y -> [to_string(String.length(x)),y] end)
|> String.to_integer
end
end
IO.inspect Enum.reduce(1..9, [1], fn _,acc -> [RC.look_and_say(hd(acc)) | acc] end) |> Enum.reverse