Created
July 13, 2024 02:55
-
-
Save noqisofon/af753cf311d711f9b6371bb966588b62 to your computer and use it in GitHub Desktop.
( ノ╹◡◡╹)ノ 多分 Elixir でソートするかもしれないやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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