Skip to content

Instantly share code, notes, and snippets.

@uxjp
Last active September 22, 2022 02:26
Show Gist options
  • Save uxjp/b2b04c52790a2f10301f36695724cff9 to your computer and use it in GitHub Desktop.
Save uxjp/b2b04c52790a2f10301f36695724cff9 to your computer and use it in GitHub Desktop.
Filter list Elixir
defmodule Solution do
[max | tail ] = IO.read(:all)
|> String.split
|> Enum.map(&String.to_integer/1) #everything is already integer after this
tail
|> Enum.filter(fn x -> x < max end)
|> Enum.each(&IO.puts/1)
end
defmodule Solution do
[max | tail ] = IO.read(:all)
|> String.split
|> Enum.map(&String.to_integer/1)
tail
|> Enum.filter(&(&1 < max))
|> Enum.each(&IO.puts/1)
end
defmodule Solution do
#I'm not familiar with this yet [1/2]
def filter_by_max([max | nums]) do
Enum.filter(nums, &(&1 < max))
end
def main() do
IO.read(:stdio, :all)
|> String.split()
|> Enum.map(&String.to_integer(&1))
# the way this function is called [2/2]
|> filter_by_max()
|> Enum.each(&(IO.puts(&1)))
end
end
Solution.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment