I had solved the alergies exercise but when i try submitting the code the tests time out even though my solution doesn’t have any performance bottlenecks, at least as far as i can tell. I do use recursion, though i don’t expect it to be a problem.
Here is my solution
allergies.allergicTo : Text -> Nat -> Boolean
allergies.allergicTo allergen score =
List.contains allergen (allergies.list score)
allergies.list : Nat -> [Text]
allergies.list = cases
x | x >= 256 ->
match x
|> Nat.toFloat
|> Float.logBase 2.0
|> Float.floor
|> Float.pow 2.0
|> Float.toNat with
Some y -> list (x - y)
None -> []
x | x >= 128 -> "cats" +: list (x - 128)
x | x >= 64 -> "pollen" +: list (x - 64)
x | x >= 32 -> "chocolate" +: list (x - 32)
x | x >= 16 -> "tomatoes" +: list (x - 16)
x | x >= 8 -> "strawberries" +: list (x - 8)
x | x >= 4 -> "shellfish" +: list (x - 4)
x | x >= 2 -> "peanuts" +: list (x - 2)
x | x >= 1 -> "eggs" +: list (x - 1)
_ -> []
I have tested the code locally and all of the tests pass
I am using the exercism cli to submit my answers.
So is my solution really slow or is the unison test runner unreliable?
Thanks in advance for anybody willing to answer.