Problem 111

http://projecteuler.net/index.php?section=problems&id=111

普通の解法、同じ数が多い連続数から作って、素数かチェック。

import Number
import Data.Char
import Data.List
toInt = read.map intToDigit :: [Int]->Integer
repDigit (d+1) m (n+1) = [k:xs | k<-[1..9], k/=,
xs<-repDigit' d m $ if k==m then n-1 else n]
repDigit'  _  = [[]]
repDigit'  _ _ = []
repDigit' d m n
| d < n = []
| d == n = [replicate d m]
| otherwise = [k:xs | k<-[..9],
xs<-repDigit' (d-1) m $ if k==m then n-1 else n]
repPrime d m = head.dropWhile null. map (repPrime' d m) $ [d,d-1..1]
repPrime' d m = filter isPrime'.map toInt.repDigit d m
main = print.sum.map (sum.repPrime 10)$[..9]
More Reading
Newer// Problem 109
Older// Problem 118