Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created July 13, 2024 02:55
Show Gist options
  • Save noqisofon/af753cf311d711f9b6371bb966588b62 to your computer and use it in GitHub Desktop.
Save noqisofon/af753cf311d711f9b6371bb966588b62 to your computer and use it in GitHub Desktop.
( ノ╹◡◡╹)ノ 多分 Elixir でソートするかもしれないやつ
defmodule Example.Sort do
def sort([]), do: []
def sort([head | tail]), do: insert(head, sort(tail))
defp insert(elt, lst) do
case lst do
[] ->
[elt]
[head | tail] ->
if elt <= head do
[elt | lst]
else
[head | insert(elt, tail)]
end
end
end
end
defmodule Example do
alias Example.Sort
def main do
1..10
|> Enum.to_list()
|> Enum.shuffle()
|> Sort.sort()
|> IO.inspect()
end
end
Example.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment