WeixiangYan/CodeTransOcean huggingface dataset:
Task: Solve the no connection puzzle

C: #include <stdbool.h>
#include <stdio.h>
#include <math.h>

int connections[15][2] = {
    {0, 2}, {0, 3}, {0, 4}, 
    {1, 3}, {1, 4}, {1, 5}, 
    {6, 2}, {6, 3}, {6, 4}, 
    {7, 3}, {7, 4}, {7, 5}, 
    {2, 3}, {3, 4}, {4, 5}, 
};

int pegs[8];
int num = 0;

bool valid() {
    int i;
    for (i = 0; i < 15; i++) {
        if (abs(pegs[connections[i][0]] - pegs[connections[i][1]]) == 1) {
            return false;
        }
    }
    return true;
}

void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}

void printSolution() {
    printf("----- %d -----\n", num++);
    printf("  %d %d\n",  pegs[0], pegs[1]);
    printf("%d %d %d %d\n", pegs[2], pegs[3], pegs[4], pegs[5]);
    printf("  %d %d\n",  pegs[6], pegs[7]);
    printf("\n");
}

void solution(int le, int ri) {
    if (le == ri) {
        if (valid()) {
            printSolution();
        }
    } else {
        int i;
        for (i = le; i <= ri; i++) {
            swap(pegs + le, pegs + i);
            solution(le + 1, ri);
            swap(pegs + le, pegs + i);
        }
    }
}

int main() {
    int i;
    for (i = 0; i < 8; i++) {
        pegs[i] = i + 1;
    }

    solution(0, 8 - 1);
    return 0;
}











Ada: With
Ada.Text_IO,
Connection_Types,
Connection_Combinations;

procedure main is
   Result : Connection_Types.Partial_Board renames Connection_Combinations;
begin
   Ada.Text_IO.Put_Line( Connection_Types.Image(Result) );
end;
Task: Permutation test

C: #include <stdio.h>

int data[] = {  85, 88, 75, 66, 25, 29, 83, 39, 97,
                68, 41, 10, 49, 16, 65, 32, 92, 28, 98 };

int pick(int at, int remain, int accu, int treat)
{
        if (!remain) return (accu > treat) ? 1 : 0;

        return  pick(at - 1, remain - 1, accu + data[at - 1], treat) +
                ( at > remain ? pick(at - 1, remain, accu, treat) : 0 );
}

int main()
{
        int treat = 0, i;
        int le, gt;
        double total = 1;
        for (i = 0; i < 9; i++) treat += data[i];
        for (i = 19; i > 10; i--) total *= i;
        for (i = 9; i > 0; i--) total /= i;

        gt = pick(19, 9, 0, treat);
        le = total - gt;

        printf("<= : %f%%  %d\n > : %f%%  %d\n",
               100 * le / total, le, 100 * gt / total, gt);
        return 0;
}











Ada: with Ada.Text_IO; with Iterate_Subsets;

procedure Permutation_Test is

   type Group_Type is array(Positive range <>) of Positive;

   Treat_Group: constant Group_Type := (85, 88, 75, 66, 25, 29, 83, 39, 97);
   Ctrl_Group:  constant Group_Type := (68, 41, 10, 49, 16, 65, 32, 92, 28, 98);

   package Iter is new Iterate_Subsets(Treat_Group'Length, Ctrl_Group'Length);

   Full_Group: constant Group_Type(1 .. Iter.All_Elements)
     := Treat_Group & Ctrl_Group;

   function Mean(S: Iter.Subset) return Float is
      Sum: Natural := 0;
   begin
      for I in S'Range loop
         Sum := Sum + Full_Group(S(I));
      end loop;
      return Float(Sum)/Float(S'Length);
   end Mean;

   package FIO is new Ada.Text_IO.Float_IO(Float);

   T_Avg: Float := Mean(Iter.First);
   S_Avg: Float;
   S:     Iter.Subset := Iter.First;
   Equal:  Positive := 1; 
   Higher: Natural  := 0;
   Lower:  Natural  := 0;

begin 
   
   loop
      Iter.Next(S);
      S_Avg := Mean(S);
      if S_Avg = T_Avg then
         Equal := Equal + 1;
      elsif S_Avg >= T_Avg then
         Higher := Higher + 1;
      else
         Lower := Lower + 1;
      end if;
      exit when Iter.Last(S);
   end loop;

   
   declare
      use Ada.Text_IO;
      Sum: Float := Float(Higher + Equal + Lower);
   begin
      Put("Less or Equal: ");
      FIO.Put(100.0*Float(Lower+Equal) / Sum, Fore=>3, Aft=>1, Exp=>0);
      Put(Integer'Image(Lower+Equal));
      New_Line;
      Put("More:          ");
      FIO.Put(100.0*Float(Higher) / Sum,      Fore=>3, Aft=>1, Exp=>0);
      Put(Integer'Image(Higher));
      New_Line;
   end;
end Permutation_Test;
Task: Image convolution

C: image filter(image img, double *K, int Ks, double, double);











Ada: type Float_Luminance is new Float;

type Float_Pixel is record
   R, G, B : Float_Luminance := 0.0;
end record;

function "*" (Left : Float_Pixel; Right : Float_Luminance) return Float_Pixel is
   pragma Inline ("*");
begin
   return (Left.R * Right, Left.G * Right, Left.B * Right);
end "*";

function "+" (Left, Right : Float_Pixel) return Float_Pixel is
   pragma Inline ("+");
begin
   return (Left.R + Right.R, Left.G + Right.G, Left.B + Right.B);
end "+";

function To_Luminance (X : Float_Luminance) return Luminance is
   pragma Inline (To_Luminance);
begin
   if X <= 0.0 then
      return 0;
   elsif X >= 255.0 then
      return 255;
   else
      return Luminance (X);
   end if;
end To_Luminance;

function To_Pixel (X : Float_Pixel) return Pixel is
   pragma Inline (To_Pixel);
begin
   return (To_Luminance (X.R), To_Luminance (X.G), To_Luminance (X.B));
end To_Pixel;
Task: Copy a string

C: #include <stdlib.h>	
#include <stdio.h>	
#include <string.h>

int
main()
{
	size_t len;
	char src[] = "Hello";
	char dst1[80], dst2[80];
	char *dst3, *ref;

	
	strcpy(dst1, src);

	
	len = strlen(src);
	if (len >= sizeof dst2) {
		fputs("The buffer is too small!\n", stderr);
		exit(1);
	}
	memcpy(dst2, src, len + 1);

	
	dst3 = strdup(src);
	if (dst3 == NULL) {
		
		perror("strdup");
		exit(1);
	}

	
	ref = src;

	
	memset(src, '-', 5);

	printf(" src: %s\n", src);   
	printf("dst1: %s\n", dst1);  
	printf("dst2: %s\n", dst2);  
	printf("dst3: %s\n", dst3);  
	printf(" ref: %s\n", ref);   

	
	free(dst3);

	return 0;
}











Ada: Src : String := "Hello";
Dest : String := Src;
Task: Keyboard input_Obtain a Y or N response

C: #include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
 
void set_mode(int want_key)
{
	static struct termios old, new;
	if (!want_key) {
		tcsetattr(STDIN_FILENO, TCSANOW, &old);
		return;
	}
 
	tcgetattr(STDIN_FILENO, &old);
	new = old;
	new.c_lflag &= ~(ICANON);
	tcsetattr(STDIN_FILENO, TCSANOW, &new);
}
 
int get_key(int no_timeout)
{
	int c = 0;
	struct timeval tv;
	fd_set fs;
	tv.tv_usec = tv.tv_sec = 0;
 
	FD_ZERO(&fs);
	FD_SET(STDIN_FILENO, &fs);

	select(STDIN_FILENO + 1, &fs, 0, 0, no_timeout ? 0 : &tv);
	if (FD_ISSET(STDIN_FILENO, &fs)) {
		c = getchar();
		set_mode(0);
	}
	return c;
}
 
int main()
{
	int c;
	while(1) {
		set_mode(1);
		while (get_key(0)); 
		printf("Prompt again [Y/N]? ");
		fflush(stdout);

		c = get_key(1);
		if (c == 'Y' || c == 'y') {
			printf("\n");
			continue;
		}

		if (c == 'N' || c == 'n') {
			printf("\nDone\n");
			break;
		}

		printf("\nYes or no?\n");
	}

	return 0;
}











Ada:    function Yes_Or_No (Prompt : String := "Your answer (Y/N): ") return Boolean is
      Answer : Character;
   begin
      Ada.Text_IO.Put (Prompt);
      loop
         Ada.Text_IO.Get_Immediate (Answer);
         case Answer is
            when 'Y'|'y' => return True;
            when 'N'|'n' => return False;
            when others  => null;
         end case;
      end loop;
   end Yes_Or_No;
Task: Include a file

C: 
#include <stdlib.h>


#include "myutil.h"











Ada: with Ada.Text_IO, Another_Package; use Ada.Text_IO;
Task: String comparison

C: 
if (strcmp(a,b)) action_on_equality();











Ada: with Ada.Text_IO, Ada.Strings.Equal_Case_Insensitive;

procedure String_Compare is

   procedure Print_Comparison (A, B : String) is
   begin
      Ada.Text_IO.Put_Line
         ("""" & A & """ and """ & B & """: " &
          (if A = B then
              "equal, "
           elsif Ada.Strings.Equal_Case_Insensitive (A, B) then
              "case-insensitive-equal, "
           else "not equal at all, ")                   &
          (if A /= B then "/=, "     else "")           &
          (if A <  B then "before, " else "")           &
          (if A >  B then "after, "  else "")           &
          (if A <= B then "<=, "     else "(not <=), ") &
          (if A >= B then ">=. "     else "(not >=)."));
   end Print_Comparison;
begin
   Print_Comparison ("this", "that");
   Print_Comparison ("that", "this");
   Print_Comparison ("THAT", "That");
   Print_Comparison ("this", "This");
   Print_Comparison ("this", "this");
   Print_Comparison ("the", "there");
   Print_Comparison ("there", "the");
end String_Compare;
Task: Find prime numbers of the form n_n_n+2

C: #include <stdio.h>
#include <stdbool.h>
#include <locale.h>

bool isPrime(int n) {
    int d;
    if (n < 2)  return false;
    if (!(n%2)) return n == 2;
    if (!(n%3)) return n == 3;
    d = 5;
    while (d*d <= n) {
        if (!(n%d)) return false;
        d += 2;
        if (!(n%d)) return false;
        d += 4;
    }
    return true;
}

int main() {
    int n, p;
    const int limit = 200;
    setlocale(LC_ALL, "");
    for (n = 1; n < limit; ++n) {
        p = n*n*n + 2;
        if (isPrime(p)) {
            printf("n = %3d => n³ + 2 = %'9d\n", n, p);
        }
    }
    return 0;
}











Ada: with Ada.Text_Io;

procedure Find_Primes is

   type Number is new Long_Integer range 0 .. Long_Integer'Last;
   package Number_Io is new Ada.Text_Io.Integer_Io (Number);

   function Is_Prime (A : Number) return Boolean is
      D : Number;
   begin
      if A < 2       then return False; end if;
      if A in 2 .. 3 then return True;  end if;
      if A mod 2 = 0 then return False; end if;
      if A mod 3 = 0 then return False; end if;
      D := 5;
      while D * D <= A loop
         if A mod D = 0 then
            return False;
         end if;
         D := D + 2;
         if A mod D = 0 then
            return False;
         end if;
         D := D + 4;
      end loop;
      return True;
   end Is_Prime;

   P : Number;
begin
   Ada.Text_Io.Put_Line ("  N   N**3+2");
   Ada.Text_Io.Put_Line ("
   for N in Number range 1 .. 199 loop
      P := N**3 + 2;
      if Is_Prime (P) then
         Number_Io.Put (N, Width => 3); Ada.Text_Io.Put ("  ");
         Number_Io.Put (P, Width => 7);
         Ada.Text_Io.New_Line;
      end if;
   end loop;
end Find_Primes;
Task: Pseudo-random numbers_Middle-square method

C: #include<stdio.h>
long long seed;
long long random(){
        seed = seed * seed / 1000 % 1000000;
        return seed;
}
int main(){
        seed = 675248;
        for(int i=1;i<=5;i++)
                printf("%lld\n",random());
        return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
   type long is range 0 .. 2**64;
   Seed : long := 675_248;
   function random return long is
   begin
      Seed := Seed * Seed / 1_000 rem 1_000_000;
      return Seed;
   end random;
begin
   for I in 1 .. 5 loop
      Put (long'Image (random));
   end loop;
   New_Line;
end Main;
Task: Executable library

C: #ifndef HAILSTONE
#define HAILSTONE       
                                
long hailstone(long, long**);   
void free_sequence(long *);

#endif











Ada: package Parameter is
   X: Natural := 0;
   Y: Natural;
end Parameter;
Task: Entropy_Narcissist

C: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>

#define MAXLEN 961 

int makehist(char *S,int *hist,int len){
	int wherechar[256];
	int i,histlen;
	histlen=0;
	for(i=0;i<256;i++)wherechar[i]=-1;
	for(i=0;i<len;i++){
		if(wherechar[(int)S[i]]==-1){
			wherechar[(int)S[i]]=histlen;
			histlen++;
		}
		hist[wherechar[(int)S[i]]]++;
	}
	return histlen;
}

double entropy(int *hist,int histlen,int len){
	int i;
	double H;
	H=0;
	for(i=0;i<histlen;i++){
		H-=(double)hist[i]/len*log2((double)hist[i]/len);
	}
	return H;
}

int main(void){
	char S[MAXLEN];
	int len,*hist,histlen;
	double H;
	FILE *f;
	f=fopen("entropy.c","r");
	for(len=0;!feof(f);len++)S[len]=fgetc(f);
	S[--len]='\0';
	hist=(int*)calloc(len,sizeof(int));
	histlen=makehist(S,hist,len);
	
	H=entropy(hist,histlen,len);
	printf("%lf\n",H);
	return 0;
}











Ada: with Ada.Text_Io;
with Ada.Command_Line;
with Ada.Numerics.Elementary_Functions;

procedure Entropy is
   use Ada.Text_Io;

   type Hist_Type is array (Character) of Natural;

   function Log_2 (V : Float) return Float is
      use Ada.Numerics.Elementary_Functions;
   begin
      return Log (V) / Log (2.0);
   end Log_2;

   procedure Read_File (Name : String; Hist : out Hist_Type) is
      File : File_Type;
      Char : Character;
   begin
      Hist := (others => 0);
      Open (File, In_File, Name);
      while not End_Of_File (File) loop
         Get (File, Char);
         Hist (Char) := Hist (Char) + 1;
      end loop;
      Close (File);
   end Read_File;

   function Length_Of (Hist : Hist_Type) return Natural is
      Sum : Natural := 0;
   begin
      for V of Hist loop
         Sum := Sum + V;
      end loop;
      return Sum;
   end Length_Of;

   function Entropy_Of (Hist : Hist_Type) return Float is
      Length : constant Float := Float (Length_Of (Hist));
      Sum    : Float := 0.0;
   begin
      for V of Hist loop
         if V > 0 then
            Sum := Sum + Float (V) / Length * Log_2 (Float (V) / Length);
         end if;
      end loop;
      return -Sum;
   end Entropy_Of;

   package Float_Io is new Ada.Text_Io.Float_Io (Float);
   Name : constant String := Ada.Command_Line.Argument (1);
   Hist : Hist_Type;
   Entr : Float;
begin
   Float_Io.Default_Exp := 0;
   Float_Io.Default_Aft := 6;

   Read_File (Name, Hist);
   Entr := Entropy_Of (Hist);

   Put ("Entropy of '");
   Put (Name);
   Put ("' is ");
   Float_Io.Put (Entr);
   New_Line;
end Entropy;
Task: Draw a pixel

C: #include<graphics.h>

int main()
{
	initwindow(320,240,"Red Pixel");
	
	putpixel(100,100,RED);
	
	getch();
	
	return 0;
}











Ada: with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;

procedure Draw_A_Pixel is

   Width   : constant := 320;
   Height  : constant := 200;

   Window   : SDL.Video.Windows.Window;
   Renderer : SDL.Video.Renderers.Renderer;

   procedure Wait is
      use type SDL.Events.Event_Types;
      Event : SDL.Events.Events.Events;
   begin
      loop
         while SDL.Events.Events.Poll (Event) loop
            if Event.Common.Event_Type = SDL.Events.Quit then
               return;
            end if;
         end loop;
         delay 0.100;
      end loop;
   end Wait;

begin
   if not SDL.Initialise (Flags => SDL.Enable_Screen) then
      return;
   end if;

   SDL.Video.Windows.Makers.Create (Win      => Window,
                                    Title    => "Draw a pixel",
                                    Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
                                    Size     => SDL.Positive_Sizes'(Width, Height),
                                    Flags    => 0);
   SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
   Renderer.Set_Draw_Colour ((0, 0, 0, 255));
   Renderer.Fill (Rectangle => (0, 0, Width, Height));
   Renderer.Set_Draw_Colour ((255, 0, 0, 255));
   Renderer.Draw (Point => (100, 100));
   Window.Update_Surface;

   Wait;
   Window.Finalize;
   SDL.Finalise;
end Draw_A_Pixel;
Task: Verify distribution uniformity_Naive

C: #include <stdlib.h>
#include <stdio.h>
#include <math.h>

inline int rand5()
{
	int r, rand_max = RAND_MAX - (RAND_MAX % 5);
	while ((r = rand()) >= rand_max);
	return r / (rand_max / 5) + 1;
}

inline int rand5_7()
{
	int r;
	while ((r = rand5() * 5 + rand5()) >= 27);
	return r / 3 - 1;
}


int check(int (*gen)(), int n, int cnt, double delta) 
{
	int i = cnt, *bins = calloc(sizeof(int), n);
	double ratio;
	while (i--) bins[gen() - 1]++;
	for (i = 0; i < n; i++) {
		ratio = bins[i] * n / (double)cnt - 1;
		if (ratio > -delta && ratio < delta) continue;

		printf("bin %d out of range: %d (%g%% vs %g%%), ",
			i + 1, bins[i], ratio * 100, delta * 100);
		break;
	}
	free(bins);
	return i == n;
}

int main()
{
	int cnt = 1;
	while ((cnt *= 10) <= 1000000) {
		printf("Count = %d: ", cnt);
		printf(check(rand5_7, 7, cnt, 0.03) ? "flat\n" : "NOT flat\n");
	}

	return 0;
}











Ada: with Ada.Numerics.Discrete_Random, Ada.Text_IO;

procedure Naive_Random is

   type M_1000 is mod 1000;
   package Rand is new Ada.Numerics.Discrete_Random(M_1000);
   Gen: Rand.Generator;

   procedure Perform(Modulus: Positive; Expected, Margin: Natural;
                    Passed: out boolean) is
      Low:  Natural  := (100-Margin) * Expected/100;
      High: Natural  := (100+Margin) * Expected/100;
      Buckets: array(0 .. Modulus-1) of Natural := (others => 0);
      Index: Natural;
   begin
      for I in 1 .. Expected * Modulus loop
         Index := Integer(Rand.Random(Gen)) mod Modulus;
         Buckets(Index) := Buckets(Index) + 1;
      end loop;
      Passed := True;
      for I in Buckets'Range loop
         Ada.Text_IO.Put("Bucket" & Integer'Image(I+1) & ":" &
                           Integer'Image(Buckets(I)));
         if Buckets(I) < Low or else Buckets(I) > High then
            Ada.Text_IO.Put_Line(" (failed)");
            Passed := False;
         else
            Ada.Text_IO.Put_Line(" (passed)");
         end if;
      end loop;
      Ada.Text_IO.New_Line;
   end Perform;

   Number_Of_Buckets: Positive := Natural'Value(Ada.Text_IO.Get_Line);
   Expected_Per_Bucket: Natural := Natural'Value(Ada.Text_IO.Get_Line);
   Margin_In_Percent: Natural := Natural'Value(Ada.Text_IO.Get_Line);
   OK: Boolean;

begin
   Ada.Text_IO.Put_Line(  "Buckets:"    & Integer'Image(Number_Of_Buckets) &
                          ", Expected:" & Integer'Image(Expected_Per_Bucket) &
                          ", Margin:"   & Integer'Image(Margin_In_Percent));
   Rand.Reset(Gen);

   Perform(Modulus  => Number_Of_Buckets,
           Expected => Expected_Per_Bucket,
           Margin   => Margin_In_Percent,
           Passed   => OK);

   Ada.Text_IO.Put_Line("Test Passed? (" & Boolean'Image(OK) & ")");
end Naive_Random;
Task: Use another language to call a function

C: #include <stdio.h>

extern int Query (char * Data, size_t * Length);

int main (int argc, char * argv [])
{
   char     Buffer [1024];
   size_t   Size = sizeof (Buffer);
   
   if (0 == Query (Buffer, &Size))
   {
      printf ("failed to call Query\n");
   }
   else
   {
      char * Ptr = Buffer;
      while (Size-- > 0) putchar (*Ptr++);
      putchar ('\n');
   }
}











Ada: with Interfaces.C;          use Interfaces.C;
with Interfaces.C.Strings;  use Interfaces.C.Strings;

package Exported is
   function Query (Data : chars_ptr; Size : access size_t)
      return int;
   pragma Export (C, Query, "Query");
end Exported;
Task: Find first and last set bit of a long integer

C: #include <stdio.h>
#include <stdint.h>

uint32_t msb32(uint32_t n)
{
	uint32_t b = 1;
	if (!n) return 0;

#define step(x) if (n >= ((uint32_t)1) << x) b <<= x, n >>= x
	step(16); step(8); step(4); step(2); step(1);
#undef step
	return b;
}

int msb32_idx(uint32_t n)
{
	int b = 0;
	if (!n) return -1;

#define step(x) if (n >= ((uint32_t)1) << x) b += x, n >>= x
	step(16); step(8); step(4); step(2); step(1);
#undef step
	return b;
}

#define lsb32(n) ( (uint32_t)(n) & -(int32_t)(n) )


inline int lsb32_idx(uint32_t n) { return msb32_idx(lsb32(n)); }

int main()
{
	int32_t n;
	int i;

	for (i = 0, n = 1; ; i++, n *= 42) {
		printf("42**%d = %10d(x%08x): M x%08x(%2d) L x%03x(%2d)\n",
			i, n, n,
			msb32(n), msb32_idx(n),
			lsb32(n), lsb32_idx(n));

		if (n >= INT32_MAX / 42) break;
	}

	return 0;
}











Ada: with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Unchecked_Conversion;

procedure Find_Last_Bit is

   type My_Integer is range -2**63 .. 2**63 - 1;

   procedure Find_Set_Bits (Value   : in     My_Integer;
                            MSB_Bit :    out Integer;
                            LSB_Bit :    out Integer)
   is
      type Bit_Field is array (0 .. My_Integer'Size - 1) of Boolean;
      pragma Pack (Bit_Field);
      for Bit_Field'Size use My_Integer'Size;

      function To_Field is
         new Ada.Unchecked_Conversion (My_Integer, Bit_Field);

      Field : constant Bit_Field := To_Field (Value);
   begin

      LSB_Bit := -1;
      MSB_Bit := -1;

      for Bit in Field'Range loop
         if Field (Bit) then
            LSB_Bit := Bit;
            exit;
         end if;
      end loop;

      for Bit in reverse Field'Range loop
         if Field (Bit) then
            MSB_Bit := Bit;
            exit;
         end if;
      end loop;
   end Find_Set_Bits;


   procedure Put_Result (Value : in My_Integer) is
      package My_Integer_IO is
         new Ada.Text_IO.Integer_IO (My_Integer);
      use Ada.Text_IO;
      use Ada.Integer_Text_IO;
      Use My_Integer_IO;

      LSB_Bit, MSB_Bit : Integer;
      Placeholder : String := " MSB XX LSB YY";
      Image_MSB     : String renames Placeholder ( 6 ..  7);
      Image_LSB     : String renames Placeholder (13 .. 14);
   begin
      Find_Set_Bits (Value,
                     MSB_Bit => MSB_Bit,
                     LSB_Bit => LSB_Bit);
      Put (Value, Width => 18);
      Put (Value, Width => 66, Base => 2);
      Put (Image_MSB, MSB_Bit);
      Put (Image_LSB, LSB_Bit);
      Put_Line (Placeholder);
   end Put_Result;

begin
   Put_Result (Value => 0);
   for A in 0 .. 11 loop
      Put_Result (Value => 42 ** A);
   end loop;
end Find_Last_Bit;
Task: Colour bars_Display

C: #include<conio.h>

#define COLOURS 8

int main()
{
	int colour=0,i,j,MAXROW,MAXCOL;
	struct text_info tInfo;
	gettextinfo(&tInfo);
	MAXROW = tInfo.screenheight;
	MAXCOL = tInfo.screenwidth;
	textbackground(BLACK);     
	clrscr();
	
	for(colour=0;colour<COLOURS;colour++)
	{
		getch();                              
		gotoxy(1+colour*MAXCOL/COLOURS,1);
		textbackground(colour);
		for(j=0;j<MAXROW;j++){
			for(i=0;i<MAXCOL/COLOURS;i++){
				cprintf(" ");
			}
		gotoxy(1+colour*MAXCOL/COLOURS,1+j);
		}
	}

	getch();
	textbackground(BLACK);

	return 0;
}











Ada: with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
with SDL.Events.Events;
with SDL.Events.Keyboards;

procedure Colour_Bars_Display is
   use type SDL.Events.Event_Types;
   use SDL.C;

   Colours : constant array (0 .. 7) of SDL.Video.Palettes.Colour :=
     ((0, 0, 0, 255),     (255, 0, 0, 255),
      (0, 255, 0, 255),   (0, 0, 255, 255),
      (255, 0, 255, 255), (0, 255, 255, 255),
      (255, 255, 0, 255), (255, 255, 255, 255));
   Window    : SDL.Video.Windows.Window;
   Renderer  : SDL.Video.Renderers.Renderer;
   Event     : SDL.Events.Events.Events;
   Bar_Width : int;
begin
   if not SDL.Initialise (Flags => SDL.Enable_Screen) then
      return;
   end if;

   SDL.Video.Windows.Makers.Create (Win      => Window,
                                    Title    => "",
                                    Position => SDL.Natural_Coordinates'(0, 0),
                                    Size     => SDL.Positive_Sizes'(0, 0),
                                    Flags    => SDL.Video.Windows.Full_Screen_Desktop);
   SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);

   Bar_Width := Window.Get_Size.Width / 8;
   for A in Colours'Range loop
      Renderer.Set_Draw_Colour (Colour => Colours (A));
      Renderer.Fill (Rectangle => (X => SDL.C.int (A) * Bar_Width, Y => 0,
                                   Width  => Bar_Width,
                                   Height => Window.Get_Size.Height));
   end loop;
   Window.Update_Surface;

   Wait_Loop : loop
      while SDL.Events.Events.Poll (Event) loop
         exit Wait_Loop when Event.Common.Event_Type = SDL.Events.Keyboards.Key_Down;
      end loop;
      delay 0.050;
   end loop Wait_Loop;
   Window.Finalize;
   SDL.Finalise;
end Colour_Bars_Display;