Comment detail

正しい文(クイズ) (Nested Flatten)

This comment is reply for 4367 shiro: ナイーブな総当たりを書いてみましたが、n...(正しい文(クイズ)). Go to thread root.

高階関数を使って。
書き換えた部分のみ。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import List
import Maybe

count pred xs = length $ filter pred xs

countDigs' radix ks = map sum $ transpose $ map (countDigs radix) ks

combListsS n lim = sequence $ replicate n [1..lim-1]

combLists'' n = [1..] >>= combListsM n

check radix xss = mapMaybe f xss  where
  f xs = if xs' == cs then Just xs' else Nothing  where
    xs' = reverse xs
    cs = map (+1) $ countDigs' radix xs'

showResult radix xs = ("この文は" ++) $ (++ "あります。")
  $ concat $ intersperse ", "
  $ map ct [0..radix-1]
  where ct i = show i ++ "が" ++ showIntAtBase radix intToDigit (xs!!i) "個"

Index

Feed

Other

Link

Pathtraq

loading...