I'm just getting into the world of computer science and programming. In preparation for applying to university, I'm reading the New Turing Omnibus -it's on the recommended undergraduate reading list so I thought I'd give it a go. The first chapter is on algorithm's -taking the standard route of comparing a recipe to a program (I say standard because I've seen it in various other tutorials) the chapter then goes on to discuss a simple 'wallpaper' algorithm that essentially makes pretty patterns. It's an exercise designed to demonstrate the power of a simple algorithm.
Anyway out of interest I was trying to replicate this program. In the book it shows the program written in pascal so I downloaded a pascal compiler and tried to compile/run the program. There were various errors and, and I don't know if I was doing the right thing in the first place. So here I am!
Here's the basic program:
1. input corna, cornb
2. input side
3. for i <-- 1 to 100
1. for j <-- 10 to 100
x <-- corna + i * side/100
y <-- cornb + j * side/100
c <-- int (x^2 + y^2)
if c even
then plot (i, j)
And here's the program in pascal:
program WALLPAPER (input, output) ;
var corna, cornb, side, x, y, c: real;
var i, j: integer;
read (corna, cornb);
for i: = 1 to 100 do
for j:= 1 to 100 do
x: = corna + i*side/100;
y: = conb + j*side/100;
c: = trunc(x*x + y*y);
if cmod2 = 0 then graph.putpixel (i, j, 1);
I hope that comes out ok - my html is awful...
I did understand the chapter, and I've done a small amount of python programming in the past. Basically my query is how can I implement this program? Is it simply a case of writing it up into the compiler or does more need to be done. The limit of my python programming was a program that wrote out all the times tables, which was just a case of hitting enter to run it. Since this is graphical maybe more needs to be done?
I don't think this is the kind of question you regularly get here, hopefully you won't mind helping me out!
Thanks in advance