about summary refs log tree commit diff
path: root/others
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-19 22:28:52 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-19 22:28:52 +0700
commitd40c9b81db3caff8ecca79df92241bc0c28a468c (patch)
tree41985e48e9da1fbfb65af8105bfa0304744320bd /others
parenta53c4128c29f98b5fdfd9b0e13a3bbe094d975ec (diff)
downloadcp-d40c9b81db3caff8ecca79df92241bc0c28a468c.tar.gz
Translate easy programs to Scheme
Diffstat (limited to 'others')
-rw-r--r--others/mHoang/decor.scm2
-rw-r--r--others/mHoang/pfactor.scm9
-rw-r--r--others/mHoang/triangle.scm5
-rw-r--r--others/other/README.md48
-rw-r--r--others/other/game.pas62
-rw-r--r--others/volume1/000.scm2
-rw-r--r--others/volume1/001.scm2
-rw-r--r--others/volume1/003.scm8
-rw-r--r--others/volume1/006.scm8
9 files changed, 36 insertions, 110 deletions
diff --git a/others/mHoang/decor.scm b/others/mHoang/decor.scm
new file mode 100644
index 0000000..1b4cea2
--- /dev/null
+++ b/others/mHoang/decor.scm
@@ -0,0 +1,2 @@
+(display (exact-integer-sqrt (read)))
+(newline)
diff --git a/others/mHoang/pfactor.scm b/others/mHoang/pfactor.scm
new file mode 100644
index 0000000..4e3bd17
--- /dev/null
+++ b/others/mHoang/pfactor.scm
@@ -0,0 +1,9 @@
+(define (div dividend divisor)
+  (if (= (remainder dividend divisor) 0)
+      (div (/ dividend divisor) divisor)
+      dividend))
+(display (let* ((n (read)) (s (exact-integer-sqrt n)))
+           (do ((i 2 (+ i 1)))
+               ((or (= (div n i) 1) (> i s)) (if (> i s) n i))
+             (set! n (div n i)))))
+(newline)
diff --git a/others/mHoang/triangle.scm b/others/mHoang/triangle.scm
new file mode 100644
index 0000000..33a154b
--- /dev/null
+++ b/others/mHoang/triangle.scm
@@ -0,0 +1,5 @@
+(define (angel-90 a b c)
+  ((lambda (x) (if (= x 0) 0 (/ x (abs x)))) (+ (* a a) (* b b) (- (* c c)))))
+(display (let ((a (read)) (b (read)) (c (read)))
+           (modulo (* (angel-90 a b c) (angel-90 b c a) (angel-90 c a b)) 3)))
+(newline)
diff --git a/others/other/README.md b/others/other/README.md
index 067ea64..a50ae60 100644
--- a/others/other/README.md
+++ b/others/other/README.md
@@ -82,54 +82,6 @@ liên tiếp chọn được.
 | 5<br>2 9 3 7 4     |     3    | Chọn dãy 2, 3, 4                     |
 | 7<br>1 2 4 7 6 0 8 |     5    | Thay 0 bởi 5, chọn dãy 4, 5, 6, 7, 8 |
 
-## Trò chơi với dãy số
-
-Hai bạn học sinh trong lúc nhàn rỗi nghĩ ra trò chơi sau đây:
-
-* Mỗi bạn chọn trước một dãy số gồm n số nguyên. Giả sử dãy số mà bạn thứ nhất
-  chọn là (b<sub>1</sub>, b<sub>2</sub>, …, b<sub>n</sub>) còn dãy số bạn thứ
-  hai chọn là (c<sub>1</sub>, c<sub>2</sub>, …, c<sub>n</sub>).
-* Mỗi lượt chơi mỗi bạn đưa ra một số hạng trong dãy số của mình. Nếu bạn thứ
-  nhất đưa ra số hạng b<sub>i</sub>, còn bạn thứ hai đưa ra số hạng
-  c<sub>j</sub> thì giá của lượt chơi đó sẽ là |b<sub>i</sub> + c<sub>j</sub>|.
-
-### Yêu cầu
-
-Hãy xác định giá nhỏ nhất của một lượt chơi trong số các lượt chơi có thể.
-
-### Dữ liệu
-
-Tệp `GAME.INP` gồm ba dòng:
-
-* Dòng đầu tiên chứa số nguyên dương n.
-* Dòng thứ hai chứa dãy số nguyên b<sub>1</sub>, b<sub>2</sub>, …,
-  b<sub>n</sub>.
-* Dòng thứ ba chứa dãy số nguyên c<sub>1</sub>, c<sub>2</sub>, …,
-  c<sub>n</sub>.
-
-### Kết quả
-
-Tệp `GAME.OUT` gồm một dòng ghi giá nhỏ nhất tìm được.
-
-### Giới hạn
-
-* n ≤ 10<sup>5</sup>.
-* |b<sub>i</sub>|, |c<sub>j</sub>| < 2<sup>63</sup> ∀ 1 ≤ i, j ≤ n.
-
-### Ví dụ
-
-|     GAME.INP     | GAME.OUT |
-| ---------------- | :------: |
-| 2<br>1 -2<br>2 3 |     0    |
-
-#### Giải thích
-
-Dãy số bạn thứ nhất chọn là (1, −2) còn dãy số mà bạn thứ hai chọn là (2,3).
-
-Khi đó các khả năng có thể của một lượt chơi là (1,2), (1,3), (−2,2), (−2,3).
-Như vậy, giá nhỏ nhất của một lượt chơi trong số các lượt chơi có thể là 0
-tương ứng với giá của lượt chơi (−2,2).
-
 ## Tìm đoạn thẳng v2
 
 Trên 1 đoạn trục số [−c, c], cho N đoạn thẳng, đoạn thứ i là [a<sub>i</sub>,
diff --git a/others/other/game.pas b/others/other/game.pas
deleted file mode 100644
index 5be1da2..0000000
--- a/others/other/game.pas
+++ /dev/null
@@ -1,62 +0,0 @@
-uses
-  sortnfind;
-
-var
-  f: text;
-  n, i, j: smallint;
-  b: array of int64;
-  c: int64;
-  a: qword = 0;
-
-
-function sign(x: int64): shortint;
-  begin
-    if x < 0 then
-      exit(-1);
-    exit(1)
-  end;
-
-
-function min(
-  x: qword;
-  y, z: int64
-): qword;
-
-  var
-    tmp: qword;
-
-  begin
-    if sign(y) = sign(z) then
-      tmp := abs(y) + abs(z)
-    else if abs(y) < abs(z) then
-      tmp := abs(z) - abs(y)
-    else
-      tmp := abs(y) - abs(z);
-
-    if tmp < x then
-      exit(tmp);
-    exit(x)
-  end;
-
-
-begin
-  assign(f, 'GAME.INP');
-  reset(f);
-  readln(f, n);
-  setlength(b, n);
-  for i := 0 to n - 1 do
-    read(f, b[i]);
-  qsort(b);
-  for i := 0 to n - 1 do
-    begin
-      read(f, c);
-      for j := 0 to n - 1 do
-        a := min(a, b[j], c)
-    end;
-  close(f);
-
-  assign(f, 'GAME.OUT');
-  rewrite(f);
-  writeln(f, a);
-  close(f)
-end.
diff --git a/others/volume1/000.scm b/others/volume1/000.scm
new file mode 100644
index 0000000..2757887
--- /dev/null
+++ b/others/volume1/000.scm
@@ -0,0 +1,2 @@
+(display (let* ((a (read)) (b (read)) (c (read)) (d (read)))
+           (if (> c b) "NO\n" "YES\n")))
diff --git a/others/volume1/001.scm b/others/volume1/001.scm
new file mode 100644
index 0000000..4e6573b
--- /dev/null
+++ b/others/volume1/001.scm
@@ -0,0 +1,2 @@
+(display (let ((a (read)) (b (read))) (exact->inexact (/ (+ a b) 2))))
+(newline)
diff --git a/others/volume1/003.scm b/others/volume1/003.scm
new file mode 100644
index 0000000..21431e7
--- /dev/null
+++ b/others/volume1/003.scm
@@ -0,0 +1,8 @@
+(define n (read))
+(display (string-length (number->string n)))
+(display " ")
+(define (digitsum n) (if (> n 0)
+                         (+ (modulo n 10) (digitsum (quotient n 10)))
+                         0))
+(display (digitsum n))
+(newline)
diff --git a/others/volume1/006.scm b/others/volume1/006.scm
new file mode 100644
index 0000000..f791de2
--- /dev/null
+++ b/others/volume1/006.scm
@@ -0,0 +1,8 @@
+(display ((lambda (str from to)
+            (let ((i (string-index str (string->char-set from))))
+              (string-replace str to i (+ i (string-length from)))))
+          (number->string (let* ((a (read)) (b (read)) (c (read)) (d (read)))
+                            (+ (/ a b) (/ c d))))
+          "/"
+          " "))
+(newline)