[ create a new paste ] login | about

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

coldgrnd - Haskell, pasted on Feb 28:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import Data.Maybe(listToMaybe)
import qualified Data.Set as S

smallestNumber :: Int -> Maybe Int
smallestNumber n = listToMaybe [a + b*10 + c*100 | c <- [0..9],
                                                   b <- [0..9],
                                                   a <- [0..9],
                                                   a*b*c == n]

findAdditionals :: Ord a => [a] -> [a] -> [a]
findAdditionals xs ys = foldl (\acc x-> if S.member x s then acc else x:acc) [] ys
  where s = S.fromList xs

main = do
  print $ smallestNumber 100
  print $ smallestNumber 20
  print $ smallestNumber 476
  print $ findAdditionals [4,7,9,6,1,3,8] [3,4,1,8,2,9,5,7,6]


Output:
1
2
3
4
Just 455
Just 145
Nothing
[5,2]


Create a new paste based on this one


Comments: