Skip to content

Instantly share code, notes, and snippets.

@bmarkons
Created November 21, 2021 00:55
Show Gist options
  • Save bmarkons/95e7d96f099a1068ae082aa79f51067d to your computer and use it in GitHub Desktop.
Save bmarkons/95e7d96f099a1068ae082aa79f51067d to your computer and use it in GitHub Desktop.
words = File.read!("input.txt") |> String.split
defmodule A do
def get(words, beginning, sequence) do
if words[beginning] do
words[beginning] |> Enum.filter(fn word ->
!Enum.member?(sequence, word)
end)
end
end
def kalodont(words, sequence) do
selected_words = get(words, sequence |> List.last |> String.slice(-2, 2), sequence)
if selected_words && !Enum.empty?(selected_words) do
selected_words |> Enum.each(fn word ->
kalodont(words, sequence ++ [word])
end)
else
IO.puts "******* NEW BIGGEST SEQUENCE WITH #{sequence |> Enum.count} CHARACTERS *********"
File.write("sequence1.txt", sequence |> Enum.join(" "))
end
end
end
words_indexed_by_beginning = Enum.group_by(words, fn e -> String.slice(e, 0, 2) end)
Enum.each(words, fn word ->
A.kalodont(words_indexed_by_beginning, [word])
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment