I was the Sensei and there was approximately 8 participants.
Some links I have suggested to the participants who want to learn more about Elixir are on this Twitter thread.
The Code Kata (problem) we chose to solve was Look and Say.
Code was posted as a gist but it is also below:
look_and_say.ex
defmodule LookAndSay do
def lookandsay(numero) do
numero
|> Integer.digits()
|> lookandsay_inicia()
|> Integer.undigits()
end
defp lookandsay_inicia([cabeca | cauda]) do
lookandsayauxaux(cabeca, cauda, 1)
end
defp lookandsayauxaux(estado, [], i) do
[i, estado]
end
defp lookandsayauxaux(estado, [estado | cauda], i) do
lookandsayauxaux(estado, cauda, i + 1)
end
defp lookandsayauxaux(estado, [novoestado | cauda], i) do
[i, estado] ++ lookandsayauxaux(novoestado, cauda, 1)
end
end
look_and_say_test.exs
defmodule LookAndSayTest do
use ExUnit.Case
test "Look and Say de 1 é 11" do
assert LookAndSay.lookandsay(1) == 11
end
test "Look and Say de 555 é 35" do
assert LookAndSay.lookandsay(555) == 35
end
test "Look and Say de 55 é 25" do
assert LookAndSay.lookandsay(55) == 25
end
test "Look and Say de 11 é 21" do
assert LookAndSay.lookandsay(11) == 21
end
test "Look and Say de 5 é 15" do
assert LookAndSay.lookandsay(5) == 15
end
test "Look and Say de 123 é 111213" do
assert LookAndSay.lookandsay(123) == 111_213
end
test "Look and Say de 551 é 2511" do
assert LookAndSay.lookandsay(551) == 2511
end
test "Look and Say de 555555 é 65" do
assert LookAndSay.lookandsay(555_555) == 65
end
end
ExToHtml— Adolfo Neto (@adolfont) 25 de outubro de 2018
A simple way to create Colourised code in html format from a .ex file.https://t.co/qrkFx7Q0Nh#myelixirstatus
The Coding Dojo was part of a Free Software event:
Yesterday my Elixir Coding Dojo was part of Free Software Festival.#ftsl #ftsl2018 #myelixirstatus https://t.co/OxcEPNaHCB— Adolfo Neto (@adolfont) 25 de outubro de 2018
Nenhum comentário:
Postar um comentário