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!

  • AndyOPM
    link
    fedilink
    arrow-up
    1
    ·
    8 months ago
    Luhn
    USING: combinators.short-circuit.smart kernel math math.functions math.parser sequences sequences.extras sets unicode ;
    
    : luhn? ( str -- ? )
      " " without
      dup { [ length 2 < ] [ [ digit? ] all? not ] } || [ drop f ] [
        string>digits
        reverse [ <evens> sum ] [ <odds> ] bi
        [ 2 * dup 9 > [ 9 - ] when ] map-sum +
        10 divisor?
      ] if
    ;
    
    • AndyOPM
      link
      fedilink
      arrow-up
      1
      ·
      8 months ago
      Luhn, again
      USING: combinators.short-circuit.smart kernel math math.parser rosetta-code.luhn-test sequences sets unicode ;
      
      : ex-luhn? ( str -- ? )
        " " without
        dup {
          [ length 2 < ]
          [ [ digit? ] all? not ]
        } || [ drop f ] [
          string>number luhn?
        ] if
      ;
      
      Luhn, a third time
      USING: combinators.short-circuit.smart kernel math sequences sets unicode validators ;
      
      : ex-luhn? ( str -- ? )
        " " without
        dup {
          [ length 2 < ]
          [ [ digit? ] all? not ]
        } || [ drop f ] [ luhn? ] if
      ;