Jimmy19001

128 Reputation

2 Badges

15 years, 17 days

MaplePrimes Activity


These are questions asked by Jimmy19001

Codewords:=proc(L,x,y,z)
local
List:=[];

if L=S then
if x=1 then

print(`A 1 j k`);
else
print(`A 0 j k`);
fi:


if y=1 then

print(`B i 1 k`);
else

print(`B i 0 k`);
fi:
if z=1 then
print(`C i j 1`);
else

print(`C i j 0`);
fi:
fi:
if L=A then
if x=1 then

print(`S 1 j k`);
else

print(`S 0 j k`);
fi:

if y=1 then

print(`C i 1 k`);
else

print(`C i 0 k`);

a:=%%, %;
 

what does this do?

 

I understand how to use an IF statement, but what does ' if ' mean??

Bogosort

I'm trying to implement bogosort procedure and don't really have any idea where to start from. I know that its a method used by randomly putting a list back in order. Ive programmed bubble and cocktail but dont really understand how i would could a random sort.

Any help would be greatfull!!

 

I have tried to programme a bubble sort procedure below and i'm a bit stuck and not sure where i've gone wrong. Many thanks.

 bubblesort:=proc(C)
local n,o,r,k,i:
n:=rtable_dims(C):
o:=rhs(n):
r:=lhs(n):
for i from r to o - 1 do
if C[i] > C[i+1] then
(C[i], C[i+1] ) := (C[i+1], C[i]);
else
(C[i], C[i+1] ) := (C[i], C[i+1] );
fi:
od:
return(C);
end proc:

 C:=rtable(1..6,random(1..50));
bubblesort(C);

C:=[44 5 38 37 3 15]
[5 38 37 3 15 44]

1 2 Page 1 of 2