Compare commits

4 Commits
master ... main

Author SHA1 Message Date
Chang CL
f63288fd8f finish lesson 04 2025-09-03 21:06:46 +08:00
Chang CL
4d82c3d2a2 finish lesson 03 2025-09-01 19:09:31 +08:00
Chang CL
01c487374d finish lesson 01 2025-08-26 23:15:16 +08:00
Chang CL
d9ed6dec0f first commit 2025-08-24 17:03:19 +08:00
5 changed files with 61 additions and 61 deletions

View File

@@ -11,30 +11,30 @@ defmodule Equalities do
# Replace ___ with the answer to make the koan pass. # Replace ___ with the answer to make the koan pass.
koan "We shall contemplate truth by testing reality, via equality" do koan "We shall contemplate truth by testing reality, via equality" do
assert true == ___ assert true == true
end end
koan "Not something is the opposite of it" do koan "Not something is the opposite of it" do
assert !true == ___ assert !true == false
end end
koan "To understand reality, we must compare our expectations against reality" do koan "To understand reality, we must compare our expectations against reality" do
assert 2 == 1 + ___ assert 2 == 1 + 1
end end
koan "Some things may appear different, but be the same" do koan "Some things may appear different, but be the same" do
assert 1 == 2 / ___ assert 1 == 2 / 2
end end
koan "Unless they actually are different" do koan "Unless they actually are different" do
assert 3.2 != ___ assert 3.2 != 3
end end
koan "Some may be looking for bigger things" do koan "Some may be looking for bigger things" do
assert ___ > 3 assert 4 > 3
end end
koan "Others are happy with less" do koan "Others are happy with less" do
assert ___ < 3 assert 2 < 3
end end
end end

View File

@@ -5,42 +5,42 @@ defmodule Strings do
@intro "Strings" @intro "Strings"
koan "Strings are there to represent text" do koan "Strings are there to represent text" do
assert "hello" == ___ assert "hello" == "hello"
end end
koan "Values may be inserted into strings by interpolation" do koan "Values may be inserted into strings by interpolation" do
assert "1 + 1 = #{1 + 1}" == ___ assert "1 + 1 = #{1 + 1}" == "1 + 1 = 2"
end end
koan "They can be put together" do koan "They can be put together" do
assert "hello world" == ___ <> "world" assert "hello world" == "hello " <> "world"
end end
koan "Or pulled apart into a list when needed" do koan "Or pulled apart into a list when needed" do
assert ["hello", "world"] == String.split(___, " ") assert ["hello", "world"] == String.split("hello world", " ")
end end
koan "Be careful, a message may be altered" do koan "Be careful, a message may be altered" do
assert String.replace("An awful day", "awful", "incredible") == ___ assert String.replace("An awful day", "awful", "incredible") == "An incredible day"
end end
koan "But strings never lie about themselves" do koan "But strings never lie about themselves" do
assert true == String.contains?("An incredible day", ___) assert true == String.contains?("An incredible day", "day")
end end
koan "Sometimes you want just the opposite of what is given" do koan "Sometimes you want just the opposite of what is given" do
assert ___ == String.reverse("ananab") assert "banana" == String.reverse("ananab")
end end
koan "Other times a little cleaning is in order" do koan "Other times a little cleaning is in order" do
assert String.trim(" \n banana\n ") == ___ assert String.trim(" \n banana\n ") == "banana"
end end
koan "Repetition is the mother of learning" do koan "Repetition is the mother of learning" do
assert String.duplicate("String", 3) == ___ assert String.duplicate("String", 3) == "StringStringString"
end end
koan "Strings can be louder when necessary" do koan "Strings can be louder when necessary" do
assert String.upcase("listen") == ___ assert String.upcase("listen") == "LISTEN"
end end
end end

View File

@@ -6,129 +6,129 @@ defmodule Numbers do
@intro "Why is the number six so scared? Because seven eight nine!\nWe should get to know numbers a bit more!" @intro "Why is the number six so scared? Because seven eight nine!\nWe should get to know numbers a bit more!"
koan "Is an integer equal to its float equivalent?" do koan "Is an integer equal to its float equivalent?" do
assert 1 == 1.0 == ___ assert 1 == 1.0 == true
end end
koan "Is an integer threequal to its float equivalent?" do koan "Is an integer threequal to its float equivalent?" do
assert 1 === 1.0 == ___ assert 1 === 1.0 == false
end end
koan "Revisit division with threequal" do koan "Revisit division with threequal" do
assert 2 / 2 === ___ assert 2 / 2 === 1.0
end end
koan "Another way to divide" do koan "Another way to divide" do
assert div(5, 2) == ___ assert div(5, 2) == 2
end end
koan "What remains or: The Case of the Missing Modulo Operator (%)" do koan "What remains or: The Case of the Missing Modulo Operator (%)" do
assert rem(5, 2) == ___ assert rem(5, 2) == 1
end end
koan "Other math operators may produce this" do koan "Other math operators may produce this" do
assert 2 * 2 === ___ assert 2 * 2 === 4
end end
koan "Or other math operators may produce this" do koan "Or other math operators may produce this" do
assert 2 * 2.0 === ___ assert 2 * 2.0 === 4.0
end end
koan "Two ways to round, are they exactly the same?" do koan "Two ways to round, are they exactly the same?" do
assert Float.round(1.2) === round(1.2) == ___ assert Float.round(1.2) === round(1.2) == false
end end
koan "Release the decimals into the void" do koan "Release the decimals into the void" do
assert trunc(5.6) === ___ assert trunc(5.6) === 5
end end
koan "Are you odd?" do koan "Are you odd?" do
assert Integer.is_odd(3) == ___ assert Integer.is_odd(3) == true
end end
koan "Actually you might be even" do koan "Actually you might be even" do
assert Integer.is_even(4) == ___ assert Integer.is_even(4) == true
end end
koan "Let's grab the individual digits in a list" do koan "Let's grab the individual digits in a list" do
individual_digits = Integer.digits(58_127) individual_digits = Integer.digits(58_127)
assert individual_digits == ___ assert individual_digits == [5, 8, 1, 2, 7]
end end
koan "Oh no! I need it back together" do koan "Oh no! I need it back together" do
number = Integer.undigits([1, 2, 3, 4]) number = Integer.undigits([1, 2, 3, 4])
assert number == ___ assert number == 1234
end end
koan "Actually I want my number as a string" do koan "Actually I want my number as a string" do
string_digit = Integer.to_string(1234) string_digit = Integer.to_string(1234)
assert string_digit == ___ assert string_digit == "1234"
end end
koan "The meaning of life in hexadecimal is 2A!" do koan "The meaning of life in hexadecimal is 2A!" do
assert Integer.parse("2A", 16) == {___, ""} assert Integer.parse("2A", 16) == {42, ""}
end end
koan "The remaining unparsable part is also returned" do koan "The remaining unparsable part is also returned" do
assert Integer.parse("5 years") == {5, ___} assert Integer.parse("5 years") == {5, " years"}
end end
koan "What if you parse a floating point value as an integer?" do koan "What if you parse a floating point value as an integer?" do
assert Integer.parse("1.2") == {___, ___} assert Integer.parse("1.2") == {1, ".2"}
end end
koan "Just want to parse to a float" do koan "Just want to parse to a float" do
assert Float.parse("34.5") == {___, ""} assert Float.parse("34.5") == {34.5, ""}
end end
koan "Hmm, I want to parse this but it has some strings" do koan "Hmm, I want to parse this but it has some strings" do
assert Float.parse("1.5 million dollars") == {___, " million dollars"} assert Float.parse("1.5 million dollars") == {1.5, " million dollars"}
end end
koan "I don't want this decimal point, let's round up" do koan "I don't want this decimal point, let's round up" do
assert Float.ceil(34.25) === ___ assert Float.ceil(34.25) === 35.0
end end
koan "OK, I only want it to 1 decimal place" do koan "OK, I only want it to 1 decimal place" do
assert Float.ceil(34.25, 1) === ___ assert Float.ceil(34.25, 1) === 34.3
end end
koan "Rounding down is what I need" do koan "Rounding down is what I need" do
assert Float.floor(99.99) === ___ assert Float.floor(99.99) === 99.0
end end
koan "Rounding down to 2 decimal places" do koan "Rounding down to 2 decimal places" do
assert Float.floor(12.345, 2) === ___ assert Float.floor(12.345, 2) === 12.34
end end
koan "Round the number up or down for me" do koan "Round the number up or down for me" do
assert Float.round(5.5) === ___ assert Float.round(5.5) === 6.0
assert Float.round(5.4) === ___ assert Float.round(5.4) === 5.0
assert Float.round(8.94, 1) === ___ assert Float.round(8.94, 1) === 8.9
assert Float.round(-5.5674, 3) === ___ assert Float.round(-5.5674, 3) === -5.567
end end
koan "I want the first and last in the range" do koan "I want the first and last in the range" do
first..last = Range.new(1, 10) first..last = Range.new(1, 10)
assert first == ___ assert first == 1
assert last == ___ assert last == 10
end end
koan "Does my number exist in the range?" do koan "Does my number exist in the range?" do
range = Range.new(1, 10) range = Range.new(1, 10)
assert 4 in range == ___ assert 4 in range == true
assert 10 in range == ___ assert 10 in range == true
assert 0 in range == ___ assert 0 in range == false
end end
def is_range?(%Range{}), do: true def is_range?(%Range{}), do: true
def is_range?(_), do: false def is_range?(_), do: false
koan "Is this a range?" do koan "Is this a range?" do
assert is_range?(1..10) == ___ assert is_range?(1..10) == true
assert is_range?(0) == ___ assert is_range?(0) == false
end end
end end

View File

@@ -6,18 +6,18 @@ defmodule Atoms do
koan "Atoms are constants where their name is their own value" do koan "Atoms are constants where their name is their own value" do
adam = :human adam = :human
assert adam == ___ assert adam == :human
end end
koan "It is surprising to find out that booleans are atoms" do koan "It is surprising to find out that booleans are atoms" do
assert is_atom(true) == ___ assert is_atom(true) == true
assert is_boolean(false) == ___ assert is_boolean(false) == true
assert true == ___ assert true == true
assert false == ___ assert false == false
end end
koan "Like booleans, the nil value is also an atom" do koan "Like booleans, the nil value is also an atom" do
assert is_atom(nil) == ___ assert is_atom(nil) == true
assert nil == ___ assert nil == nil
end end
end end

View File

@@ -1,6 +1,6 @@
%{ %{
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"credo": {:hex, :credo, "1.7.1", "6e26bbcc9e22eefbff7e43188e69924e78818e2fe6282487d0703652bc20fd62", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9871c6095a4c0381c89b6aa98bc6260a8ba6addccf7f6a53da8849c748a58a2"}, "credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
} }