Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
24
Task/Box-the-compass/Elixir/box-the-compass.elixir
Normal file
24
Task/Box-the-compass/Elixir/box-the-compass.elixir
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
defmodule Box do
|
||||
defp head do
|
||||
Enum.chunk(~w(north east south west north), 2, 1)
|
||||
|> Enum.flat_map(fn [a,b] ->
|
||||
c = if a=="north" or a=="south", do: "#{a}#{b}", else: "#{b}#{a}"
|
||||
[ a, "#{a} by #{b}", "#{a}-#{c}", "#{c} by #{a}",
|
||||
c, "#{c} by #{b}", "#{b}-#{c}", "#{b} by #{a}" ]
|
||||
end)
|
||||
|> Enum.with_index
|
||||
|> Enum.map(fn {s, i} -> {i+1, String.capitalize(s)} end)
|
||||
|> Map.new
|
||||
end
|
||||
|
||||
def compass do
|
||||
header = head()
|
||||
angles = Enum.map(0..32, fn i -> i * 11.25 + elem({0, 5.62, -5.62}, rem(i, 3)) end)
|
||||
Enum.each(angles, fn degrees ->
|
||||
index = rem(round(32 * degrees / 360), 32) + 1
|
||||
:io.format "~2w ~-20s ~6.2f~n", [index, header[index], degrees]
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Box.compass
|
||||
Loading…
Add table
Add a link
Reference in a new issue