Anda di halaman 1dari 4

CS1010S, Semester II, 2013/2014Mission 2 1

National University of Singapore


School of Computing
CS1010S: Programming Methodology
Semester II, 2013/2014
Mission 2
Rune Paintings
Start date: 30 January 2014
Due: 5 February 2014, 23:59
Background
After passing through the two doors in your previous mission, you arrive in a large
spacious hall with no visible exits except for a large hole in the ceiling from which a
bright light illuminate the entire hall. In one corner, you nd 2 raised terminal with an
interface similar to the empty spaces you found on the doors. You can barely see the
rst letters on their interfaces - R and I.
This mission has two tasks.
Task 1a: Fractal (5 marks)
On the terminals, you see the symbols glow - reminiscent of the previous rooms. Yet
they represented all the complexities that came before them in simple elegant patterns.
It will be well for you to comprehend the similarities and differences.
Write a function fractal that takes as arguments a rune and an integer n > 0. It should
generate the rune below by means of a recursive process with the following command:
show(fractal(make_cross(rcross_bb), 3))
To determine that your function is correct for n > 3, check that the same command with
n = 7 draws:
CS1010S, Semester II, 2013/2014Mission 2 2
You should check that your function will perform correctly for any arbitary number of
draws that is 3 or above.
Task 1b: Fractal - Iteration (5 marks)
Write a function fractal iter that takes in the same arguments as fractal but it will
generate the output in an iterative way this time.
The function should generate the same rune as the recursive one by replacing fractal
with fractal iter in your test functions.
CS1010S, Semester II, 2013/2014Mission 2 3
Figure 1: (Left) dual fractal with 3 layers (Right) dual fractal with 7 layers
Task 1c: Dual Fractals (5 marks)
Write a function dual fractal that takes as arguments 2 runes and an integer n > 0.
It should generate the rune below by means of a recursive process with the following
command:
show(dual_fractal(make_cross(rcross_bb), make_cross(nova_bb), 3))
The rst rune is used for every odd layers in the fractal starting from the largest rune,
whereas the second rune is used for every even layers in the fractal.
You should check that your function will perform correctly for any arbitary number of
draws that is 3 or above.
Task 1d: Dual Fractals - Iteration (5 marks)
Write a function dual fractal iter that takes in the same arguments as dual fractal
but it will generate the output in an iterative way.
The function should generate the same rune as the recursive one by replacing dual fractal
with dual fractal iter in your test functions.
Note: In the template le all functions are dened as some function(params). It
doesnt mean that all functions take in only one parameter. Its your job to gure out
what parameters should each function take and replace params accordingly.
CS1010S, Semester II, 2013/2014Mission 2 4
Task 2: Egyptian (10 marks)
As your eyes slowly adjusted to the room, several paintings that were hidden by the
darkness reveal themselves. They exuded the same runes in the terminal but with an
intricate repeating pattern. Almost like the Egyptian paintings you read in a book before.
Perhaps this is where they make them.
Observing a nearest painting, you notice that it exhibits 5 repeating patterns on every
edge with the centre hollow lled with the same pattern:
However, there are other paintings that sports different numbers of repeating patterns.
Write a function egyptian that takes n as an argument and creates runic patterns
shown on these Egyptian paintings with different numbers of repetitions at the edges,
where n 3.
In particular, the above picture can be created with:
show(egyptian(make_cross(rcross_bb), 5))
Furthermore, note that the orientation of all images should remain the same as the
original. See Figure 2 for more examples.
(a) show(egyptian(make cross(rcross bb),9)) (b) show(egyptian(nova bb, 9))
Figure 2: More examples. (a) is the same as previous example but with n = 9, (b) demonstrates
that the original pattern (e.g. nova bb) should not be rotated.

Anda mungkin juga menyukai