summaryrefslogtreecommitdiff
path: root/euler49.myr
diff options
context:
space:
mode:
Diffstat (limited to 'euler49.myr')
-rw-r--r--euler49.myr53
1 files changed, 53 insertions, 0 deletions
diff --git a/euler49.myr b/euler49.myr
new file mode 100644
index 0000000..4003767
--- /dev/null
+++ b/euler49.myr
@@ -0,0 +1,53 @@
+use std
+
+const isprime = {n
+ if n == 1 || n % 2 == 0
+ ->false
+ ;;
+ for var i = 3; i * i <= n; i++
+ if n % i == 0
+ -> false
+ ;;
+ ;;
+ -> true
+}
+
+const isperm = {a, b
+ var dmap: int[10]
+ for var i = 0; i < 10; i++
+ dmap[i] = 0
+ ;;
+ while a > 0
+ dmap[a % 10] ++
+ a /= 10
+ ;;
+ while b > 0
+ var t = b % 10
+ dmap[t] --
+ if dmap[t] < 0
+ -> false
+ ;;
+ b /= 10
+ ;;
+ -> true
+}
+
+const main = {
+ for var i = 1001; i < 9999; i++
+ if !isprime(i)
+ continue
+ ;;
+ for var j = 2; i + j * 2 <= 9999; j ++
+ var t1 = i + j
+ var t2 = t1 + j
+ if !isprime(t1) || !isprime(t2)
+ continue
+ ;;
+ if !isperm(i, t1) || !isperm(i, t2)
+ continue
+ ;;
+ std.put("{} {} {}\n", i, t1, t2)
+ ;;
+ ;;
+}
+