Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from remote #1280

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a501e70
Add some solutions
Jun 9, 2023
d394b18
Clock
Jun 9, 2023
d8c9fb1
Minesweeper WIP
Aug 29, 2023
b0c3fe5
PhoneNumber WIP
Aug 29, 2023
ddd2a56
Punctuations / letters
Aug 29, 2023
0c9bc6a
Refacto phone number
Aug 29, 2023
6b56b61
Phone number solved
Aug 30, 2023
4446c3a
Tournament: advice 1
Aug 30, 2023
95e76ff
Refacto \o/
Aug 30, 2023
6ee45b9
Tournament : small changes
Aug 30, 2023
4a4ddda
Refactor Telephone number
Sep 5, 2023
cafb07b
Start of pig latin
Sep 6, 2023
8e03408
Merge branch 'exercism:main' into main
Sprootch Dec 13, 2023
6b8ee79
Solve Minesweeper.
Dec 14, 2023
c49207f
RLE encode
Dec 14, 2023
a000d80
RLE : almost decode
Dec 14, 2023
81547ce
Solve RLE
Dec 18, 2023
cdfc726
Poker: parse hands
Jan 9, 2024
f988925
Almost NucleotideCount.fs
Jan 12, 2024
9ab577d
Nucleotides: refacto
Jan 15, 2024
113e6bb
Ledger start refacto
Jan 15, 2024
1f6b783
Replace currency and locale
Jan 15, 2024
7ec19a2
Use fold
Jan 15, 2024
4277c2f
Refacto
Jan 15, 2024
37a847a
Refacto getAmount
Jan 16, 2024
0594ee4
Solve acronym
Feb 7, 2024
25ef9a9
Refacto Acronym
Feb 7, 2024
b037a58
Simplify Anagram using LINQ
Feb 8, 2024
740a902
Refacto Ledger
Feb 8, 2024
5f64152
Start bookstore
Feb 20, 2024
c2b3475
Solve Clock.fs
Feb 20, 2024
c90d35e
Solve RotationalCipher
Feb 21, 2024
a7214bc
Meetup : ugly solve
Feb 21, 2024
db3df6a
Meetup : Refacto
Feb 21, 2024
1f5fff3
Meetup : refacto
Feb 21, 2024
3e76fab
AffineCipher : Start solving
Feb 21, 2024
f1b3fe3
Check coprime
Feb 21, 2024
91f2a2a
Solve AffineCipher.
Feb 22, 2024
1e7de35
ListOps
Jun 6, 2024
4a4ccbb
Solve RNA transcript
Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module LuciansLusciousLasagna

// TODO: define the 'expectedMinutesInOven' binding

// TODO: define the 'remainingMinutesInOven' function

// TODO: define the 'preparationTimeInMinutes' function

// TODO: define the 'elapsedTimeInMinutes' function
let expectedMinutesInOven = 40
let remainingMinutesInOven ovenTime = expectedMinutesInOven - ovenTime
let preparationTimeInMinutes layers = layers * 2
let elapsedTimeInMinutes layers ovenTime = (layers * 2) + ovenTime
9 changes: 8 additions & 1 deletion exercises/practice/acronym/Acronym.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module Acronym

let abbreviate phrase = failwith "You need to implement this function."
open System

let abbreviate(phrase: string) =
phrase
.ToUpper()
.Split([| ' '; '-'; '_' |], StringSplitOptions.RemoveEmptyEntries)
|> Array.map (fun s -> s[0])
|> String.Concat
17 changes: 8 additions & 9 deletions exercises/practice/acronym/AcronymTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,34 @@ open Acronym
let ``Basic`` () =
abbreviate "Portable Network Graphics" |> should equal "PNG"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Lowercase words`` () =
abbreviate "Ruby on Rails" |> should equal "ROR"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Punctuation`` () =
abbreviate "First In, First Out" |> should equal "FIFO"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``All caps word`` () =
abbreviate "GNU Image Manipulation Program" |> should equal "GIMP"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Punctuation without whitespace`` () =
abbreviate "Complementary metal-oxide semiconductor" |> should equal "CMOS"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Very long abbreviation`` () =
abbreviate "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me" |> should equal "ROTFLSHTMDCOALM"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Consecutive delimiters`` () =
abbreviate "Something - I made up from thin air" |> should equal "SIMUFTA"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Apostrophes`` () =
abbreviate "Halley's Comet" |> should equal "HC"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Underscore emphasis`` () =
abbreviate "The Road _Not_ Taken" |> should equal "TRNT"

68 changes: 66 additions & 2 deletions exercises/practice/affine-cipher/AffineCipher.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,69 @@
module AffineCipher

let decode a b cipheredText = failwith "You need to implement this function."
open System

let encode a b plainText = failwith "You need to implement this function."
let alphabet = [ 'a' .. 'z' ]

let private coprime a b =
let rec gcd a b =
if a = b then a
elif a > b then gcd (a - b) b
else gcd a (b - a)

gcd a b = 1

let private mmi a m =
let rec loop a x m =
match a * x % m with
| 1 -> x
| _ -> loop a (x + 1) m

loop a 1 m

let rec gcd p q =
if (p = 0 || q = 0) then 0
elif (p = q) then p
elif (p > q) then gcd (p - q) q
else gcd p (q - p)

let private (%%) n m =
match n % m with
| mod' when sign mod' >= 0 -> mod'
| mod' -> abs m + mod'

let decode a b (cipheredText: string) =
if (coprime a 26 |> not) then
raise (ArgumentException "Not coprime")

cipheredText.ToLower().Replace(" ", "")
|> Seq.map (fun c ->
if c |> Char.IsDigit then
c
else
let y = alphabet |> List.findIndex ((=) c)
let result = (mmi a 26) * (y - b) %% 26
alphabet[result])
|> String.Concat

let encodeChar a b c =
if (c |> Char.IsDigit) then
c
else
let i = alphabet |> List.findIndex ((=) c)
let result = (a * i + b) % 26
alphabet[result]

let encode a b (plainText: string) =
if (coprime a 26 |> not) then
raise (ArgumentException "Not coprime")

plainText.ToLower().Replace(" ", "")
|> Seq.choose (fun c ->
if (c |> Char.IsLetterOrDigit) then
Some(encodeChar a b c)
else
None)
|> Seq.chunkBySize 5
|> Seq.map String.Concat
|> (function
| s -> String.Join(" ", s))
31 changes: 15 additions & 16 deletions exercises/practice/affine-cipher/AffineCipherTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,62 @@ open AffineCipher
let ``Encode yes`` () =
encode 5 7 "yes" |> should equal "xbt"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode no`` () =
encode 15 18 "no" |> should equal "fu"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode OMG`` () =
encode 21 3 "OMG" |> should equal "lvz"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode O M G`` () =
encode 25 47 "O M G" |> should equal "hjp"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode mindblowingly`` () =
encode 11 15 "mindblowingly" |> should equal "rzcwa gnxzc dgt"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode numbers`` () =
encode 3 4 "Testing,1 2 3, testing." |> should equal "jqgjc rw123 jqgjc rw"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode deep thought`` () =
encode 5 17 "Truth is fiction." |> should equal "iynia fdqfb ifje"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode all the letters`` () =
encode 17 33 "The quick brown fox jumps over the lazy dog." |> should equal "swxtj npvyk lruol iejdc blaxk swxmh qzglf"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Encode with a not coprime to m`` () =
(fun () -> encode 6 17 "This is a test." |> ignore) |> should throw typeof<System.ArgumentException>

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Decode exercism`` () =
decode 3 7 "tytgn fjr" |> should equal "exercism"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Decode a sentence`` () =
decode 19 16 "qdwju nqcro muwhn odqun oppmd aunwd o" |> should equal "anobstacleisoftenasteppingstone"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Decode numbers`` () =
decode 25 7 "odpoz ub123 odpoz ub" |> should equal "testing123testing"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Decode all the letters`` () =
decode 17 33 "swxtj npvyk lruol iejdc blaxk swxmh qzglf" |> should equal "thequickbrownfoxjumpsoverthelazydog"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Decode with no spaces in input`` () =
decode 17 33 "swxtjnpvyklruoliejdcblaxkswxmhqzglf" |> should equal "thequickbrownfoxjumpsoverthelazydog"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Decode with too many spaces`` () =
decode 15 16 "vszzm cly yd cg qdp" |> should equal "jollygreengiant"

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Decode with a not coprime to m`` () =
(fun () -> decode 13 5 "Test" |> ignore) |> should throw typeof<System.ArgumentException>

14 changes: 13 additions & 1 deletion exercises/practice/anagram/Anagram.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
module Anagram

let findAnagrams sources target = failwith "You need to implement this function."
open System
open System.Linq

let isAnagram (target: string) (source: string) =
if target.Equals(source, StringComparison.OrdinalIgnoreCase) then
false
else
let sort(str: string) = str.ToLower() |> Seq.sort

(target |> sort).SequenceEqual(source |> sort)

let findAnagrams sources target =
sources |> List.filter (isAnagram target)
31 changes: 15 additions & 16 deletions exercises/practice/anagram/AnagramTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,77 @@ let ``No matches`` () =
let candidates = ["hello"; "world"; "zombies"; "pants"]
findAnagrams candidates "diaper" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Detects two anagrams`` () =
let candidates = ["lemons"; "cherry"; "melons"]
findAnagrams candidates "solemn" |> should equal ["lemons"; "melons"]

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Does not detect anagram subsets`` () =
let candidates = ["dog"; "goody"]
findAnagrams candidates "good" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Detects anagram`` () =
let candidates = ["enlists"; "google"; "inlets"; "banana"]
findAnagrams candidates "listen" |> should equal ["inlets"]

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Detects three anagrams`` () =
let candidates = ["gallery"; "ballerina"; "regally"; "clergy"; "largely"; "leading"]
findAnagrams candidates "allergy" |> should equal ["gallery"; "regally"; "largely"]

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Detects multiple anagrams with different case`` () =
let candidates = ["Eons"; "ONES"]
findAnagrams candidates "nose" |> should equal ["Eons"; "ONES"]

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Does not detect non-anagrams with identical checksum`` () =
let candidates = ["last"]
findAnagrams candidates "mass" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Detects anagrams case-insensitively`` () =
let candidates = ["cashregister"; "Carthorse"; "radishes"]
findAnagrams candidates "Orchestra" |> should equal ["Carthorse"]

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Detects anagrams using case-insensitive subject`` () =
let candidates = ["cashregister"; "carthorse"; "radishes"]
findAnagrams candidates "Orchestra" |> should equal ["carthorse"]

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Detects anagrams using case-insensitive possible matches`` () =
let candidates = ["cashregister"; "Carthorse"; "radishes"]
findAnagrams candidates "orchestra" |> should equal ["Carthorse"]

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Does not detect an anagram if the original word is repeated`` () =
let candidates = ["go Go GO"]
findAnagrams candidates "go" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Anagrams must use all letters exactly once`` () =
let candidates = ["patter"]
findAnagrams candidates "tapper" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Words are not anagrams of themselves`` () =
let candidates = ["BANANA"]
findAnagrams candidates "BANANA" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Words are not anagrams of themselves even if letter case is partially different`` () =
let candidates = ["Banana"]
findAnagrams candidates "BANANA" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Words are not anagrams of themselves even if letter case is completely different`` () =
let candidates = ["banana"]
findAnagrams candidates "BANANA" |> should be Empty

[<Fact(Skip = "Remove this Skip property to run this test")>]
[<Fact>]
let ``Words other than themselves can be anagrams`` () =
let candidates = ["LISTEN"; "Silent"]
findAnagrams candidates "LISTEN" |> should equal ["Silent"]

20 changes: 19 additions & 1 deletion exercises/practice/book-store/BookStore.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
module BookStore

let total books = failwith "You need to implement this function."
let getDiscount =
function
| 2 -> 0.95m
| 3 -> 0.90m
| 4 -> 0.8m
| 5 -> 0.75m
| _ -> 1m

let computeForFiveOrLess books =
let distinct = List.distinct books |> List.length
(books |> List.length |> decimal) * 8m * getDiscount distinct

let computePrice books =
0m

let total books =
match List.length books with
| n when n <= 5 -> computeForFiveOrLess books
| _ -> computePrice books
Loading