Created
September 1, 2016 20:55
-
-
Save iliyan-trifonov/e6aa222cc0c47b4be2558d45207595fd to your computer and use it in GitHub Desktop.
Solution 3 for Project Euler problem 1 written in Elm
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
-- we will show the result with a single html text node | |
import Html exposing (text) | |
-- let's call the function euler1 and say it receives a single Int param and returns a single Int param | |
euler1 : Int -> Int | |
euler1 num = | |
-- no recursion this time, only lists | |
let | |
-- create a list with numbers from 1 to num - 1 | |
list = [1..num-1] | |
-- remove all of the numbers in the list which are not divisable by 3 or 5 | |
list2 = List.filter (\num -> num % 3 == 0 || num % 5 ==0) list | |
in | |
-- return the sum of all of the good numbers | |
List.sum list2 | |
main = | |
-- convert from String to Int and show the result with a text node | |
-- param = 10 because we need to get the sum of all the numbers below 10 that pass the test | |
text ( toString ( euler1 10 ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment