Comment detail

自然数の分割 (Nested Flatten)

This comment is reply for 4303 shiro: comprehension大活躍。(自然数の分割). Go to thread root.

高階関数を使った版。

コード長くなった、読みづらくなった。orz
1
2
3
4
5
import List

partitionNum n m = iterate f ([[]]: repeat []) !! m !! n  where
  f xs = tail $ snd $ mapAccumL g (repeat []) [0..] where
    g (y:ys) i = (zipWith (++) (map (map (i:)) xs) ys, y)

Index

Feed

Other

Link

Pathtraq

loading...