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
Unassembled.
; 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)
SCRAB_SCORE MACRO I, IL, TBL, SC
LOCAL LOOP_LETTER, ODD
IFDIFI <I>,<SI> ; skip if I is already SI
MOV SI, I ; load string into SI
ENDIF
IFDIFI <IL>,<CX> ; skip if IL is already CX
MOV CX, IL ; set up loop counter
ENDIF
MOV BX, OFFSET TBL ; load score table into BX
LOOP_LETTER:
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
ODD:
AND AL, 0FH ; mask low nibble
ADD SC, AL ; add letter score to total
LOOP LOOP_LETTER
ENDM
; Score table
SCTBL DB 013H,032H,014H,024H,018H,051H,031H,013H,0A1H,011H,014H,048H,04AH
Explanation
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.
Output
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
SCRAB_SCORE SI, CX, SCTBL, DL
MOV AX, DX ; put score in AX for OUTDEC display
CALL OUTDEC ; generic decimal display routine
![enter image description here](../../I/static/images/6c611013e1f3a4e14ff5030d18be93c9ebd7be1096d1424635a0608039ca5484.png)
6I'm hoping to see a MATLAB/Octave solution. All my attempts were horribly long... =/ – Stewie Griffin – 2018-04-17T19:04:37.053
4I'm hoping to see a Beatnik solution. Cuz, you know, that would be the right tool for the job. – Giuseppe – 2018-04-17T19:28:16.417
@StewieGriffin Does 85 bytes count as horribly long? – Luis Mendo – 2018-04-17T21:11:06.003
3Hasn't Mathematica a built-in for it? – sergiol – 2018-04-18T00:30:44.820
@StewieGriffin Down to 73 with Octave now. – Tom Carpenter – 2018-04-18T06:06:22.377
@LuisMendo Is 85 bytes horribly long compared to 50...? :) – Sanchises – 2018-04-18T08:31:57.657
@StewieGriffin I've been thinking of making a more complex Scrabble challenge. Unless someone else does it first I may (finally) go ahead and do that. – manassehkatz-Moving 2 Codidact – 2018-04-18T17:50:08.217
1
@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.
– Stewie Griffin – 2018-04-18T19:37:15.607@StewieGriffin Are we allowed to have the program fail if the input is longer than what fits on a Scrabble board (15)? – mbomb007 – 2018-04-20T16:20:21.940
It should work for the test cases @mbomb007. You have plenty of tiles (and boards) available. You may add it as a "this would work if...", if it's an interesting/fun/short solution. :-) – Stewie Griffin – 2018-04-20T16:44:05.420
@StewieGriffin Added to Sandbox - please take a look at it. – manassehkatz-Moving 2 Codidact – 2018-04-22T03:51:35.083