Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reimplement euler001 as infinite list processing
- Loading branch information
1 parent
ca00c5e
commit 318a61c
Showing
2 changed files
with
22 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
|
|||
module Main where | |||
|
|||
import System.IO | |||
|
|||
sum3_5 0 = 0 | |||
sum3_5 n | |||
| n `mod` 3 == 0 = n + sum3_5(n-1) | |||
| n `mod` 5 == 0 = n + sum3_5(n-1) | |||
| otherwise = sum3_5(n-1) | |||
|
|||
main :: IO() | |||
main = do | |||
print (sum3_5 999) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,14 +1,9 @@ | |||
|
|
||
module Main where | sum3_5 n = [x|x <- [1..], mod x 3 == 0 || mod x 5 == 0] `sum_to` n | ||
|
where | ||
import System.IO | sum_to (x:xs) n | ||
|
| x >= n = 0 | ||
sum3_5 0 = 0 | | otherwise = x + (xs `sum_to` n) | ||
sum3_5 n |
|
||
| n `mod` 3 == 0 = n + sum3_5(n-1) | main = do | ||
| n `mod` 5 == 0 = n + sum3_5(n-1) | print $ sum3_5 1000 | ||
| otherwise = sum3_5(n-1) | |||
|
|||
main :: IO() | |||
main = do | |||
print (sum3_5 999) |