views:

169

answers:

2

i have been asked to make a simple sort aglorithm to sort a random series of 6 numbers into numerical order. However i have been asked to do this using "Barebones" a theoretical language put forward in the Book Computer Science an overview.

Some information on the language can be found here http://www.brouhaha.com/~eric/software/barebones/

Just to clarify i am a student teacher and have been doing anaysis on "mini-programing languages" and their uses in a teaching environment, i suggested to my tutor that i look at barebones and asked what sort of exmaple program i should write . He suggested a simple sort algorithm. Now since looking at the language i cant understand how i can do this without using arrays and if statements.

The code to swap the value of variables would be

while a not 0 do;
    incr Aux1;
    decr a;
end;
while b not 0 do;
    incr Aux2
    decr b
end;
while Aux1 not 0 do;
    incr a;
    decr Aux1;
end;
while Aux2 not 0 do;
    incr b;
    decr Aux2;
end;

however the language does not provide < or > operators

+2  A: 

Oh, come on, start thinking about the problem!

What's an array? A list of variables.

So Barebones doesn't have an if statement? It's got while loops.

Get on with your homework.

High Performance Mark
+2  A: 

Interesting exercise.

I would suggest you try to first implement the following:

  • Swap values of two variables
  • Set a variable (say z) to zero if value of variable x >= value of variable y.

Since the program is supposed to sort exactly 6 integers, I suppose you can assume they are in the variables x1, x2, .., x6.

In the end we need: x1 <= x2 <= ... <= x6.

Moron
to swap the values of 2 variables the code would be along the lines ofwhile a not 0 do; incr Aux1; decr a;end;while b not 0 do; incr Aux2 decr bend;while Aux1 not 0 do; incr a; decr Aux1;end;while Aux2 not 0 do; incr b; decr Aux2;end;however the language provides no implementation of > or < operators and therefore am stuggling to work out how to solve this problem(unless i am missing something stupid)
sorry should'nt have put that above