We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4e4d470 commit 8bb7f3dCopy full SHA for 8bb7f3d
examples/euler.v
@@ -0,0 +1,18 @@
1
+// This example shows 2 solutions for https://projecteuler.net/problem=1 :
2
+fn gauss_sum(n int) fn (int) int {
3
+ return fn [n] (m int) int {
4
+ return m * ((n - 1) / m) * ((n - 1) / m + 1) / 2
5
+ }
6
+}
7
+
8
+gs := gauss_sum(1000)
9
+println('O(1) arithmetic progression sum: ${gs(3) + gs(5) - gs(15)}')
10
11
+// A brute force solution, by checking every n in the range:
12
+mut sum := 0
13
+for n in 1 .. 1000 {
14
+ if n % 3 == 0 || n % 5 == 0 {
15
+ sum += n
16
17
18
+println('O(n) brute force calculated sum: ${sum}')
0 commit comments