Skip to content

Commit

Permalink
Merge branch 'exercism:main' into add-exercise-rational-numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
natanaelsirqueira authored Mar 4, 2023
2 parents f197d93 + 46b419b commit ae9102f
Show file tree
Hide file tree
Showing 144 changed files with 1,163 additions and 442 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: erlef/setup-beam@e3f6ffe2878180f57318bf13febd3933ee81f664
with:
otp-version: "25.2"
gleam-version: "0.26.0"
gleam-version: "0.27.0"

- name: Run tests for all exercises
run: bin/test
Expand Down
35 changes: 35 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,24 @@
],
"difficulty": 4
},
{
"slug": "luhn",
"name": "Luhn",
"uuid": "a66bbefd-db5a-44d0-ab4b-73d871756f08",
"practices": [
"string",
"list"
],
"prerequisites": [
"string",
"list",
"case",
"bool",
"int",
"result"
],
"difficulty": 5
},
{
"slug": "wordy",
"name": "Wordy",
Expand Down Expand Up @@ -1301,6 +1319,23 @@
],
"difficulty": 2
},
{
"slug": "grade-school",
"name": "Grade School",
"uuid": "836dddea-2a02-434f-a886-c8e1c429268f",
"practices": [
"map",
"result"
],
"prerequisites": [
"map",
"result",
"string",
"int",
"list"
],
"difficulty": 3
},
{
"slug": "pig-latin",
"name": "Pig Latin",
Expand Down
6 changes: 3 additions & 3 deletions exercise_generator/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_erlang", version = "0.18.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "14ABC93A7975369CCDDC0C4D9A34C0E0FE99CA3AD336BE6A17299EC0285B7107" },
{ name = "gleam_json", version = "0.5.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "E42443C98AA66E30143C24818F2CEA801491C10CE6B1A5EDDF3FC4ABDC7601CB" },
{ name = "gleam_stdlib", version = "0.26.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B17BBE8A78F3909D93BCC6C24F531673A7E328A61F24222EB1E58D0A7552B1FE" },
{ name = "gleam_erlang", version = "0.18.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "C69F59D086AD50B80DE294FB0963550630971C9DC04E92B1F7AEEDD2C0BE226C" },
{ name = "gleam_json", version = "0.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9A805C1E60FB9CD73AF3034EB464268A6B522D937FCD2DF92BD246F2F4B37930" },
{ name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
]

Expand Down
10 changes: 5 additions & 5 deletions exercise_generator/src/exercise_generator.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn have_same_type(a: JsonData, b: JsonData) -> Bool {
// Main

pub fn main() {
assert [slug, canonical_data] = erlang.start_arguments()
let assert [slug, canonical_data] = erlang.start_arguments()

case json.decode(from: canonical_data, using: canonical_data_decoder()) {
Ok(data) -> {
Expand Down Expand Up @@ -226,15 +226,15 @@ fn write_solution_files(
["..", "exercises", "practice", slug, "src", exercise <> ".gleam"],
"/",
)
assert Ok(Nil) = file.write(content, solution_path)
let assert Ok(Nil) = file.write(content, solution_path)

let example_path =
string.join(
["..", "exercises", "practice", slug, ".meta", "example.gleam"],
"/",
)

assert Ok(Nil) = file.write(content, example_path)
let assert Ok(Nil) = file.write(content, example_path)
}

fn functions_to_implement(test_cases: List(TestCase)) -> Map(String, Function) {
Expand Down Expand Up @@ -322,7 +322,7 @@ fn write_test_file(slug: String, data: CanonicalData) {
"/",
)

assert Ok(Nil) = file.write(content, path)
let assert Ok(Nil) = file.write(content, path)
}

fn print_comments(comments: List(String)) -> String {
Expand Down Expand Up @@ -375,7 +375,7 @@ fn print_test(
_ -> print_comments(comments)
}
let test_name = flatten_description(prefix <> description)
assert Ok(Function(need_labels: need_labels, ..)) =
let assert Ok(Function(need_labels: need_labels, ..)) =
map.get(functions, function)
let input =
input
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/accumulate/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

packages = [
{ name = "gleam_bitwise", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "6064699EFBABB1CA392DCB193D0E8B402FB042B4B46857B01E6875E643B57F54" },
{ name = "gleam_stdlib", version = "0.26.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B17BBE8A78F3909D93BCC6C24F531673A7E328A61F24222EB1E58D0A7552B1FE" },
{ name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
]

Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/acronym/.meta/example.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import gleam/regex.{from_string, split}
import gleam/string.{capitalise, first}

pub fn abbreviate(phrase phrase: String) -> String {
assert Ok(re) = from_string("[ +\\-/;_]+")
let assert Ok(re) = from_string("[ +\\-/;_]+")
split(with: re, content: phrase)
|> fold(
"",
fn(acc, val) {
assert Ok(letter) =
let assert Ok(letter) =
val
|> capitalise
|> first
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/acronym/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

packages = [
{ name = "gleam_bitwise", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "6064699EFBABB1CA392DCB193D0E8B402FB042B4B46857B01E6875E643B57F54" },
{ name = "gleam_stdlib", version = "0.26.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B17BBE8A78F3909D93BCC6C24F531673A7E328A61F24222EB1E58D0A7552B1FE" },
{ name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
]

Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/affine-cipher/.meta/example.gleam
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gleam/result
import gleam/string
import gleam/list
import gleam/int
Expand All @@ -11,7 +12,7 @@ pub fn encode(
a a: Int,
b b: Int,
) -> Result(String, Error) {
try _ = modular_inverse(a, alphabet_length)
use _ <- result.then(modular_inverse(a, alphabet_length))

plaintext
|> translate(fn(index) { a * index + b })
Expand All @@ -27,7 +28,7 @@ pub fn decode(
a a: Int,
b b: Int,
) -> Result(String, Error) {
try mmi = modular_inverse(a, alphabet_length)
use mmi <- result.then(modular_inverse(a, alphabet_length))

Ok(translate(ciphertext, fn(index) { mmi * { index - b } }))
}
Expand All @@ -42,7 +43,7 @@ fn translate(input: String, op: fn(Int) -> Int) -> String {
|> list.filter_map(fn(char) {
case list.contains(letters, char) {
True -> {
assert Ok(shifted_index) =
let assert Ok(shifted_index) =
int.modulo(
op(string.utf_codepoint_to_int(char) - letter_a_int_code_point),
alphabet_length,
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/affine-cipher/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

packages = [
{ name = "gleam_bitwise", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "6064699EFBABB1CA392DCB193D0E8B402FB042B4B46857B01E6875E643B57F54" },
{ name = "gleam_stdlib", version = "0.26.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B17BBE8A78F3909D93BCC6C24F531673A7E328A61F24222EB1E58D0A7552B1FE" },
{ name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
]

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

packages = [
{ name = "gleam_bitwise", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "6064699EFBABB1CA392DCB193D0E8B402FB042B4B46857B01E6875E643B57F54" },
{ name = "gleam_stdlib", version = "0.26.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B17BBE8A78F3909D93BCC6C24F531673A7E328A61F24222EB1E58D0A7552B1FE" },
{ name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ pub fn output_base_is_negative_test() {
pub fn both_bases_are_negative_test() {
let output =
all_your_base.rebase(digits: [1], input_base: -2, output_base: -7)
assert True =
let assert True =
output == Error(InvalidBase(-2)) || output == Error(InvalidBase(-7))
}
2 changes: 1 addition & 1 deletion exercises/practice/allergies/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

packages = [
{ name = "gleam_bitwise", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "6064699EFBABB1CA392DCB193D0E8B402FB042B4B46857B01E6875E643B57F54" },
{ name = "gleam_stdlib", version = "0.26.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B17BBE8A78F3909D93BCC6C24F531673A7E328A61F24222EB1E58D0A7552B1FE" },
{ name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
]

Expand Down
Loading

0 comments on commit ae9102f

Please sign in to comment.