[ create a new paste ] login | about

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

mohit_at_codepad - Haskell, pasted on Mar 14:
1
2
3
4
5
6
7
8
9
10
11
12
-- Written by Mohit Jain
-- Problem statement: Print all prime number in given range
main = showPrimeNumbersUpTo 321 where
       showPrimeNumbersUpTo = putStrLn . unlines . printPrimes

printPrimes n = if n < 2 then [] else filterPrimesFromList [2..n] where
                filterPrimesFromList = map show . removeNonPrimes

removeNonPrimes [] = []
removeNonPrimes (x:xs) = x : removeNonPrimes rem where
                         rem = filter nonZeroRem xs
                         nonZeroRem z = 0 /= z `mod` x


Output:
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
211
223
227
229
233
239
241
251
257
263
269
271
277
281
283
293
307
311
313
317



Create a new paste based on this one


Comments: