# Question 22 (e) Was Faulty (1 Viewer)

##### New Member
Did anyone else notice this? The algorithm was faulty. Once you enter the first while loop it was impossible to escape. I'll try and reconstruct the algorithm from memory to show you.

Code:
``````FOR Runner = 1 TO 8
RandomLane = random number from 1 to 8 inclusive
WHILE RunnerName(RandomLane) IS NOT NULL
RandomLane = random number from 1 to 8 inclusive
ENDWHILE
INPUT name
RunnerName(RandomLane) = name
NEXT``````

Last edited:

#### dezistheshit

##### New Member
bahhhh

i finished before 4

what you all think of the test

DEF FAIL!

but easier then previous years

i found that binary multiplication hard

prolly wouldve help if i didnt go drifting b4 the exam

not as hard as engineering though

#### Binaries

##### New Member
Easy, i totally enilated it multiple times except for about 3-4 questions which stumped me. How about 23 i cant remember which part it was but you had to code a sub program for the output of odd numbers and what not.

I got something like this but it isn't fully correct im sure of that

Code:
``Print "1", (n/2), n``

#### Tomotron

##### New Member
this is the exam which wont be included in my UAI thats for sure LOL

our software class did almost no work all year and this is pretty much how it was going to end...left after 1.5 hours and most of my answers were stupid.

#### zcb666

##### Member
I thought it was really easy. Theres only 1, maybe 2 questions i didn't understand. And no, i didn't notice anything was up with that algorithm :/

#### ajdlinux

##### Mod: ANU, ATAR/HSC Marks
I didn't notice the error, but now that you point it out it's obvious.

Still, it's only a minor thing and I don't think markers will penalise you for not noticing.

#### OneShotWill

##### New Member
uHH NO it wasnt fualty.. . it says.. while that lane has a runner in it.. get a new lane number.. it ensures that every1 gets a seperate lane.. DUH

#### Martyno1

##### oh hi
I can't see any faults with that algorithm?

#### ajdlinux

##### Mod: ANU, ATAR/HSC Marks
Actually, turns out it wasn't faulty having read last two posts and thought about it for another minute... yes, it's to ensure the lane is not in use.

#### nubix

##### Member
There's nothing wrong with it, it doesn't initialise for the first loop thingo(lost the word :=(). Then for the other ones, checks whether a lane has already been assigned. It prevents lanes from getting more than 1 person.

#### Starcraftmazter

##### Member
The algorithm is not faulty

There is only one while loop. For loops cannot be infinite because they are counted.

The while loop is a safeguard to ensure that if an index of the array already has a runner, he will not get overriden, and a new index is generated, until one is not used up, and hence that will be used.

The algorithm is as follows:

Code:
``````BEGIN
FOR Runner = 1 to 8
RandomLane = random Integer between 1 and 8 inclusive
WHILE RunnerName (RandomLane) is not null
RandomLane = random Integer between 1 and 8 inclusive
ENDWHILE
Input Name
RunnerName (RandomLane) = Name
NEXT
FOR Runner = 1 to 8
LaneNo = Runner
Output RunnerName (Runner), "is in Lane", LaneNo
NEXT
END``````

##### New Member
Edit: Actually, I see what the problem is ... for some reason I read it as "IS NULL" even though I wrote it as "IS NOT NULL" ... good thing I fudged the answer on the exam and gave them what they wanted to hear.

Last edited:

#### Starcraftmazter

##### Member
The code inside the while loop generates a different RandomLine integer, which is the condition for the loop - RunnerName (RandomLane) not being null.

By default all indexes of the array are null, so the code inside the while loop won't even execute.

If it happens to generate an index which is already used, it will not be null, and so the code inside the while loop will repeat until it generates an index which is null (ie. not used up). The code inside the while loop does this - generate a new index.

WHILE RunnerName (RandomLane) is not null
RandomLane = random Integer between 1 and 8 inclusive
ENDWHILE

#### Plunkdogg

##### New Member
yay for people who didnt get that question done
yay me

#### NovaAesa

##### Member
Starcraftmazter said:
The code inside the while loop generates a different RandomLine integer, which is the condition for the loop - RunnerName (RandomLane) not being null.

By default all indexes of the array are null, so the code inside the while loop won't even execute.

If it happens to generate an index which is already used, it will not be null, and so the code inside the while loop will repeat until it generates an index which is null (ie. not used up). The code inside the while loop does this - generate a new index.
That sums up my thoughts precisely. No problem with the algorithm at all.

##### New Member
Starcraftmazter said:
The code inside the while loop generates a different RandomLine integer, which is the condition for the loop - RunnerName (RandomLane) not being null.

By default all indexes of the array are null, so the code inside the while loop won't even execute.

If it happens to generate an index which is already used, it will not be null, and so the code inside the while loop will repeat until it generates an index which is null (ie. not used up). The code inside the while loop does this - generate a new index.
Yea I got it now. I wasn't acknowledging the NOT in front of the null, despite the fact that I actually wrote it multiple times.

#### Starcraftmazter

##### Member
That's okey, the exact thing happened to me on one of the multiple choice questions

#### FromDeeEast

##### Member
NovaAesa said:
That sums up my thoughts precisely. No problem with the algorithm at all.
LOL ur such a random suckup

#### Tsuska

##### New Member
Tomotron said:
this is the exam which wont be included in my UAI thats for sure LOL

our software class did almost no work all year and this is pretty much how it was going to end...left after 1.5 hours and most of my answers were stupid.
Haha sounds like us! We lost our good old teacher (he left the school to become head teacher at another school with higher pay) and got a new one who last yr also took our class as a student teacher. They're both D&T teachers...and software is definately not prime. Hmm...i get about 0% of the text book. Which is pretty much the same with all of us... Umm, and since the classes were all b4 school started, some people didn't bothere to show up. The ones that did realised that all the teacher did was look at his shares (on the stock market) and go on MSN news looking at sports etc.

Did he teach us anything? no....

And when he decides to give us his first set of notes...he spotted one of my friends on bored of studies looking at one of the HSC course summaries. Printed everyone a copy and said...study this =P...

So we all went on our computers and continued doing whatever we wanted... +P

Owell...EPIC FAIL!!!

#### NovaAesa

##### Member
Whatever, I just realised he had posed what I was about to post, so I just quoted instead.