Skip to content

Instantly share code, notes, and snippets.

@iliyan-trifonov
Created September 1, 2016 20:47
Show Gist options
  • Save iliyan-trifonov/7246eb2ffbacd5106ef1176df4eac4b7 to your computer and use it in GitHub Desktop.
Save iliyan-trifonov/7246eb2ffbacd5106ef1176df4eac4b7 to your computer and use it in GitHub Desktop.
Solution 2 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 two Int params and returns a single Int param
euler1 : Int -> Int -> Int
euler1 num numMax =
-- break point of the recursion is when num increased to numMax
if num == numMax 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) numMax
else
-- if no, skip this number, go look for others and return their sum
euler1 (num+1) numMax
main =
-- convert from String to Int and show the result with a text node
-- 1 10 because we need to give the starting num and the constant numMax, range: 1..9
text ( toString ( euler1 1 10 ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment