Skip to content

Instantly share code, notes, and snippets.

@jayrbolton
Last active July 30, 2019 21:29
Show Gist options
  • Save jayrbolton/fa7eb854cf7a283a24f0c55fa0c8350b to your computer and use it in GitHub Desktop.
Save jayrbolton/fa7eb854cf7a283a24f0c55fa0c8350b to your computer and use it in GitHub Desktop.
# Sum of multiples of `n` up to `limit
# eg: 18 is the sum of multiples of 3 up to 10 (3, 6, 9)
fun mul_sum n:int lim:int -> int
| sum <- 0
| counter <- 1
| mul <- n
$ loop while !lt mul lim
| counter <- !inc counter
| mul <- !add mul n
| sum <- !add sum mul
$ repeat
$ return sum
# Proj euler problem 1
# Sum of multiples of 3 and 5 up to 1000
fun mul_sum_3_5 -> int
| sum3 <- !mul_sum 3 1000
| sum5 <- !mul_sum 5 1000
| sum3_5 <- !add sum3 sum5
# subtract the common multiples (we have overcounted them)
| sum15 <- !mul_sum 15 1000
| result <- !sub sum15 sum3_5
$ return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment