diff --git a/gleam/arrays_and_hashing/.gitignore b/gleam/arrays_and_hashing/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/gleam/arrays_and_hashing/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/gleam/arrays_and_hashing/gleam.toml b/gleam/arrays_and_hashing/gleam.toml new file mode 100644 index 0000000..e963f14 --- /dev/null +++ b/gleam/arrays_and_hashing/gleam.toml @@ -0,0 +1,21 @@ +name = "arrays_and_hashing" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "", repo = "" } +# links = [{ title = "Website", href = "" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_stdlib = ">= 1.0.0 and < 2.0.0" +in = ">= 1.1.0 and < 2.0.0" +simplifile = ">= 2.4.0 and < 3.0.0" + +[dev_dependencies] +gleeunit = ">= 1.0.0 and < 2.0.0" diff --git a/gleam/arrays_and_hashing/manifest.toml b/gleam/arrays_and_hashing/manifest.toml new file mode 100644 index 0000000..a861bb6 --- /dev/null +++ b/gleam/arrays_and_hashing/manifest.toml @@ -0,0 +1,16 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, + { name = "gleam_stdlib", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "0C5506589DF4C63DF5D6FFBB834562D6865C6C2AEE0019D7B37886BD6D128141" }, + { name = "gleeunit", version = "1.10.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "254B697FE72EEAD7BF82E941723918E421317813AC49923EE76A18C788C61E72" }, + { name = "in", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "in", source = "hex", outer_checksum = "5339494529936AF83EAA0B8368195DCA9505382836CDED4CD6B0F5F9FA93C2B8" }, + { name = "simplifile", version = "2.4.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "7C18AFA4FED0B4CE1FA5B0B4BAC1FA1744427054EA993565F6F3F82E5453170D" }, +] + +[requirements] +gleam_stdlib = { version = ">= 1.0.0 and < 2.0.0" } +gleeunit = { version = ">= 1.0.0 and < 2.0.0" } +in = { version = ">= 1.1.0 and < 2.0.0" } +simplifile = { version = ">= 2.4.0 and < 3.0.0" } diff --git a/gleam/arrays_and_hashing/src/arrays_and_hashing.gleam b/gleam/arrays_and_hashing/src/arrays_and_hashing.gleam new file mode 100644 index 0000000..eda41f0 --- /dev/null +++ b/gleam/arrays_and_hashing/src/arrays_and_hashing.gleam @@ -0,0 +1,39 @@ +import gleam/int +import gleam/io +import gleam/result +import gleam/string +import in + +pub fn exercise_chosing() { + io.print("> Enter which exercise you'd like to run (enter \"0\" to exit): ") + let number_input = + result.replace_error(in.read_line(), Nil) + |> result.map(string.trim) + |> result.try(int.parse) + |> result.unwrap(-1) + + case number_input { + 0 -> { + io.println("Exiting program, bye!") + } + 1 -> { + io.println("Executing Contains Duplicate:") + exercise_chosing() + } + _ -> { + io.println("Wrong exercise code!") + exercise_chosing() + } + } +} + +pub fn main() -> Nil { + io.println("Arrays and Hashing - Available problems:") + io.println("1. Contains Duplicate") + io.println("2. Valid Anagram") + io.println("3. Two Sum") + + exercise_chosing() + + Nil +} diff --git a/gleam/arrays_and_hashing/src/contains_duplicate.gleam b/gleam/arrays_and_hashing/src/contains_duplicate.gleam new file mode 100644 index 0000000..2fe1958 --- /dev/null +++ b/gleam/arrays_and_hashing/src/contains_duplicate.gleam @@ -0,0 +1,16 @@ +import gleam/dict +import gleam/int +import gleam/io +import gleam/result +import gleam/string +import in + +pub fn has_duplicate(nums: List(Int)) -> Bool { + let number_input = dict.new() + result.replace_error(in.read_line(), Nil) + |> result.map(string.trim) + |> result.try(int.parse) + |> result.unwrap(-1) + + False +} diff --git a/arrays_and_hashing/contains_duplicate/input.txt b/gleam/arrays_and_hashing/src/input_contains_duplicate.txt similarity index 100% rename from arrays_and_hashing/contains_duplicate/input.txt rename to gleam/arrays_and_hashing/src/input_contains_duplicate.txt diff --git a/arrays_and_hashing/two_sum/input.txt b/gleam/arrays_and_hashing/src/input_two_sum.txt similarity index 100% rename from arrays_and_hashing/two_sum/input.txt rename to gleam/arrays_and_hashing/src/input_two_sum.txt diff --git a/arrays_and_hashing/valid_anagram/input.txt b/gleam/arrays_and_hashing/src/input_valid_anagram.txt similarity index 100% rename from arrays_and_hashing/valid_anagram/input.txt rename to gleam/arrays_and_hashing/src/input_valid_anagram.txt diff --git a/gleam/arrays_and_hashing/src/two_sum.gleam b/gleam/arrays_and_hashing/src/two_sum.gleam new file mode 100644 index 0000000..e69de29 diff --git a/gleam/arrays_and_hashing/src/valid_anagram.gleam b/gleam/arrays_and_hashing/src/valid_anagram.gleam new file mode 100644 index 0000000..e69de29 diff --git a/gleam/arrays_and_hashing/test/arrays_and_hashing_test.gleam b/gleam/arrays_and_hashing/test/arrays_and_hashing_test.gleam new file mode 100644 index 0000000..fba3c88 --- /dev/null +++ b/gleam/arrays_and_hashing/test/arrays_and_hashing_test.gleam @@ -0,0 +1,13 @@ +import gleeunit + +pub fn main() -> Nil { + gleeunit.main() +} + +// gleeunit test functions end in `_test` +pub fn hello_world_test() { + let name = "Joe" + let greeting = "Hello, " <> name <> "!" + + assert greeting == "Hello, Joe!" +} diff --git a/ruby/arrays_and_hashing/contains_duplicate/input.txt b/ruby/arrays_and_hashing/contains_duplicate/input.txt new file mode 100644 index 0000000..93a4845 --- /dev/null +++ b/ruby/arrays_and_hashing/contains_duplicate/input.txt @@ -0,0 +1 @@ +1 2 3 4 diff --git a/arrays_and_hashing/contains_duplicate/main.rb b/ruby/arrays_and_hashing/contains_duplicate/main.rb similarity index 100% rename from arrays_and_hashing/contains_duplicate/main.rb rename to ruby/arrays_and_hashing/contains_duplicate/main.rb diff --git a/ruby/arrays_and_hashing/two_sum/input.txt b/ruby/arrays_and_hashing/two_sum/input.txt new file mode 100644 index 0000000..2758f7b --- /dev/null +++ b/ruby/arrays_and_hashing/two_sum/input.txt @@ -0,0 +1,2 @@ +5 5 +10 diff --git a/arrays_and_hashing/two_sum/main.rb b/ruby/arrays_and_hashing/two_sum/main.rb similarity index 100% rename from arrays_and_hashing/two_sum/main.rb rename to ruby/arrays_and_hashing/two_sum/main.rb diff --git a/ruby/arrays_and_hashing/valid_anagram/input.txt b/ruby/arrays_and_hashing/valid_anagram/input.txt new file mode 100644 index 0000000..cb786cf --- /dev/null +++ b/ruby/arrays_and_hashing/valid_anagram/input.txt @@ -0,0 +1 @@ +fried fired diff --git a/arrays_and_hashing/valid_anagram/main.rb b/ruby/arrays_and_hashing/valid_anagram/main.rb similarity index 100% rename from arrays_and_hashing/valid_anagram/main.rb rename to ruby/arrays_and_hashing/valid_anagram/main.rb