From 95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Tue, 18 Aug 2015 16:06:19 +0200 Subject: Exported all problems from the SQLite database into the new directory structure. --- prolog/problems/old_exams/pascal_3/common.py | 16 ++++++++++++++++ prolog/problems/old_exams/pascal_3/en.py | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 prolog/problems/old_exams/pascal_3/common.py create mode 100644 prolog/problems/old_exams/pascal_3/en.py (limited to 'prolog/problems/old_exams/pascal_3') diff --git a/prolog/problems/old_exams/pascal_3/common.py b/prolog/problems/old_exams/pascal_3/common.py new file mode 100644 index 0000000..7fcb55e --- /dev/null +++ b/prolog/problems/old_exams/pascal_3/common.py @@ -0,0 +1,16 @@ +id = 179 +group = 'old_exams' +number = 86 +visible = False +facts = None + +solution = '''\ +pascal(_, 0, 1) :- !. +pascal(I, I, 1) :- !. +pascal(I, J, N) :- + I1 is I - 1, + J1 is J - 1, + pascal(I1, J, N1), + pascal(I1, J1, N2), + N is N1 + N2. +''' diff --git a/prolog/problems/old_exams/pascal_3/en.py b/prolog/problems/old_exams/pascal_3/en.py new file mode 100644 index 0000000..31a0d47 --- /dev/null +++ b/prolog/problems/old_exams/pascal_3/en.py @@ -0,0 +1,26 @@ +id = 179 +name = 'pascal/3' +slug = 'pascal's triangle' + +description = '''\ +

The first five rows of the Pascal's triangle look like this:

+
+        1
+       1 1
+      1 2 1
+     1 3 3 1
+    1 4 6 4 1
+
+

+Each row begins and ends with 1. Every other element can be obtained as a sum of the two values above it. Write the predicate pascal(I,J,N) that returns the J-th value in the I-th column of the Pascal's triangle. Your solution should return exactly one answer for any input (the I and J arguments start counting with 0; you can assume that 0 ≤ JI). + +

+  ?- pascal(0, 0, N).
+    N = 1.
+  ?- pascal(2, 1, N).
+    N = 2.
+  ?- pascal(4, 3, N).
+    N = 4.
+
''' + +hint = {} -- cgit v1.2.1