 ## – Code Chef Problem RRCode –

procedure RRCODE is
type Data is mod 10**9 + 1;
subtype Index is Positive range 1…1000;
subtype T is Positive range 1…100;
type Data_Array is array(Index range <>) of Data;
type operations is (a, o, x);
use Data_IO;
function F (N : in Index;
K : in Data;
Operator : in Operations;
The_Data : in Data_Array) return Data is
begin
for I in 1…K loop
for J in The_Data’Range loop
case Operator is
when a =>
Temp := Temp and The_Data(J);
when o =>
Temp := Temp or The_Data(J);
when x =>
Temp := Temp xor The_Data(j);
end case;
end loop;
end loop;
return Temp;
end F;
Tries : T;
N : Index;
K : Data;
Operator_String : String(1…10);
Operator_Length : Natural;
Opcode : Operations;
begin
Get(Item => Tries);
for Try in 1…Tries loop
Get(Item => N);
Get(Item => K);
declare
The_Data : Data_Array(1…N);
begin
for I in The_Data’Range loop
Get(Item => The_Data(I));
end loop;
Skip_Line;
Get_Line(Item => Operator_String, Last => Operator_Length);
if Operator_String(1) = ‘A’ then
Opcode := a;
elsif Operator_String(1) = ‘O’ then
Opcode := o;
else
Opcode := x;
end if;
end;
end loop;
Set_Exit_Status(Code => Success);
end RRCODE;

``````-- Code Chef Problem RRCode --
------------------------------------------------------------------

procedure RRCODE is
type Data is mod 10**9 + 1;
subtype Index is Positive range 1..1000;
subtype T is Positive range 1..100;
type Data_Array is array(Index range <>) of Data;
type operations is (a, o, x);
use Data_IO;
function F (N : in Index;
K : in Data;
Operator : in Operations;
The_Data : in Data_Array) return Data is
begin
for I in 1..K loop
for J in The_Data'Range loop
case Operator is
when a =>
Temp := Temp and The_Data(J);
when o =>
Temp := Temp or The_Data(J);
when x =>
Temp := Temp xor The_Data(j);
end case;
end loop;
end loop;
return Temp;
end F;
Tries : T;
N : Index;
K : Data;
Operator_String : String(1..10);
Operator_Length : Natural;
Opcode : Operations;
begin
Get(Item => Tries);
for Try in 1..Tries loop
Get(Item => N);
Get(Item => K);
declare
The_Data : Data_Array(1..N);
begin
for I in The_Data'Range loop
Get(Item => The_Data(I));
end loop;
Skip_Line;
Get_Line(Item => Operator_String, Last => Operator_Length);
if Operator_String(1) = 'A' then
Opcode := a;
elsif Operator_String(1) = 'O' then
Opcode := o;
else
Opcode := x;
end if;