Kirjautuminen

Haku

Tehtävät

Keskustelu: Koodit: 8th: Pangrammi

jalski [22.06.2022 22:13:51]

#

Alla esimerkkinä pari naiivia tapaa nopeampaa mahdollisuutta selvittää onko merkkijono pangrammi:

[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  %1,
  %10,
  %100,
  %1000,
  %10000,
  %100000,
  %1000000,
  %10000000,
  %100000000,
  %1000000000,
  %10000000000,
  %100000000000,
  %1000000000000,
  %10000000000000,
  %100000000000000,
  %1000000000000000,
  %10000000000000000,
  %100000000000000000,
  %1000000000000000000,
  %10000000000000000000,
  %100000000000000000000,
  %1000000000000000000000,
  %10000000000000000000000,
  %100000000000000000000000,
  %1000000000000000000000000,
  %10000000000000000000000000 ] constant bits

%11111111111111111111111111 constant all-ones

: pangram?  \ s -- T
  0 swap s:lc
  ( bits swap a:@ nip n:bor ) s:each!
  all-ones n:= ;

[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
  73, 79, 83, 89, 97, 101 ] constant primes

primes ' n:* 1 a:reduce constant prime-hash

: perfect-pangram?  \ s -- T
  1 swap s:lc
  ( primes swap a:@ nip n:* ) s:each!
  prime-hash n:= ;

: app:main
  "The quick brown fox jumps over the lazy dog" pangram? . cr
  "Mr Jock, TV quiz PhD, bags few lynx" perfect-pangram? . cr ;

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta