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
    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
    ;
    
    • Andy@programming.devOPM
      link
      fedilink
      arrow-up
      1
      ·
      3 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
      ;