Take a string of upper or lower case letters as input (optional), and calculate the score that string would get in a game of Scrabble in English.


The score of each letter is as follows (use this even if there are other versions of the game):

1 point: E, A, I, O, N, R, T, L, S, U
2 points: D, G
3 points: B, C, M, P
4 points: F, H, V, W, Y
5 points: K
8 points: J, X
10 points: Q, Z

The score of a string is simply the sum of the scores of each of the letters used. You may assume that you have plenty of tiles available, so long words, and words with many of the same letters are valid input.

Test cases:

ABC       ->    7
PPCG      ->   11
STEWIE    ->    9
UGPYKXQ   ->   33
FIZZBUZZ  ->   49

The shortest answer in each language wins! The input and output formats are flexible, so you may take the input as an array of characters (upper or lower case) if you want.

  • 6
    \$\begingroup\$ I'm hoping to see a MATLAB/Octave solution. All my attempts were horribly long... =/ \$\endgroup\$ – Stewie Griffin Apr 17 '18 at 19:04
  • 4
    \$\begingroup\$ I'm hoping to see a Beatnik solution. Cuz, you know, that would be the right tool for the job. \$\endgroup\$ – Giuseppe Apr 17 '18 at 19:28
  • \$\begingroup\$ @StewieGriffin Does 85 bytes count as horribly long? \$\endgroup\$ – Luis Mendo Apr 17 '18 at 21:11
  • 3
    \$\begingroup\$ Hasn't Mathematica a built-in for it? \$\endgroup\$ – sergiol Apr 18 '18 at 0:30
  • 1
    \$\begingroup\$ @manassehkatz you should definitely give it a go! I highly recommend that you post the challenge in the Sandbox to get some feedback and help with it before posting it on the main site. Complex challenges are notoriously difficult to get right without any feedback. \$\endgroup\$ – Stewie Griffin Apr 18 '18 at 19:37

48 Answers 48


PowerShell, 92 bytes

$args|% T*y|%{$i+=switch -r($_){[DG]{2}[BCMP]{3}[FHVWY]{4}K{5}[JX]{8}[QZ]{10}default{1}}};$i

Try it online!

Didn't notice @Add-TheNewOne's answer before writing this, but I think it's fairly different in any case.


JavaScript (ES6), 69 bytes

Takes input as an array of characters.


Try it online!


Bash + GNU utilities, 64

sed -es/[{QZ]/JD,JX]/KB,K]/FE,FHVWY]/BE,BCMP]/DE,DG]/EE}/g|wc -c

Try it online!

Input read from STDIN. Uses a brace expansion to generate sed expressions equivalent to those in my sed answer.


Perl 6, 55 bytes

{sum .map:{:36<Z3P8JOBRZ4X1FBXLWSVL>+>(.ord*4-260)%16}}

Try it online!

Takes an array of characters. Uses a 4-bit lookup table encoded in base-36.


Perl 5 -pF, 73 bytes


Try it online!

  • \$\begingroup\$ Managed to save a few using =~/./g, but can't get it down as far as @nwellnhof's answer... Try it online! \$\endgroup\$ – Dom Hastings Apr 18 '18 at 11:48
  • \$\begingroup\$ My Perl6 solution is pretty similar to this, I opted to use value-1 thus only needing 0-9 which are single digits and then split 022103... \$\endgroup\$ – Phil H Apr 19 '18 at 21:11

Red, 97 bytes

func[s][t: :to-integer n: 0 foreach c s[n: n - 47 + t pick{02210313074020029000033739}t c - 64]n]

Takes a string as input.

Explanation of the ungolfed solution:

f: func[s][
    n: 0                  ; n will store the sum
    foreach c s [         ; for each character in the argument 
        n: n - 47 + to-integer pick {02210313074020029000033739} to-integer c - 64
                          ; find its offset from "A" (to-integer c - 64)
                          ; use this as an index in the string with scores (pick {...} ...)
                          ; to extract the score and convert it to an integer 
                          ; increase it with 1 and add it to the sum    
    n                     ; return the sum 

Try it online!


Pip, 34 33 bytes


Takes input in lowercase as a command-line argument. Try it online!


We map a function to each character of the command-line argument a and sum the results using MS.

In the function, we convert the argument _ to its ASCII code using A, and then use that to index into the magic number 30740200290000337390221031. With cyclic indexing, this maps a -> 0, b -> 2, ... , z -> 9 (one less than the Scrabble score). We then add 1 to get the correct score of each letter.

We save one byte by encoding the number in base 36 (the highest base Pip's builtin base conversion can handle) as the string "3V1S1QFRU1SMQ12W7" and then converting it from base 36 to decimal using FB.


SmileBASIC, 87 85 78 bytes

INPUT S$WHILE""<S$S=S+VAL(@2210313074020029000033739[ASC(POP(S$))-65])+1WEND?S

Old method:


Go, 96 94 bytes

func(i string){a,s:=`

`,0;for _,c:=range i{s+=int(a[c-65])};print(s)}

Go allows any byte sequence in a raw string, except \r and `, this saves about 3 bytes off the total.

This is just a remix of existing solutions in other languages, so no real new innovation here.

Edit: I missed the memo where we dont have to name our functions

Try it online!


Powershell with amazing 297 Bytes

Any idea to make the script shorter?

  • \$\begingroup\$ You can remove the string $s=0. The -in is sorter than -contains. switch can returns a value $s+=$(switch($_){...{1}...{2}... ...{5}}). and etc :) Welcome! \$\endgroup\$ – mazzy Mar 1 at 14:50
  • \$\begingroup\$ Thank you :D !!! I'm not very experienced in Code golfing so can you explain me what you did in your Code? \$\endgroup\$ – Add-TheNewOne Mar 1 at 15:08
  • \$\begingroup\$ Step 1: obvious thing 240 bytes \$\endgroup\$ – mazzy Mar 1 at 17:05
  • \$\begingroup\$ Step 2: big case to default 195 bytes \$\endgroup\$ – mazzy Mar 1 at 17:07
  • \$\begingroup\$ Step 3: to take out repeating code 171 bytes \$\endgroup\$ – mazzy Mar 1 at 17:09

IBM PC DOS, 8088 assembly, 36 bytes

bb33 01ac 2c41 d0d8 d772 0651 b104 d2e8 5924 0f02 d0e2 ec13 3214 2418 5131 13a1 1114 484a


; score a Scrabble word string
; input:
;   I: pointer to input string
;   IL: length of input string
;   TBL: pointer to score table
; output:
;   SC: word score (reg8)
            LOCAL   LOOP_LETTER, ODD
        IFDIFI <I>,<SI>     ; skip if I is already SI
    MOV  SI, I              ; load string into SI 
        IFDIFI <IL>,<CX>    ; skip if IL is already CX
    MOV  CX, IL             ; set up loop counter
    MOV  BX, OFFSET TBL     ; load score table into BX
    LODSB                   ; load next char from DS:SI into AL, advance SI
    SUB  AL, 'A'            ; convert letter to zero-based index
    RCR  AL, 1              ; divide index by 2, set CF if odd index
    XLAT                    ; lookup score
    JC   ODD                ; if odd index use low nibble; if even use high nibble
    PUSH CX                 ; save loop counter (since SHR can only take CL)
    MOV  CL, 4              ; set up right shift for 4 bits
    SHR  AL, CL             ; shift high nibble into low nibble
    POP  CX                 ; restore loop counter
    AND  AL, 0FH            ; mask low nibble
    ADD  SC, AL             ; add letter score to total

; Score table
SCTBL DB 013H,032H,014H,024H,018H,051H,031H,013H,0A1H,011H,014H,048H,04AH


Implemented as a MACRO (essentially a function) this uses a score table of 4-bit nibbles. Loops through the input string and converts each letter to a zero-based index. Each index is divided by two to find the corresponding byte in the table. The low nibble is added if the index is odd, otherwise the high nibble is added if the index is even.


Example test program:

    MOV  SI, 80H            ; point SI to DOS PSP
    LODSW                   ; load arg length into AL, advance SI to 82H
    MOV  CL, AL             ; set up loop counter in CH
    DEC  CX                 ; remove leading space from letter count
    XOR  DX, DX             ; clear DX to hold total score


    MOV  AX, DX             ; put score in AX for OUTDEC display
    CALL OUTDEC             ; generic decimal display routine

enter image description here


05AB1E, 18 bytes


Try it online!


•Q<ß÷λv¸Ïàœ¶•           # compressed integer 30740200290000337390221031
             IÇ         # codepoints of the input
               è        # index into the digits of the large integer
                >       # increment each
                 O      # sum

The large integer encodes the point value of each letter. Since encoding numbers in the range 1-10 would be inconvenient, we subtract 1 so that each one fits on a single digit (this is why the > is needed).

Note that indexing in 05AB1E wraps around, so the first digit of the number actually corresponds to "h" ("h"'s codepoint is 104, which is 0 mod 26). This is convenient: since numbers can't start with 0, we don't want the first digit to correspond to "a".

Alternative 18-byter:


Try it online!

A pushes "abcdefghijklmnopqrstuvwxyz". transliterates, replacing each letter in the input with the corresponding digit in the compressed integer. A‡ saves one byte over IÇè; unfortunately, this encoding puts "a" first, so we have to use R (reverse) to get around the issue that numbers can't start with 0.

Yet another 18-byter:


Try it online!

Same idea as above, but this one uses the obscure žW built-in to push "qwertyuiopasdfghjklzxcvbnm". žW is one byte longer than A, but it saves the R since "q" isn't a 1-point letter.


brainfuck, 386 382 bytes


Try it online!

Pretty much ungolfed, but first brainfuck code for this question. This code can only handle uppercase letters. Any other symbol will lead to an endless loop. Also the maximum score depends on the used bf-interpreter. On tio.run this can handle scores up to 254.

abcde fghij klmno pqrst uvwxyz
13321 42418 51311 3x111 14484x (x = 10)

[input], 0, [points table], 0, 0, score
input: current letter marker (0 or neg 1), current letter
points table: check letter marker (0 or neg 1), points

-           set current letter marker
>,[>>,]     input characters

->          set check letter marker
            fill points table

+[-<<+]->                   go to first input letter
+                           bugfix: intersecting pointers
[                       main loop
  -                         bugfix: intersecting pointers
  >++++++++[<-------->-]<-  subtract 65 from current letter (ASCII A)
  [                         check loop: mark the entry in points table that's related to the current letter
    [->+]                   decrease letter and go to check letter marker
    >>-                     set new check letter marker
    <+[-<+]-                go back to current letter marker
    >                       go to current letter
                            the related points entry is found so we need to add the points to the score
  +[->+]->                  go to related points entry
  [                     addition loop
    ->+                     decrease points entry and save points to temporary cell
    >[>>]>+                 go to score and add 1
    +[-<+]->                go back to related points entry
  >[-<+>]                   move points back from temp cell
  <<+                       delete "check letter marker"
  <[<<]>-                   set "check letter marker" at A
  <+[-<+]                   go to current letter marker
  >>-                       set new current letter marker
  >                         next input letter
  +                         exit loop if cell pointer is at "check letter marker" position

>[>>]>                      go to score
                            number printing routine from esolangs

if unary output is allowed then this 297 293 bytes code can be used:


Try it online!


Visual Basic for Applications, 117 bytes

s=inputbox(u):for i=1to 16:s=replace(s,mid("DGBCMPFHVWYKJXQZ",i,1),space(mid("1122223333347799",i,1)+1)):next:?len(s)

Run in immediate (debug) window.


C# 49 bytes


Where s is a string containing the word in uppercase.

Uses the LINQ operator sum which examines each character and subtracts 65 (upper case A) and uses the resultant value to lookup a number in the long string, which represents the scores in alphabetical order starting with 0 as 1, 1 as 2 etc. The final subtraction -47 reduces the score to its ASCII value = 0 becomes 1, 1 becomes 2 etc

  • 2
    \$\begingroup\$ You can not assume input to be present in a predefined variable: codegolf.meta.stackexchange.com/a/8731/56433 \$\endgroup\$ – Laikoni Apr 19 '18 at 22:12
  • 1
    \$\begingroup\$ So this is the broken and "cheating" version of my answer posted a day before yours? \$\endgroup\$ – TheLethalCoder Apr 20 '18 at 10:17
  • \$\begingroup\$ @TheLethalCoder No - whacked this out over lunch and forgot about it. Didn't see yours until I l read your comment. There aren't many ways of doing this as succinctly as possible, and I guess I came up with the same method (albeit with a glaring mistake) as you, but if it makes your fragile ego feel better, go ahead and accuse me of cheating. \$\endgroup\$ – supermeerkat Apr 23 '18 at 8:54
  • \$\begingroup\$ The "cheating" is that you haven't included the method signature, in this case i=> and you haven't included the using System.Linq; into your byte count. You can also drop the trailing semi-colon. My ego is, however, very much intact thank you very much. \$\endgroup\$ – TheLethalCoder Apr 23 '18 at 8:59

PHP, 74 bytes


case insensitive. Run as pipe with -nR or try it online.


C# (.NET Core), 48 + 18 = 66 bytes


+18 bytes is for using System.Linq;

Try it online!

  • \$\begingroup\$ Isnt the function signature part of the code? \$\endgroup\$ – Kristoffer Sall-Storgaard Apr 20 '18 at 22:01
  • \$\begingroup\$ @KristofferSall-Storgaard I'm not actually sure on the code golf rules since I don't post often. I just mimicked TheLethalCoder's setup and tried to save a few bytes. \$\endgroup\$ – Geoffrey Apr 21 '18 at 22:54
  • \$\begingroup\$ I was wrong. It would appear we dont need to name the functions \$\endgroup\$ – Kristoffer Sall-Storgaard Apr 23 '18 at 12:24

T-SQL, 107 bytes

Accepting uppercase characters.

Inserted a line break to make this readable:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.