Challenge #17 - Scrabble Scrore

In this challenge words_start.dfl (77.9 KB) we calculate the scrabble score of given words.

We start with a list of scrabble words:

aeromedical
aetiology
airheaded
alternativenesses
amalgamated
animator
anisogamies
antifraud
anxieties
atticism
...

The task is to determine each word’s score using scrabble rules.

Each character contributes points as follows:

  • 1 Point - a, e, i, l, n, o, r, s, t and u
  • 2 Points - d and g
  • 3 Points - b, c, m and p
  • 4 Points - f, h, v, w and y
  • 5 Points - k
  • 8 Points - j and x
  • 10 Points - q and z

The output should look like this:
Screenshot 2021-10-31 at 13.31.46

I’d like to offer two possible solutions. Each follows a different strategy.

Solution 1: Functions only

This approach - words_functional.dfl (100.9 KB) - casts the word to a list of characters, maps the character’s to their score, and sums up the scores to arrive at the total.

The calculator uses the following strategy.

The lookup table is a dict indexed by character like this:

The calculator casts the word to a list and maps each character to the corresponding points - then sums up the points

Solution 2: Row Stream

This approach - words_rows.dfl (100.3 KB) - splits the words to characters and places each character into the row stream into the row.

The value mapper step does the bulk of the work:

  • it defines list holding characters worth the same amount
  • it defines functions that test for membership of the current character in one of these lists, mapping to the corresponding score value on success

Once each character is mapped, it’s just a matter of collecting/summing them up per word in the group by step.