I didn't know you could use a let expression like that in a list comprehension... nice!
False positive in case of
isOpposite "ab" "CD"
nothing crazy here if you are familiar with curyying and composition
to is intended to be implemented based on coerce, so the original author didn't test for it as a standalone function.
There is test for that function now.
I was wrong. I don't know what I meant with the second sentence (after all it's two years ago).
@muesli4, can you elaborate on conditions when you expect problems to happen for this solution?
https://downloads.haskell.org/~ghc/6.0/docs/html/base/Data.Int.html states "All arithmetic is performed modulo 2^n, where n is the number of bits in the type."
The output should be one or 2 characters by removing the same amount of characters from left and right. d is the number to remove from left (or right). n is what is left after removal.
To get the d expression it's easier to look at some examples.
"1" -> "1" (l = 1, d = 0)
"12" -> "12" (l = 2, d = 0)
"123" -> "2" (l = 3, d = 1)
"1234" -> "23" (l = 4, d = 1)
"12345" -> "3" (l = 5, d = 2)
"123456" -> "34" (l = 6, d = 2)
From here it's hopefully easy to come up with any suitable formula that gives you this property. I used (l - 1) / 2 :)
(l - 1) / 2
Gah! Right you are! I'm too used to workaround priorities before actually reading orginal grammar :)
The original grammar is by design parser-friendly. The reason is that every rule starts with and is uniquely identified by a single terminal (LL(1) grammar). I didn't want people to struggle with ambiguous expressions and associativity after the biggest part. That could be part of another Kata. ;)
Yeah! I was wondering if this could be done without having to destructure the pair... learning so much from everyone here :)
How did you get this formslas for d and n???!
This comment is hidden because it contains spoiler information about the solution
I am crazy about this solution.
I am crazy about this solutions.