Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- rename Challenge.txt => README.txt

- fix some whitespace issues in Challenge.txt / README.txt
  • Loading branch information...
commit 3ba653f479def3c190356190a8da7d105116074f 1 parent 8b5c046
@smtlaissezfaire authored
Showing with 144 additions and 142 deletions.
  1. +144 −142 ChallengeFiles/Challenge.txt → README.txt
View
286 ChallengeFiles/Challenge.txt → README.txt
@@ -11,22 +11,22 @@ To gain maximum learning from these challenges, you must
follow the rules. The rules of the challenge are:
(1) You must design and program your solutions yourself,
- without seeking out anyone else's solutions;
-
+ without seeking out anyone else's solutions;
+
(2) You may ask any number of questions, but only those
- with a yes/no answer;
-
+ with a yes/no answer;
+
(3) You must swear to destroy your solutions and
- never to show them to anyone else.
-
+ never to show them to anyone else.
+
Begin with the first challenge, and work through them in order.
As you come up with a solution for each one, email it to the
TXL oracle, oracle@txl.ca, for confirmation and advice
-on how your solution could be improved.
+on how your solution could be improved.
-You may email the oracle f you need answers to yes/no questions
-while working on the problems. Answers and evaluations of solutions
-can also be provided by any experienced TXL programmer, all of
+You may email the oracle f you need answers to yes/no questions
+while working on the problems. Answers and evaluations of solutions
+can also be provided by any experienced TXL programmer, all of
whom have been sworn to secrecy during their own initiation into
the mysteries of TXL.
@@ -38,7 +38,7 @@ directory, and get the Turing grammar.
You should then write a TXL program that does the following
thing: replace every if-then-elsif-then-elsif-then-else-end if
-statement by an equivalent nested if-then-else-end if
+statement by an equivalent nested if-then-else-end if
statement (i.e, the equivalent to translating if statements
from Turing to standard Pascal or C).
@@ -46,56 +46,58 @@ Here's an example of what it should do:
Input (silly meaningless example):
- var x,y,z,m,n := 1
- if x = y then
- z :=1
- elsif x = m then
- put "hi"
- k := 3
- elsif m > n then
- if m = 5 then
- x := m * n
- elsif y = z then
- x := 4
- end if
- put x
- else
- put "that's it"
- end if
- put "done"
+ var x,y,z,m,n := 1
+
+ if x = y then
+ z :=1
+ elsif x = m then
+ put "hi"
+ k := 3
+ elsif m > n then
+ if m = 5 then
+ x := m * n
+ elsif y = z then
+ x := 4
+ end if
+ put x
+ else
+ put "that's it"
+ end if
+ put "done"
Output:
- var x,y,z,m,n := 1
- if x = y then
- z :=1
- else
- if x = m then
- put "hi"
- k := 3
- else
- if m > n then
- if m = 5 then
- x := m * n
- else
- if y = z then
- x := 4
- end if
- end if
- put x
- else
- put "that's it"
- end if
- end if
- end if
- put "done"
+ var x,y,z,m,n := 1
+
+ if x = y then
+ z :=1
+ else
+ if x = m then
+ put "hi"
+ k := 3
+ else
+ if m > n then
+ if m = 5 then
+ x := m * n
+ else
+ if y = z then
+ x := 4
+ end if
+ end if
+ put x
+ else
+ put "that's it"
+ end if
+ end if
+ end if
+ put "done"
Your solution must work for any Turing program, no matter
how large or complex, and should fix every if statement in
the entire program in one run.
-A really good solution to this in TXL is no more than 25 lines or so.
+A really good solution to this in TXL is no more than 25 lines or so.
It is not necessary to change the Turing grammar in any way.
-If you get over 40 lines you are probably barking up the wrong tree.
+If you get over 40 lines you are probably barking up the wrong tree.
You can ask me any yes/no question about the problem or your
attempts at it. I'll try to answer quickly.
@@ -125,10 +127,10 @@ no elsif's, if you believe that will help.
TXL Challenge #3
-Now we get down to something resembling what TXL is really used
+Now we get down to something resembling what TXL is really used
for, and something that will demonstrate the power of the language.
In this challenge, you are to write a TXL program that will take
-an arbitrary Turing program containing case statements, and
+an arbitrary Turing program containing case statements, and
translate every case statement in the program into an equivalent
if-the-elsif-then-else-end if statement.
@@ -136,55 +138,55 @@ Here's an example of what it should do:
Input (silly meaningless example):
- var x,y,z,m,n := 1
- case x of
- label 2:
- z :=1
- label 1:
- put "hi"
- k := 3
- label 4:
- case m of
- label 5:
- x := m * n
- label 7:
- x := 4
- end case
- put x
- label:
- put "that's it"
- end case
- put "done"
+ var x,y,z,m,n := 1
+ case x of
+ label 2:
+ z :=1
+ label 1:
+ put "hi"
+ k := 3
+ label 4:
+ case m of
+ label 5:
+ x := m * n
+ label 7:
+ x := 4
+ end case
+ put x
+ label:
+ put "that's it"
+ end case
+ put "done"
Output:
- var x,y,z,m,n := 1
- if x = 2 then
- z :=1
- elsif x = 1 then
- put "hi"
- k := 3
- elsif x = 4 then
- if m = 5 then
- x := m * n
- elsif m = 7 then
- x := 4
- end if
- put x
- else
- put "that's it"
- end if
- put "done"
+ var x,y,z,m,n := 1
+ if x = 2 then
+ z :=1
+ elsif x = 1 then
+ put "hi"
+ k := 3
+ elsif x = 4 then
+ if m = 5 then
+ x := m * n
+ elsif m = 7 then
+ x := 4
+ end if
+ put x
+ else
+ put "that's it"
+ end if
+ put "done"
In this transform you will have to make use of almost
every feature of TXL (but not quite, some are reserved for
-challenge #4!). You will have to learn how to create something
-out of nothing (since there are no if statements in the input
-and you must make some in the output), and you will have to use
-subrules to handle some of the transform (since it cannot all be
-done in one rule).
-
-You may find it helpful to introduce overrides (new definitions)
-for some of the nonterminals of the Turing grammar to help
+challenge #4!). You will have to learn how to create something
+out of nothing (since there are no if statements in the input
+and you must make some in the output), and you will have to use
+subrules to handle some of the transform (since it cannot all be
+done in one rule).
+
+You may find it helpful to introduce overrides (new definitions)
+for some of the nonterminals of the Turing grammar to help
make the transform easier (but this isn't necessary).
@@ -202,51 +204,51 @@ Here's an example of what it should do:
Input (silly meaningless example):
- var x,y,z,m,n := 1
- if x = 2 then
- z :=1
- elsif x = 1 then
- if m = 5 then
- x := m * n
- elsif m < 7 then
- x := 4
- end if
- put "hi"
- elsif x = 4 then
- if m = 5 then
- x := m * n
- elsif k = 7 then
- x := 4
- end if
- put x
- else
- put "that's it"
- end if
- put "done"
+ var x,y,z,m,n := 1
+ if x = 2 then
+ z :=1
+ elsif x = 1 then
+ if m = 5 then
+ x := m * n
+ elsif m < 7 then
+ x := 4
+ end if
+ put "hi"
+ elsif x = 4 then
+ if m = 5 then
+ x := m * n
+ elsif k = 7 then
+ x := 4
+ end if
+ put x
+ else
+ put "that's it"
+ end if
+ put "done"
Output:
- var x,y,z,m,n := 1
- case x of
- label 2:
- z :=1
- label 1:
- if m = 5 then
- x := m * n
- elsif m < 7 then
- x := 4
- end if
- put "hi"
- label 4:
- if m = 5 then
- x := m * n
- elsif k = 7 then
- x := 4
- end if
- put x
- label:
- put "that's it"
- end case
- put "done"
+ var x,y,z,m,n := 1
+ case x of
+ label 2:
+ z :=1
+ label 1:
+ if m = 5 then
+ x := m * n
+ elsif m < 7 then
+ x := 4
+ end if
+ put "hi"
+ label 4:
+ if m = 5 then
+ x := m * n
+ elsif k = 7 then
+ x := 4
+ end if
+ put x
+ label:
+ put "that's it"
+ end case
+ put "done"
Notice that the two embedded if statements of this example were NOT
converted - because neither of them corresponds to a case statement.

0 comments on commit 3ba653f

Please sign in to comment.
Something went wrong with that request. Please try again.