diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-05-25 00:16:47 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-05-25 01:05:11 +0800 |
commit | 3caa8876e4c1d71cf8973d0d78231f16a0cd5b93 (patch) | |
tree | 37e104696c6aeb589b0771bb2143f1fec715d086 | |
parent | 1eefd58ca4fdb5d2f51f657bfd70c9a89a4707db (diff) | |
download | project_euler-3caa8876e4c1d71cf8973d0d78231f16a0cd5b93.tar.xz |
45, 46, 92
-rw-r--r-- | euler45.myr | 30 | ||||
-rw-r--r-- | euler46.myr | 36 | ||||
-rw-r--r-- | euler92.myr | 27 |
3 files changed, 93 insertions, 0 deletions
diff --git a/euler45.myr b/euler45.myr new file mode 100644 index 0000000..3bf53fc --- /dev/null +++ b/euler45.myr @@ -0,0 +1,30 @@ +use std + +const main = { + for var n: uint64 = 144; true; n++ + var hn = n * (n * 2 - 1) + /* find pentagonal pn = n(3n-1)/2 */ + /* n' < 2/sqrt(3)*n */ + var i: uint64 = n * 148 / 128 + var pn = i * (i * 3 - 1) / 2 + while pn > hn + i-- + pn = i * (i * 3 - 1) / 2 + ;; + if (pn != hn) + continue + ;; + /* find triangle tn = n(n+1)/2, n'<2n */ + i = n*2 + var tn = i * (i + 1) / 2 + while tn > hn + i-- + tn = i * (i + 1) / 2 + ;; + if (tn != hn) + continue + ;; + std.put("n = {}, h[n] = {}\n", n, hn) + break + ;; +} diff --git a/euler46.myr b/euler46.myr new file mode 100644 index 0000000..0aa1180 --- /dev/null +++ b/euler46.myr @@ -0,0 +1,36 @@ +use std + +const isprime = {x + if (x < 1) + -> false + ;; + for var i = 2; i * i <= x; i++ + if (x % i ==0) + -> false + ;; + ;; + -> true +} + +const main = { + for var i = 9; true; i+=2 + if (isprime(i)) + continue + ;; + var found = true + for var j = 1; true; j++ + var t = i - j * j * 2 + if t <= 0 + break + ;; + if (isprime(t)) + found = false + break + ;; + ;; + if found + std.put("{}\n", i) + break + ;; + ;; +} diff --git a/euler92.myr b/euler92.myr new file mode 100644 index 0000000..3092405 --- /dev/null +++ b/euler92.myr @@ -0,0 +1,27 @@ +use std + +const goto89 = {x + const sqrsum = {y + var sum = 0 + while y > 0 + var b = y % 10 + y = y / 10 + sum += b * b + ;; + -> sum + } + while x != 1 && x != 89 + x = sqrsum(x) + ;; + -> x == 89 +} + +const main = { + var n = 0 + for var i = 1; i < 10_000_000; i++ + if goto89(i) + n++ + ;; + ;; + std.put("{}\n", n) +} |