deleted

deletedg qg qgq gq gqh qhqgfsadgfasg ag

Comments

  • : For example I got an array, which values are 2 5 3 6 1 4
    : if my array[1] is 2 then it would change 2 first values in array.
    : if my array[1] is 5 then i have to change 5 first values in array
    : (by change i mean: [b]5 2 3 6 1[/b] 4 -> [b]1 6 3 2 5[/b] 4)
    : I have to count, how many times i have to do it before array[1]
    : becomes 1.
    [code][color=Blue]var a:array[1..6] of byte;
    i,t,j:byte;

    procedure swap(var a,b:byte);
    begin if a<>b then begin a:=a xor b;b:=a xor b;a:=a xor b;end;end;

    procedure display;
    var k:byte;begin for k:=1 to 5 do write(a[k],',');writeln(a[6]);end;

    begin
    randomize;
    for i:=1 to 6 do a[i]:=i;
    for i:=1 to 12 do swap(a[random(6)+1],a[random(6)+1]);
    display;
    j:=0;
    while a[1]>1 do begin
    t:=a[1];
    for i:=1 to t shr 1 do swap(a[i],a[t+1-i]);
    display;
    inc(j);
    end;
    writeln(#13#10,j,' swaps made.');
    readln;
    end.[/color][/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion