[ create a new paste ] login | about

Link: http://codepad.org/lSE0apQM    [ raw code | output | fork ]

johannes - Haskell, pasted on Jul 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Main where

import Data.Foldable as F
import Control.Monad
import Control.Applicative

fn a b = liftM2 (++) a b <|> a <|> b

bigbad x = case F.foldr fn Nothing [f 3 "big", f 5 "bad"]
           of (Just a) -> a
              _        -> show x
              where f v s | mod x v == 0 = Just s
                          | otherwise    = Nothing

main = print $ fmap bigbad [1..150]


Output:
1
["1","2","big","4","bad","big","7","8","big","bad","11","big","13","14","bigbad","16","17","big","19","bad","big","22","23","big","bad","26","big","28","29","bigbad","31","32","big","34","bad","big","37","38","big","bad","41","big","43","44","bigbad","46","47","big","49","bad","big","52","53","big","bad","56","big","58","59","bigbad","61","62","big","64","bad","big","67","68","big","bad","71","big","73","74","bigbad","76","77","big","79","bad","big","82","83","big","bad","86","big","88","89","bigbad","91","92","big","94","bad","big","97","98","big","bad","101","big","103","104","bigbad","106","107","big","109","bad","big","112","113","big","bad","116","big","118","119","bigbad","121","122","big","124","bad","big","127","128","big","bad","131","big","133","134","bigbad","136","137","big","139","bad","big","142","143","big","bad","146","big","148","149","bigbad"]


Create a new paste based on this one


Comments: