summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-05-27 13:25:10 +0800
committerIru Cai <mytbk920423@gmail.com>2018-05-27 13:25:10 +0800
commit12b78407f3ce4d6ee5f67fb0c6ce5c754cf78a58 (patch)
treec5add6603cb45857977a797f251d9d123464fb57
parent1c76beb0d4ccf57d2db84cf417f37a3a155fb905 (diff)
downloadproject_euler-12b78407f3ce4d6ee5f67fb0c6ce5c754cf78a58.tar.xz
57, 59, 67, 206
-rw-r--r--euler206.c27
-rw-r--r--euler57.scm17
-rw-r--r--euler59.py41
-rw-r--r--euler67.c35
4 files changed, 120 insertions, 0 deletions
diff --git a/euler206.c b/euler206.c
new file mode 100644
index 0000000..2a5b007
--- /dev/null
+++ b/euler206.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+int test(long long t)
+{
+ t = t * t;
+ int b = 9;
+ while (b >= 1) {
+ if (t % 10 != b)
+ return 0;
+ b--;
+ t = t / 100;
+ }
+ return 1;
+}
+
+int main()
+{
+ /* test 1{0000000..5000000}{30,70} */
+ for (long long i = 10000000; i < 15000000; i++) {
+ long long t = i * 10 + 3;
+ if (test(t))
+ printf("%lld0\n", t);
+ t = i * 10 + 7;
+ if (test(t))
+ printf("%lld0\n", t);
+ }
+}
diff --git a/euler57.scm b/euler57.scm
new file mode 100644
index 0000000..aa8972a
--- /dev/null
+++ b/euler57.scm
@@ -0,0 +1,17 @@
+(define (expension n)
+ (define (e n)
+ (if (= n 1) (/ 1 2)
+ (/ 1 (+ 2 (e (- n 1))))))
+ (+ 1 (e n)))
+
+(define (digits n)
+ (if (< n 10) 1 (+ 1 (digits (quotient n 10)))))
+
+(define (solve n)
+ (if (= n 0) 0
+ (+ (solve (- n 1))
+ (let ((t (expension n)))
+ (if (> (digits (numerator t)) (digits (denominator t))) 1 0)))))
+
+(display (solve 1000))
+(newline)
diff --git a/euler59.py b/euler59.py
new file mode 100644
index 0000000..fe297c0
--- /dev/null
+++ b/euler59.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+cipher_bytes = list(map(int, (input().split(','))))
+cipher_with_index = list(zip(range(0, len(cipher_bytes)), cipher_bytes))
+
+def decrypt(key, cwi):
+ def dec(tup):
+ i, c = tup
+ return c^key[i%3]
+
+ return list(map(dec, cwi))
+
+def toText(t):
+ s = ''
+ for c in t:
+ s = s + chr(c)
+ return s
+
+def asciisum(t):
+ s = 0
+ for c in t:
+ s = s + c
+ return s
+
+
+def allprint(a):
+ for c in a:
+ if c >= 0x7f or c < 0x20:
+ return False
+ return True
+
+
+key = [ord('a')] * 3
+
+for key[0] in range(ord('a'), ord('z')+1):
+ for key[1] in range(ord('a'), ord('z')+1):
+ for key[2] in range(ord('a'), ord('z')+1):
+ decrypted = decrypt(key, cipher_with_index)
+ if allprint(decrypted):
+ print(toText(decrypted))
+ print(asciisum(decrypted))
diff --git a/euler67.c b/euler67.c
new file mode 100644
index 0000000..f7a7291
--- /dev/null
+++ b/euler67.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+
+int max(int a, int b)
+{
+ if (a > b)
+ return a;
+ else
+ return b;
+}
+
+int main()
+{
+ int triangle[100][100];
+ int sol[100][100];
+ int i, j, n, a;
+
+ n = 0;
+ while (scanf("%d", &a)!=EOF) {
+ triangle[n][0] = a;
+ for (i = 1; i <= n; i++)
+ scanf("%d", &triangle[n][i]);
+ n++;
+ }
+
+ for (i = 0; i < n; i++)
+ sol[n-1][i] = triangle[n-1][i];
+
+ for (i = n-2; i >= 0; i--) {
+ for (j = 0; j <= i; j++) {
+ sol[i][j] = triangle[i][j] + max(sol[i+1][j], sol[i+1][j+1]);
+ }
+ }
+
+ printf("%d\n", sol[0][0]);
+}