レジで小銭をスムーズに支払う方法
http://www.itmedia.co.jp/bizid/articles/0611/22/news045.html
財布から硬貨を出すより片付ける方がコストかからないから、22円持ってるより77円持ってたほうが対応しやすいのね。
ならコスト計算おかしいやん。99円がベスト?そういえば小銭77円も持ってないな。
import List coins n = snd $ foldl f (n, []) [50, 10, 5, 1] where f (n, lst) c = let (q, r) = n `divMod` c in (r, q:lst) cost n = let cs = coins n in sum $ map (\i -> sum $ zipWith (\a b -> abs (a - b)) cs (coins i)) [0..99]
> take 5 $ sortBy (\(_, a) (_, b) -> a `compare` b) $ map (\n -> (n, cost n)) [0..99] [(22,340),(27,340),(72,340),(77,340),(12,360)]