# Psuedo code - completely mythed!!

Discussion in 'Scotland - curriculum' started by Henjo, Jul 16, 2014.

1. ### Henjo

Hi,

I wonder if any of you could help me interpret the code below. I'm no stranger to basic programming, but I fail to see how this piece of pseudo code does what it purports to - which is to discover square numbers (because they have an odd number of improper factors)

Any help greatly appreciated

Hi,

Apparently the code below discovers square numbers by virtue of always having an odd number of improper factors (a mathematical fact with which I'm fully on board).

Please, please please could someone explain what is happening with it!! I'm no stranger to computer code but this is just not making sense to me!

INPUT n

LET J=1

REPEAT

LET X(J) = 0

LET J = J+1

UNTIL J=n+1

REPEAT

LET K=J

REPEAT

LET X(K)=1-X(K)

LET K=K+J

UNTIL K>n

LET J =J+1

UNTIL J =n+1

2. ### gnulinuxOccasional commenter

First, this is not pseudo-code but BASIC (program code). Next it is rubbish. What is an improper factor??? A square number is the product of 2 factors which are equal. That's it.

Somebody is pulling your chain - duh!!!

3. ### BensusanNew commenter

Whilst this code does look to be rubbish (K is always bigger than n, so will stop at the statement UnTIL K>n) the criteria for determining a square number is correct.

1. For every factor a number has, there is another factor which pairs with it - the one which completes the number. e.g. 2 is a factor of 24 and it pairs with 12 since 2x12=24. So all numbers should have an even number of factors. Except.....

2. Square numbers, because they have a factor which pairs with itself. Which means they have an odd number of factors. e.g. factors of 16 are ..... 1, 2, 4, 8, 16. 1 pairs with 16, 2 pairs with 8, but 4 "pairs" with itself.