Programming Assignment
Programming Assignment
General Instructions: Read the input and output formats very carefully since the evaluation will be
scripted. There will be an evaluation/viva after the submission, and a part of the grade would depend
on it.
Language constraints: The submission must be in Python. You will have to read/write from both a
file and stdout. For any further use of other libraries please refer to one of the TAs for approval. Usage
of any other language will lead to no evaluation.
For each test case, output N space-separated integers where the i-th integer represents the frequency
of the number i output by the PRNG.
1
1.3 Constraints
• 1 ≤ N, M ≤ 105
• 1≤S≤N
• 0 ≤ X ≤ 1012
It is guaranteed that sum of N and M over all test cases does not exceed 105 .
2
3 3 1 5
1 2
2 3
3 1
7 6 4 13
1 5
2 6
4 7
5 2
6 1
7 1
2 2 1
3 3 0 1 3 2 1
1.6 Explanation
• The input itself to the DFA does not matter since they are all the same due the alphabet being a
single letter, only its size which is 5 determines the number of random numbers generated. The
DFA has 3 states, 3 relevant transitions and it starts from state 1.
• The sequence of outputs is 1, 2, 3, 1, 2 and hence the frequencies are 2,2,1 for the numbers 1,2,3
respectively.
2 L-Systems
L-systems, or Lindenmayer systems, are a mathematical formalism introduced by biologist Aristid
Lindenmayer in 1968. They are used to model the growth processes of plants and other organisms. L-
systems consist of an alphabet of symbols, production rules (grammar) that define how these symbols
Page 2
can be replaced or expanded, and an initial state called the axiom. The system iteratively applies the
production rules to generate complex structures, often visualized as fractals or plant-like forms.
Example:
Rule: F → F + F - F - F +F
Iteration 0: F (Axiom)
Iteration 1: F+F-F-F+F
Iteration 2: F+F-F-F+F+F+F-F-F+F-F-F+F+F+F-F-F+F
Symbol Meaning
F Move forward and draw a line
+ Turn right by a specified angle
- Turn left by a specified angle
[ Save the current state (position and direction)
] Restore the saved state (position and direction)
G Move forward without drawing a line (gap)
X, Y Variables used in rules (placeholders)
Look at the links spiecified below and read the documentation for further understanding.
• Javascript
• Haskell
Axiom: G
Angle: 30
Rule 1: G = X − G − X
Rule 2: X = G + Y + G
Rule 3: Y = [+F ]F [−F ]
Axiom: X
Angle: (r mod 30) − 15 + 10 × (−1)15−(r mod 30)
Rule 1: X = F [−X]X[+X][+X]F − [−X] + X[−X]
Rule 2: F = F F
Here, r stands for the last three digits of your roll number. For example, if 2019111234 is your
roll number, for you r = 234.
Page 3
3. “Anything that can happen will happen" (minimum 4 iterations)
Axiom: X
Angle: 12.5
Rule 1: X = F − [[−X] + X] + F [+F X] − X, F + [[+X] − X] − F [−F X] + X[X]
Rule 2: F = F [F ]F, F [+]F, F [F F ]F
Each comma separated rule is equally probable. Provide 5 images displaying different L-system
configurations obtained from this set of axioms and rules.
4. “Content without context is noise" (minimum 9 iterations)
Axiom: F + F
Angle: 90
Rule 1: F = F − F + +F − F
Rule 2: F ⟨F ⟩ − F = F − +F + F
Given the following 2 sets of graphics or final system configurations, come up with the underlying
production rules to model that system. [CO 1, CO 2, CO 3, CO 4]
Page 4
(a) after 4 iterations (b) after 5 iterations
For each of the above sub-parts submit a JSON file in the following format. File name for sub-part i:
‘i.json’:
{
"axiom": · · · ,
"productions": {· · · },
"finals": {· · · }
···
}
Submission details
The submission must be a zip file containing the code and a report explaining the approach for the solutions.
rollnumber_prog1.zip
→ q1
→ ./prng.py
→ q2
→ ./mirrorball.xyz
→ ./tree.xyz
→ ./anything.xyz
→ ./noise.xyz
(use suitable file extensions in place of xyz)
→ q3
→ ./stick_plant.json
→ ./santa.json
→ report.pdf
Page 5