Top Stories published by Essay Club in September of 2013

一道小题目

午饭的时候 @hax 说到一道问题是:“有1分、2分、5分的硬币各无限枚,要凑成1元有多少种凑法?”想到其实 Haskell 挺适合做这种事,吃完饭就解解看。

算法肯定有很多种,因为没有很多算法的基础,我最先想到的就是遍历再筛选这中傻算的方法,于是…上代码:

 module Main where
coin :: Int -> Int
coin 0 = 0
coin n = length $ filter (==n) [a + 2 * b + 5 * c | a <- [0 .. n], b <- [0 .. n]…

About
Essay Club
On a mission to fill the doughnut hole of knowledge.
More information
Tags