Everyone loves a game of Scrabble! Your challenge today is to calculate the scrabble score of a given word.
Scoring per tile:
To make things e...
For further actions, you may consider blocking this person and/or reporting abuse
Here's my solution in Perl, along with a few tests.
Edit: fixed a bug, stray print, and added the 7 letter bonus
Erlang:
Ah, neat. Pattern matching was definitely the way to go about it functionally, wish I'd done that instead!
Good old C. Be advised though there are ways to bork this one with some inputs not consistent with the rubric.
JavaScript
Live demo on CodePen.
A few days late, but here's my JavaScript solution, using
reduce
.I changed the rules a bit, since it's hard to distinguish between double/triple words and words that naturally end in d or t, I decided to use 2 or 3 instead.
Because these are fun in languages you don't actually know, here's Haskell:
I didn't provide tests, but I think it works. Maybe I'll write some later on.
Ruby solution
I borrowed your tests, @yzhernand . Thank you for writing them, so I didn't have to.
My overly complex (nim) solution :)
Calculates only by letter points
Elixir. Admittedly my Exercism solution with a bunch of String.replace calls to handle the more sophisticated way the problem is stated here.
Clojure:
codesandbox.io/s/daily-challenges-...
I’m learning Erlang.
I had forgotten that you can have several elements to the Head in a pattern match (then I saw @stevemoon ’s solution), so I used
lists:foldr
to process the word from the end, which means I accumulate the multipliers and apply them once I encounter a letter. I could have named variables better, but with short names it’s easier on the eye, with this state tuple I’m moving around.For fun I decided to allow several word multipliers, and to allow the blank indicator before, after, or in the middle of the asterisks.
I made my own tests, and stole other peoples’ as well.
To run:
Ooh I love Scrabble! I'm excited for this one lol
Here is my over engineered solution in Rust!
I broke it down into multiple different Rust strucs and enums! I'm getting more and more familiar with the Rust type system, and breaking down a game like this is great practice!
One thing I slightly added, is the ability to parse multiple word modifiers together! I opted for a
(t)(d)
syntax do indicate both a triple and double word score. This is possible in Scrabble, so I wanted to include support for itMy solution and test cases is just over 250 lines so here is the link to the source file in Github!
github.com/coreyja/dev-to-challeng...
Oh no, I didn't get to it today! Tomorrow will have to be a double day!
Clojure: