Just because Exercism doesn’t offer your favorite language as an official track, it doesn’t mean we can’t play at all. Post some solutions to the weekly challenges in the language of your choice!

  • Andy@programming.devOPM
    link
    fedilink
    arrow-up
    1
    ·
    3 months ago
    Scrabble Score, again
    USING: combinators kernel sequences sets unicode ;
    
    MEMO: char>score ( char -- n )
      {
        { [ dup "AEIOULNRST" in? ] [  1 ] }
        { [ dup         "DG" in? ] [  2 ] }
        { [ dup       "BCMP" in? ] [  3 ] }
        { [ dup      "FHVWY" in? ] [  4 ] }
        { [ dup          "K" in? ] [  5 ] }
        { [ dup         "JX" in? ] [  8 ] }
        { [ dup         "QZ" in? ] [ 10 ] }
      } cond nip ;
    
    : scrabble-score ( str -- n )
      >upper [ char>score ] map-sum ;
    
    • Andy@programming.devOPM
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago
      Scrabble Score, a third time
      USING: assocs.extras kernel make sequences unicode ;
      
      : scrabble-score ( str -- n )
        >upper
        [
          "AEIOULNRST" [  1 swap ,, ] each
                  "DG" [  2 swap ,, ] each
                "BCMP" [  3 swap ,, ] each
               "FHVWY" [  4 swap ,, ] each
                   "K" [  5 swap ,, ] each
                  "JX" [  8 swap ,, ] each
                  "QZ" [ 10 swap ,, ] each
        ] H{ } make
        swap values-of sum ;
      
      • Andy@programming.devOPM
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago
        Scrabble Score, 3.5
        USING: assocs.extras kernel literals make sequences unicode ;
        
        CONSTANT: charscores $[
          [
            "AEIOULNRST" [  1 swap ,, ] each
                    "DG" [  2 swap ,, ] each
                  "BCMP" [  3 swap ,, ] each
                 "FHVWY" [  4 swap ,, ] each
                     "K" [  5 swap ,, ] each
                    "JX" [  8 swap ,, ] each
                    "QZ" [ 10 swap ,, ] each
          ] H{ } make
        ]
        
        : scrabble-score ( str -- n )
          charscores swap >upper values-of sum ;
        
        • Andy@programming.devOPM
          link
          fedilink
          arrow-up
          1
          ·
          2 months ago
          Scrabble Score 4.0
          USING: assocs.extras kernel literals make sequences unicode ;
          
          CONSTANT: charscores $[
            [
              { 1 2 3 4 5 8 10 }
              { "AEIOULNRST" "DG" "BCMP" "FHVWY" "K" "JX" "QZ" }
              [ [ ,, ] with each ] 2each
            ] H{ } make
          ]
          
          : scrabble-score ( str -- n )
            charscores swap >upper values-of sum ;