Stream.repeatedly(fn -> Enum.random(["ズン", "ドコ"]) end) |>
Enum.reduce_while(
[],
fn x, acc ->
acc |>
(&(List.starts_with?(&1, ["ドコ", "ズン", "ズン", "ズン", "ズン"]) && !List.starts_with?(&1, ["ドコ", "ズン", "ズン", "ズン", "ズン", "ズン"]))).()
|> if(do: {:halt, ["キ・ヨ・シ!" | acc]}, else: {:cont, [x | acc]})
end) |>
Enum.reverse |>
Enum.each(fn x -> IO.puts x end)
https://scrapbox.io/Geek-SpaceBox/ズンドコ問題
こちらに準拠して、ズン ズン ズン ズン ズン ドコを不正としました。
repeatedlyがきれいですね。あとList.ends_with?がなかったので仕方なくstarts_with?を使いました。リストは先頭への追加が高速なのでしかたないですね.