Skip to content

Instantly share code, notes, and snippets.

@iliyan-trifonov
Last active September 1, 2016 20:43
Show Gist options
  • Save iliyan-trifonov/ea23863a8dc9f5d0925f1fcd8b66c8b7 to your computer and use it in GitHub Desktop.
Save iliyan-trifonov/ea23863a8dc9f5d0925f1fcd8b66c8b7 to your computer and use it in GitHub Desktop.
Solution 1 for Project Euler problem 1 written in Elm
-- 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 =
-- break point of the recursion is when num is 0
if num == 0 then
0
else
-- check if the number is divisable by 3 or 5
if num % 3 == 0 || num % 5 == 0 then
-- if yes, return the sum of the number and any other numbers detected
num + euler1 (num-1)
else
-- if no, skip this number, go look for others and return their sum
euler1 (num-1)
main =
-- convert from String to Int and show the result with a text node
-- 10-1 because we need to find all numbers below 10
text ( toString ( euler1 (10-1) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment