WeixiangYan/CodeTransOcean huggingface dataset:
Task: Non-continuous subsequences



C#: using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main() {
        var sequence = new[] { "A", "B", "C", "D" };
        foreach (var subset in Subsets(sequence.Length).Where(s => !IsContinuous(s))) {
            Console.WriteLine(string.Join(" ", subset.Select(i => sequence[i])));
        }
    }
    
    static IEnumerable<List<int>> Subsets(int length) {
        int[] values = Enumerable.Range(0, length).ToArray();
        var stack = new Stack<int>(length);
        for (int i = 0; stack.Count > 0 || i < length; ) {
            if (i < length) {
                stack.Push(i++);
                yield return (from index in stack.Reverse() select values[index]).ToList();
            } else {
                i = stack.Pop() + 1;
                if (stack.Count > 0) i = stack.Pop() + 1;
            }
        }
    }

    static bool IsContinuous(List<int> list) => list[list.Count - 1] - list[0] + 1 == list.Count;

}









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

procedure Test_Non_Continuous is
   type Sequence is array (Positive range <>) of Integer;
   procedure Put_NCS
             (  Tail : Sequence;                
                Head : Sequence := (1..0 => 1); 
                Contiguous : Boolean := True    
             )  is
   begin
      if not Contiguous and then Head'Length > 1 then
         for I in Head'Range loop
            Put (Integer'Image (Head (I)));
         end loop;
         New_Line;
      end if;
      if Tail'Length /= 0 then 
         declare
            New_Head : Sequence (Head'First..Head'Last + 1);
         begin
            New_Head (Head'Range) := Head;
            for I in Tail'Range loop
               New_Head (New_Head'Last) := Tail (I);
               Put_NCS
               (  Tail => Tail (I + 1..Tail'Last),
                  Head => New_Head,
                  Contiguous => Contiguous and then (I = Tail'First or else Head'Length = 0)
               );
            end loop;
         end;
      end if;
   end Put_NCS;
begin
   Put_NCS ((1,2,3));     New_Line;
   Put_NCS ((1,2,3,4));   New_Line;
   Put_NCS ((1,2,3,4,5)); New_Line;
end Test_Non_Continuous;
Task: Non-continuous subsequences

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

int main(int c, char **v)
{
	unsigned int n = 1 << (c - 1), i = n, j, k;
	assert(n);

	while (i--) {
		if (!(i & (i + (i & -(int)i)))) 
			continue;

		for (j = n, k = 1; j >>= 1; k++)
			if (i & j) printf("%s ", v[k]);

		putchar('\n');
	}

	return 0;
}











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

procedure Test_Non_Continuous is
   type Sequence is array (Positive range <>) of Integer;
   procedure Put_NCS
             (  Tail : Sequence;                
                Head : Sequence := (1..0 => 1); 
                Contiguous : Boolean := True    
             )  is
   begin
      if not Contiguous and then Head'Length > 1 then
         for I in Head'Range loop
            Put (Integer'Image (Head (I)));
         end loop;
         New_Line;
      end if;
      if Tail'Length /= 0 then 
         declare
            New_Head : Sequence (Head'First..Head'Last + 1);
         begin
            New_Head (Head'Range) := Head;
            for I in Tail'Range loop
               New_Head (New_Head'Last) := Tail (I);
               Put_NCS
               (  Tail => Tail (I + 1..Tail'Last),
                  Head => New_Head,
                  Contiguous => Contiguous and then (I = Tail'First or else Head'Length = 0)
               );
            end loop;
         end;
      end if;
   end Put_NCS;
begin
   Put_NCS ((1,2,3));     New_Line;
   Put_NCS ((1,2,3,4));   New_Line;
   Put_NCS ((1,2,3,4,5)); New_Line;
end Test_Non_Continuous;
Task: Non-continuous subsequences


C++: 
class N{
  uint n,i,g,e,l;
public:
  N(uint n): n(n-1),i{},g{},e(1),l(n-1){}
  bool hasNext(){
    g=(1<<n)+e;for(i=l;i<n;++i) g+=1<<i;
    if (l==2)             {l=--n; e=1; return true;}
    if (e<((1<<(l-1))-1)) {++e;        return true;}
                           e=1; --l;   return (l>0);
  }
  uint next() {return g;}
};










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

procedure Test_Non_Continuous is
   type Sequence is array (Positive range <>) of Integer;
   procedure Put_NCS
             (  Tail : Sequence;                
                Head : Sequence := (1..0 => 1); 
                Contiguous : Boolean := True    
             )  is
   begin
      if not Contiguous and then Head'Length > 1 then
         for I in Head'Range loop
            Put (Integer'Image (Head (I)));
         end loop;
         New_Line;
      end if;
      if Tail'Length /= 0 then 
         declare
            New_Head : Sequence (Head'First..Head'Last + 1);
         begin
            New_Head (Head'Range) := Head;
            for I in Tail'Range loop
               New_Head (New_Head'Last) := Tail (I);
               Put_NCS
               (  Tail => Tail (I + 1..Tail'Last),
                  Head => New_Head,
                  Contiguous => Contiguous and then (I = Tail'First or else Head'Length = 0)
               );
            end loop;
         end;
      end if;
   end Put_NCS;
begin
   Put_NCS ((1,2,3));     New_Line;
   Put_NCS ((1,2,3,4));   New_Line;
   Put_NCS ((1,2,3,4,5)); New_Line;
end Test_Non_Continuous;
Task: Non-continuous subsequences




Go: package main

import "fmt"

const ( 
    m   = iota 
    c          
    cm         
    cmc        
)

func ncs(s []int) [][]int {
    if len(s) < 3 {
        return nil
    }
    return append(n2(nil, s[1:], m), n2([]int{s[0]}, s[1:], c)...)
}

var skip = []int{m, cm, cm, cmc}
var incl = []int{c, c, cmc, cmc}

func n2(ss, tail []int, seq int) [][]int {
    if len(tail) == 0 {
        if seq != cmc {
            return nil
        }
        return [][]int{ss}
    }
    return append(n2(append([]int{}, ss...), tail[1:], skip[seq]),
        n2(append(ss, tail[0]), tail[1:], incl[seq])...)
}

func main() {
    ss := ncs([]int{1, 2, 3, 4})
    fmt.Println(len(ss), "non-continuous subsequences:")
    for _, s := range ss {
        fmt.Println("  ", s)
    }
}








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

procedure Test_Non_Continuous is
   type Sequence is array (Positive range <>) of Integer;
   procedure Put_NCS
             (  Tail : Sequence;                
                Head : Sequence := (1..0 => 1); 
                Contiguous : Boolean := True    
             )  is
   begin
      if not Contiguous and then Head'Length > 1 then
         for I in Head'Range loop
            Put (Integer'Image (Head (I)));
         end loop;
         New_Line;
      end if;
      if Tail'Length /= 0 then 
         declare
            New_Head : Sequence (Head'First..Head'Last + 1);
         begin
            New_Head (Head'Range) := Head;
            for I in Tail'Range loop
               New_Head (New_Head'Last) := Tail (I);
               Put_NCS
               (  Tail => Tail (I + 1..Tail'Last),
                  Head => New_Head,
                  Contiguous => Contiguous and then (I = Tail'First or else Head'Length = 0)
               );
            end loop;
         end;
      end if;
   end Put_NCS;
begin
   Put_NCS ((1,2,3));     New_Line;
   Put_NCS ((1,2,3,4));   New_Line;
   Put_NCS ((1,2,3,4,5)); New_Line;
end Test_Non_Continuous;
Task: Non-continuous subsequences





Java: public class NonContinuousSubsequences {

    public static void main(String args[]) {
        seqR("1234", "", 0, 0);
    }

    private static void seqR(String s, String c, int i, int added) {
        if (i == s.length()) {
            if (c.trim().length() > added)
                System.out.println(c);
        } else {
            seqR(s, c + s.charAt(i), i + 1, added + 1);
            seqR(s, c + ' ', i + 1, added);
        }
    }
}







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

procedure Test_Non_Continuous is
   type Sequence is array (Positive range <>) of Integer;
   procedure Put_NCS
             (  Tail : Sequence;                
                Head : Sequence := (1..0 => 1); 
                Contiguous : Boolean := True    
             )  is
   begin
      if not Contiguous and then Head'Length > 1 then
         for I in Head'Range loop
            Put (Integer'Image (Head (I)));
         end loop;
         New_Line;
      end if;
      if Tail'Length /= 0 then 
         declare
            New_Head : Sequence (Head'First..Head'Last + 1);
         begin
            New_Head (Head'Range) := Head;
            for I in Tail'Range loop
               New_Head (New_Head'Last) := Tail (I);
               Put_NCS
               (  Tail => Tail (I + 1..Tail'Last),
                  Head => New_Head,
                  Contiguous => Contiguous and then (I = Tail'First or else Head'Length = 0)
               );
            end loop;
         end;
      end if;
   end Put_NCS;
begin
   Put_NCS ((1,2,3));     New_Line;
   Put_NCS ((1,2,3,4));   New_Line;
   Put_NCS ((1,2,3,4,5)); New_Line;
end Test_Non_Continuous;
Task: Non-continuous subsequences







Python: def ncsub(seq, s=0):
    if seq:
        x = seq[:1]
        xs = seq[1:]
        p2 = s % 2
        p1 = not p2
        return [x + ys for ys in ncsub(xs, s + p1)] + ncsub(xs, s + p2)
    else:
        return [[]] if s >= 3 else []





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

procedure Test_Non_Continuous is
   type Sequence is array (Positive range <>) of Integer;
   procedure Put_NCS
             (  Tail : Sequence;                
                Head : Sequence := (1..0 => 1); 
                Contiguous : Boolean := True    
             )  is
   begin
      if not Contiguous and then Head'Length > 1 then
         for I in Head'Range loop
            Put (Integer'Image (Head (I)));
         end loop;
         New_Line;
      end if;
      if Tail'Length /= 0 then 
         declare
            New_Head : Sequence (Head'First..Head'Last + 1);
         begin
            New_Head (Head'Range) := Head;
            for I in Tail'Range loop
               New_Head (New_Head'Last) := Tail (I);
               Put_NCS
               (  Tail => Tail (I + 1..Tail'Last),
                  Head => New_Head,
                  Contiguous => Contiguous and then (I = Tail'First or else Head'Length = 0)
               );
            end loop;
         end;
      end if;
   end Put_NCS;
begin
   Put_NCS ((1,2,3));     New_Line;
   Put_NCS ((1,2,3,4));   New_Line;
   Put_NCS ((1,2,3,4,5)); New_Line;
end Test_Non_Continuous;
Task: Non-continuous subsequences








VB: 

Function noncontsubseq(l)
    Dim  i, j, g, n, r, s, w, m
    Dim  a, b, c
    n = Ubound(l)
    For s = 0 To n-2
        For g = s+1 To n-1
            a = "["
            For i = s To g-1
                a = a & l(i) & ", "
            Next 
            For w = 1 To n-g
                r = n+1-g-w
                For i = 1 To 2^r-1 Step 2
                    b = a
                    For j = 0 To r-1
                        If i And 2^j Then b=b & l(g+w+j) & ", "
                    Next 
                    c = (Left(b, Len(b)-1))
                    WScript.Echo Left(c, Len(c)-1) & "]"
					m = m+1
                Next 
            Next 
        Next 
    Next 
    noncontsubseq = m
End Function 

list = Array("1", "2", "3", "4")
WScript.Echo "List: [" & Join(list, ", ") & "]"
nn = noncontsubseq(list)
WScript.Echo nn & " non-continuous subsequences"




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

procedure Test_Non_Continuous is
   type Sequence is array (Positive range <>) of Integer;
   procedure Put_NCS
             (  Tail : Sequence;                
                Head : Sequence := (1..0 => 1); 
                Contiguous : Boolean := True    
             )  is
   begin
      if not Contiguous and then Head'Length > 1 then
         for I in Head'Range loop
            Put (Integer'Image (Head (I)));
         end loop;
         New_Line;
      end if;
      if Tail'Length /= 0 then 
         declare
            New_Head : Sequence (Head'First..Head'Last + 1);
         begin
            New_Head (Head'Range) := Head;
            for I in Tail'Range loop
               New_Head (New_Head'Last) := Tail (I);
               Put_NCS
               (  Tail => Tail (I + 1..Tail'Last),
                  Head => New_Head,
                  Contiguous => Contiguous and then (I = Tail'First or else Head'Length = 0)
               );
            end loop;
         end;
      end if;
   end Put_NCS;
begin
   Put_NCS ((1,2,3));     New_Line;
   Put_NCS ((1,2,3,4));   New_Line;
   Put_NCS ((1,2,3,4,5)); New_Line;
end Test_Non_Continuous;
Task: Non-continuous subsequences

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

int main(int c, char **v)
{
	unsigned int n = 1 << (c - 1), i = n, j, k;
	assert(n);

	while (i--) {
		if (!(i & (i + (i & -(int)i)))) 
			continue;

		for (j = n, k = 1; j >>= 1; k++)
			if (i & j) printf("%s ", v[k]);

		putchar('\n');
	}

	return 0;
}
Task: Non-continuous subsequences



C#: using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main() {
        var sequence = new[] { "A", "B", "C", "D" };
        foreach (var subset in Subsets(sequence.Length).Where(s => !IsContinuous(s))) {
            Console.WriteLine(string.Join(" ", subset.Select(i => sequence[i])));
        }
    }
    
    static IEnumerable<List<int>> Subsets(int length) {
        int[] values = Enumerable.Range(0, length).ToArray();
        var stack = new Stack<int>(length);
        for (int i = 0; stack.Count > 0 || i < length; ) {
            if (i < length) {
                stack.Push(i++);
                yield return (from index in stack.Reverse() select values[index]).ToList();
            } else {
                i = stack.Pop() + 1;
                if (stack.Count > 0) i = stack.Pop() + 1;
            }
        }
    }

    static bool IsContinuous(List<int> list) => list[list.Count - 1] - list[0] + 1 == list.Count;

}
Task: Non-continuous subsequences


C++: 
class N{
  uint n,i,g,e,l;
public:
  N(uint n): n(n-1),i{},g{},e(1),l(n-1){}
  bool hasNext(){
    g=(1<<n)+e;for(i=l;i<n;++i) g+=1<<i;
    if (l==2)             {l=--n; e=1; return true;}
    if (e<((1<<(l-1))-1)) {++e;        return true;}
                           e=1; --l;   return (l>0);
  }
  uint next() {return g;}
};
Task: Non-continuous subsequences





Java: public class NonContinuousSubsequences {

    public static void main(String args[]) {
        seqR("1234", "", 0, 0);
    }

    private static void seqR(String s, String c, int i, int added) {
        if (i == s.length()) {
            if (c.trim().length() > added)
                System.out.println(c);
        } else {
            seqR(s, c + s.charAt(i), i + 1, added + 1);
            seqR(s, c + ' ', i + 1, added);
        }
    }
}
Task: Non-continuous subsequences







Python: def ncsub(seq, s=0):
    if seq:
        x = seq[:1]
        xs = seq[1:]
        p2 = s % 2
        p1 = not p2
        return [x + ys for ys in ncsub(xs, s + p1)] + ncsub(xs, s + p2)
    else:
        return [[]] if s >= 3 else []
Task: Non-continuous subsequences








VB: 

Function noncontsubseq(l)
    Dim  i, j, g, n, r, s, w, m
    Dim  a, b, c
    n = Ubound(l)
    For s = 0 To n-2
        For g = s+1 To n-1
            a = "["
            For i = s To g-1
                a = a & l(i) & ", "
            Next 
            For w = 1 To n-g
                r = n+1-g-w
                For i = 1 To 2^r-1 Step 2
                    b = a
                    For j = 0 To r-1
                        If i And 2^j Then b=b & l(g+w+j) & ", "
                    Next 
                    c = (Left(b, Len(b)-1))
                    WScript.Echo Left(c, Len(c)-1) & "]"
					m = m+1
                Next 
            Next 
        Next 
    Next 
    noncontsubseq = m
End Function 

list = Array("1", "2", "3", "4")
WScript.Echo "List: [" & Join(list, ", ") & "]"
nn = noncontsubseq(list)
WScript.Echo nn & " non-continuous subsequences"
Task: Non-continuous subsequences




Go: package main

import "fmt"

const ( 
    m   = iota 
    c          
    cm         
    cmc        
)

func ncs(s []int) [][]int {
    if len(s) < 3 {
        return nil
    }
    return append(n2(nil, s[1:], m), n2([]int{s[0]}, s[1:], c)...)
}

var skip = []int{m, cm, cm, cmc}
var incl = []int{c, c, cmc, cmc}

func n2(ss, tail []int, seq int) [][]int {
    if len(tail) == 0 {
        if seq != cmc {
            return nil
        }
        return [][]int{ss}
    }
    return append(n2(append([]int{}, ss...), tail[1:], skip[seq]),
        n2(append(ss, tail[0]), tail[1:], incl[seq])...)
}

func main() {
    ss := ncs([]int{1, 2, 3, 4})
    fmt.Println(len(ss), "non-continuous subsequences:")
    for _, s := range ss {
        fmt.Println("  ", s)
    }
}
Task: Binary digits



C#: using System;

class Program
{
    static void Main()
    {
        foreach (var number in new[] { 5, 50, 9000 })
        {
            Console.WriteLine(Convert.ToString(number, 2));
        }
    }
}









Ada: with ada.text_io; use ada.text_io;
procedure binary is 
  bit : array (0..1) of character := ('0','1');

  function bin_image (n : Natural) return string is 
  (if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));

  test_values : array (1..3) of Natural := (5,50,9000); 
begin
  for test of test_values loop 
	put_line ("Output for" & test'img & " is " & bin_image (test)); 
  end loop; 
end binary;
Task: Binary digits

C: #define _CRT_SECURE_NO_WARNINGS    
#define _CRT_NONSTDC_NO_DEPRECATE   

#include <stdio.h>
#include <stdlib.h>


char* bin2str(unsigned value, char* buffer)
{
    
    
    
    
    
    
    

    const unsigned N_DIGITS = sizeof(unsigned) * 8;
    unsigned mask = 1 << (N_DIGITS - 1);
    char* ptr = buffer;

    for (int i = 0; i < N_DIGITS; i++)
    {
        *ptr++ = '0' + !!(value & mask);
        mask >>= 1;
    }
    *ptr = '\0';

    
    
    for (ptr = buffer; *ptr == '0'; ptr++)
        ;

    return ptr;
}


char* bin2strNaive(unsigned value, char* buffer)
{
    

    unsigned n, m, p;

    n = 0;
    p = 1;  
    while (p <= value / 2)
    {
        n = n + 1;
        p = p * 2;
    }

    m = 0;
    while (n > 0)
    {
        buffer[m] = '0' + value / p;
        value = value % p;
        m = m + 1;
        n = n - 1;
        p = p / 2;
    }

    buffer[m + 1] = '\0';
    return buffer;
}


int main(int argc, char* argv[])
{
    const unsigned NUMBERS[] = { 5, 50, 9000 };

    const int RADIX = 2;
    char buffer[(sizeof(unsigned)*8 + 1)];

    
    
    
    
    
    
    
    for (int i = 0; i < sizeof(NUMBERS) / sizeof(unsigned); i++)
    {
        unsigned value = NUMBERS[i];
        itoa(value, buffer, RADIX);
        printf("itoa:          %u decimal = %s binary\n", value, buffer);
    }

    
    
    
    for (int i = 0; i < sizeof(NUMBERS) / sizeof(unsigned); i++)
    {
        unsigned value = NUMBERS[i];
        printf("bin2str:       %u decimal = %s binary\n", value, bin2str(value, buffer));
    }

    
    
    for (int i = 0; i < sizeof(NUMBERS) / sizeof(unsigned); i++)
    {
        unsigned value = NUMBERS[i];
        printf("bin2strNaive:  %u decimal = %s binary\n", value, bin2strNaive(value, buffer));
    }

    return EXIT_SUCCESS;
}











Ada: with ada.text_io; use ada.text_io;
procedure binary is 
  bit : array (0..1) of character := ('0','1');

  function bin_image (n : Natural) return string is 
  (if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));

  test_values : array (1..3) of Natural := (5,50,9000); 
begin
  for test of test_values loop 
	put_line ("Output for" & test'img & " is " & bin_image (test)); 
  end loop; 
end binary;
Task: Binary digits


C++: #include <bitset>
#include <iostream>
#include <limits>
#include <string>
 
void print_bin(unsigned int n) {
  std::string str = "0";

  if (n > 0) {
    str = std::bitset<std::numeric_limits<unsigned int>::digits>(n).to_string();
    str = str.substr(str.find('1')); 
  } 
  
  std::cout << str << '\n';
}

int main() {
  print_bin(0);
  print_bin(5);
  print_bin(50);
  print_bin(9000);
}










Ada: with ada.text_io; use ada.text_io;
procedure binary is 
  bit : array (0..1) of character := ('0','1');

  function bin_image (n : Natural) return string is 
  (if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));

  test_values : array (1..3) of Natural := (5,50,9000); 
begin
  for test of test_values loop 
	put_line ("Output for" & test'img & " is " & bin_image (test)); 
  end loop; 
end binary;
Task: Binary digits




Go: package main

import (
	"fmt"
)

func main() {
	for i := 0; i < 16; i++ {
		fmt.Printf("%b\n", i)
	}
}








Ada: with ada.text_io; use ada.text_io;
procedure binary is 
  bit : array (0..1) of character := ('0','1');

  function bin_image (n : Natural) return string is 
  (if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));

  test_values : array (1..3) of Natural := (5,50,9000); 
begin
  for test of test_values loop 
	put_line ("Output for" & test'img & " is " & bin_image (test)); 
  end loop; 
end binary;
Task: Binary digits





Java: module BinaryDigits
    {
    @Inject Console console;
    void run()
        {
        Int[] tests = [0, 1, 5, 50, 9000];

        Int longestInt = tests.map(n -> n.estimateStringLength()).reduce(0, (max, len) -> max.maxOf(len));
        Int longestBin = tests.map(n -> (64-n.leadingZeroCount).maxOf(1)).reduce(0, (max, len) -> max.maxOf(len));

        function String(Int) num = n ->
            {
            Int indent = longestInt - n.estimateStringLength();
            return $"{' ' * indent}{n}";
            };

        function String(Int) bin = n ->
            {
            Int index  = n.leadingZeroCount.minOf(63);
            Int indent = index - (64 - longestBin);
            val bits   = n.toBitArray()[index ..< 64];
            return $"{' ' * indent}{bits.toString().substring(2)}";
            };

        for (Int test : tests)
            {
            console.print($"The decimal value {num(test)} should produce an output of {bin(test)}");
            }
        }
    }







Ada: with ada.text_io; use ada.text_io;
procedure binary is 
  bit : array (0..1) of character := ('0','1');

  function bin_image (n : Natural) return string is 
  (if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));

  test_values : array (1..3) of Natural := (5,50,9000); 
begin
  for test of test_values loop 
	put_line ("Output for" & test'img & " is " & bin_image (test)); 
  end loop; 
end binary;
Task: Binary digits







Python: >>> for i in range(16): print('{0:b}'.format(i))

0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111





Ada: with ada.text_io; use ada.text_io;
procedure binary is 
  bit : array (0..1) of character := ('0','1');

  function bin_image (n : Natural) return string is 
  (if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));

  test_values : array (1..3) of Natural := (5,50,9000); 
begin
  for test of test_values loop 
	put_line ("Output for" & test'img & " is " & bin_image (test)); 
  end loop; 
end binary;
Task: Binary digits








VB: 
Print "bin 5 = ", bin$(5)
Print "bin 50 = ",bin$(50)
Print "bin 9000 = ",bin$(9000)
sleep 10




Ada: with ada.text_io; use ada.text_io;
procedure binary is 
  bit : array (0..1) of character := ('0','1');

  function bin_image (n : Natural) return string is 
  (if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));

  test_values : array (1..3) of Natural := (5,50,9000); 
begin
  for test of test_values loop 
	put_line ("Output for" & test'img & " is " & bin_image (test)); 
  end loop; 
end binary;