WeixiangYan/CodeTransOcean huggingface dataset:
Task: Terminal control_Dimensions








VB: Module Module1

    Sub Main()
        Dim bufferHeight = Console.BufferHeight
        Dim bufferWidth = Console.BufferWidth
        Dim windowHeight = Console.WindowHeight
        Dim windowWidth = Console.WindowWidth

        Console.Write("Buffer Height: ")
        Console.WriteLine(bufferHeight)
        Console.Write("Buffer Width: ")
        Console.WriteLine(bufferWidth)
        Console.Write("Window Height: ")
        Console.WriteLine(windowHeight)
        Console.Write("Window Width: ")
        Console.WriteLine(windowWidth)
    End Sub

End Module


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. terminal-dimensions.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  num-lines PIC 9(3).
       01  num-cols  PIC 9(3).

       SCREEN SECTION.
       01  display-screen.
           03  LINE 01 COL 01 PIC 9(3) FROM num-lines.
           03  LINE 01 COL 05 VALUE "rows by " .
           03  LINE 01 COL 13 PIC 9(3) FROM num-cols.
           03  LINE 01 COL 16 VALUE " columns.".

       PROCEDURE DIVISION.
           ACCEPT num-lines FROM LINES
           ACCEPT num-cols FROM COLUMNS

           DISPLAY display-screen

      *    This pauses the program, as ncurses will immediately revert
      *    back to the console when the program ends.
           CALL "C$SLEEP" USING BY CONTENT 3

           GOBACK
           .
Task: Sorting algorithms_Bead sort








VB: Option Base 1

Private Function sq_add(arr As Variant, x As Double) As Variant
    Dim res() As Variant
    ReDim res(UBound(arr))
    For i = 1 To UBound(arr)
        res(i) = arr(i) + x
    Next i
    sq_add = res
End Function

Private Function beadsort(ByVal a As Variant) As Variant
    Dim poles() As Variant
    ReDim poles(WorksheetFunction.Max(a))
    For i = 1 To UBound(a)
        For j = 1 To a(i)
            poles(j) = poles(j) + 1
        Next j
    Next i
    For j = 1 To UBound(a)
        a(j) = 0
    Next j
    For i = 1 To UBound(poles)
        For j = 1 To poles(i)
            a(j) = a(j) + 1
        Next j
    Next i
    beadsort = a
End Function
 
Public Sub main()
    Debug.Print Join(beadsort([{5, 3, 1, 7, 4, 1, 1, 20}]), ", ")
End Sub


COBOL:         >>SOURCE FORMAT FREE


identification division.
program-id. beadsort.
environment division.
configuration section.
repository. function all intrinsic.
data division.
working-storage section.
01  filler.
    03  row occurs 9 pic x(9).
    03  r pic 99.
    03  r1 pic 99.
    03  r2 pic 99.
    03  pole pic 99.
    03  a-lim pic 99 value 9.
    03  a pic 99.
    03  array occurs 9 pic 9.
01  NL pic x value x'0A'.
procedure division.
start-beadsort.

    
    compute a = random(seconds-past-midnight)
    perform varying a from 1 by 1 until a > a-lim
        compute array(a) = random() * 10
    end-perform

    perform display-array
    display space 'initial array'

    
    perform varying r from 1 by 1 until r > a-lim
        move all '.' to row(r)
        perform varying pole from 1 by 1 until pole > array(r)
            move 'o' to row(r)(pole:1)
        end-perform
    end-perform
    display NL 'initial beads'
    perform display-beads

    
    perform varying pole from 1 by 1 until pole > a-lim
        move a-lim to r2
        perform find-opening
        compute r1 = r2 - 1
        perform find-bead
        perform until r1 = 0 
            
            move '.' to row(r1)(pole:1)
            move 'o' to row(r2)(pole:1)
            
            compute r2 = r2 - 1
            perform find-opening
            compute r1 = r2 - 1
            perform find-bead
        end-perform
    end-perform
    display NL 'dropped beads'
    perform display-beads

    
    perform varying r from 1 by 1 until r > a-lim
        move 0 to array(r)
        inspect row(r) tallying array(r)
            for all 'o' before initial '.'
    end-perform

    perform display-array
    display space 'sorted array'

    stop run
    .
find-opening.
    perform varying r2 from r2 by -1
    until r2 = 1 or row(r2)(pole:1) = '.'
        continue
    end-perform
    .
find-bead.
    perform varying r1 from r1 by -1
    until r1 = 0 or row(r1)(pole:1) = 'o'
        continue
    end-perform
    .
display-array.
    display space
    perform varying a from 1 by 1 until a > a-lim
        display space array(a) with no advancing
    end-perform
    .
display-beads.
    perform varying r from 1 by 1 until r > a-lim
        display row(r)
    end-perform
    .
end program beadsort.
Task: Tau function








VB: Public Sub Main()  
  
  Print "The tau functions for the first 100 positive integers are:\n" 
  For i As Integer = 1 To 100 
    Print Format$(numdiv(i), "####");  
    If i Mod 10 = 0 Then Print 
  Next 
  
End

Public Function numdiv(n As Integer) As Integer 

  Dim c As Integer = 1 
  For i As Integer = 1 To (n + 1) \ 2 
    If n Mod i = 0 Then c += 1 
  Next 
  If n = 1 Then c -= 1 
  Return c 

End Function


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. TAU-FUNCTION.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 TAU-VARS.
          03 TOTAL              PIC 999.
          03 N                  PIC 999.
          03 FILLER             REDEFINES N.
             05 FILLER          PIC 99.
             05 FILLER          PIC 9.
                88 N-EVEN       VALUES 0, 2, 4, 6, 8.
          03 P                  PIC 999.
          03 P-SQUARED          PIC 999.
          03 N-DIV-P            PIC 999V999.
          03 FILLER             REDEFINES N-DIV-P.
             05 NEXT-N          PIC 999.
             05 FILLER          PIC 999.
                88 DIVISIBLE    VALUE ZERO.
          03 F-COUNT            PIC 999.
       01 CONTROL-VARS.
          03 I                  PIC 999.
       01 OUT-VARS.
          03 OUT-ITM            PIC ZZ9.
          03 OUT-STR            PIC X(80) VALUE SPACES.
          03 OUT-PTR            PIC 99 VALUE 1.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SHOW-TAU VARYING I FROM 1 BY 1
               UNTIL I IS GREATER THAN 100.
           STOP RUN.
       
       SHOW-TAU.
           MOVE I TO N.
           PERFORM TAU.
           MOVE TOTAL TO OUT-ITM.
           STRING OUT-ITM DELIMITED BY SIZE INTO OUT-STR
               WITH POINTER OUT-PTR.
           IF OUT-PTR IS EQUAL TO 61,
               DISPLAY OUT-STR,
               MOVE 1 TO OUT-PTR.

       TAU.
           MOVE 1 TO TOTAL.
           PERFORM POWER-OF-2 UNTIL NOT N-EVEN.
           MOVE ZERO TO P-SQUARED.
           PERFORM ODD-FACTOR THRU ODD-FACTOR-LOOP
               VARYING P FROM 3 BY 2
               UNTIL P-SQUARED IS GREATER THAN N.
           IF N IS GREATER THAN 1,
               MULTIPLY 2 BY TOTAL.
       POWER-OF-2.
           ADD 1 TO TOTAL.
           DIVIDE 2 INTO N.
       ODD-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           MOVE 1 TO F-COUNT.
       ODD-FACTOR-LOOP.
           DIVIDE N BY P GIVING N-DIV-P.
           IF DIVISIBLE,
               MOVE NEXT-N TO N,
               ADD 1 TO F-COUNT,
               GO TO ODD-FACTOR-LOOP.
           MULTIPLY F-COUNT BY TOTAL.
Task: Harmonic series








VB: Public Sub Main() 
  
  Dim h As Float = 0
  Dim n As Integer, i As Integer
  
  Print "The first twenty harmonic numbers are:" 
  For n = 1 To 20 
    h += 1 / n 
    Print n, h 
  Next 
  Print 
  
  h = 1
  n = 2 
  For i = 2 To 10 
    While h < i 
      h += 1 / n 
      n += 1 
    Wend 
    Print "The first harmonic number greater than "; i; " is "; h; ", at position "; n - 1 
  Next
  
End


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. HARMONIC.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARS.
          03 N           PIC 9(5) VALUE ZERO.
          03 HN          PIC 9(2)V9(12) VALUE ZERO.
          03 INT         PIC 99 VALUE ZERO.
       01 OUT-VARS.
          03 POS         PIC Z(4)9.
          03 FILLER      PIC X(3) VALUE SPACES.
          03 H-OUT       PIC Z9.9(12).

       PROCEDURE DIVISION.
       BEGIN.
           DISPLAY "First 20 harmonic numbers:"
           PERFORM SHOW-HARMONIC 20 TIMES.
           DISPLAY SPACES.
           MOVE ZERO TO N, HN.
           DISPLAY "First harmonic number to exceed whole number:"
           PERFORM EXCEED-INT 10 TIMES.
           STOP RUN.

       SHOW-HARMONIC.
           PERFORM NEXT-HARMONIC.
           MOVE HN TO H-OUT.
           DISPLAY H-OUT.

       EXCEED-INT.
           ADD 1 TO INT.
           PERFORM NEXT-HARMONIC UNTIL HN IS GREATER THAN INT.
           MOVE N TO POS.
           MOVE HN TO H-OUT.
           DISPLAY OUT-VARS.

       NEXT-HARMONIC.
           ADD 1 TO N.
           COMPUTE HN = HN + 1 / N.
Task: Test integerness








VB: #define isInteger(x)  iif(Int(val(x)) = val(x), 1, 0)

Dim As String test(1 To 8) = {"25.000000", "24.999999", "25.000100", "-2.1e120", "-5e-2", "NaN", "Inf", "-0.05"}

For i As Integer = 1 To Ubound(test)
    Dim As String s = test(i)
    
    Print s,
    If isInteger(s) then Print "is integer" Else Print "is not integer"
Next i

Sleep


COBOL: IDENTIFICATION DIVISION.
PROGRAM-ID. INTEGERNESS-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  INTEGERS-OR-ARE-THEY.
    05 POSSIBLE-INTEGER PIC S9(9)V9(9).
    05 DEFINITE-INTEGER PIC S9(9).
01  COMPLEX-NUMBER.
    05 REAL-PART        PIC S9(9)V9(9).
    05 IMAGINARY-PART   PIC S9(9)V9(9).
PROCEDURE DIVISION.
TEST-PARAGRAPH.
    MOVE ZERO TO IMAGINARY-PART.
    DIVIDE -28 BY 7 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    DIVIDE 28 BY 18 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    DIVIDE 3 BY 10000000000 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
TEST-COMPLEX-PARAGRAPH.
    MOVE ZERO TO REAL-PART.
    MOVE 1 TO IMAGINARY-PART.
    MOVE REAL-PART TO POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    STOP RUN.
INTEGER-PARAGRAPH.
    IF IMAGINARY-PART IS EQUAL TO ZERO THEN PERFORM REAL-PARAGRAPH,
    ELSE PERFORM COMPLEX-PARAGRAPH.
REAL-PARAGRAPH.
    MOVE POSSIBLE-INTEGER TO DEFINITE-INTEGER.
    IF DEFINITE-INTEGER IS EQUAL TO POSSIBLE-INTEGER
    THEN DISPLAY POSSIBLE-INTEGER ' IS AN INTEGER.',
    ELSE DISPLAY POSSIBLE-INTEGER ' IS NOT AN INTEGER.'.
COMPLEX-PARAGRAPH.
    DISPLAY REAL-PART '+' IMAGINARY-PART 'i IS NOT AN INTEGER.'.
Task: Print debugging statement








VB: #if __FB_DEBUG__ <> 0
    #print Debug mode 
    Dim err_command_line As Ubyte
    err_command_line = __fb_err__
    Select Case err_command_line
    Case 0
        Print "No Error Checking enabled on the Command Line!"
    Case 1
        Print "Some Error Checking enabled on the Command Line!"
    Case 3
        Print "QBasic style Error Checking enabled on the Command Line!"
    Case 7
        Print "Extreme Error Checking enabled on the Command Line!"
    Case Else
        Print "Some Unknown Error level has been set!"
    End Select
#else 
    #print Release mode 
#endif

Sleep


COBOL: gcobol
      
      
      
      
       identification division.
       program-id. steptrace.

       data division.
       working-storage section.

       procedure division.
       steptrace-main.

       display "explicit line" upon syserr

    >>Ddisplay "debug line" upon syserr

       display "from " FUNCTION MODULE-ID " in " FUNCTION MODULE-SOURCE
       goback.
       end program steptrace.
Task: Sorting algorithms_Shell sort





Java: public static void shell(int[] a) {
	int increment = a.length / 2;
	while (increment > 0) {
		for (int i = increment; i < a.length; i++) {
			int j = i;
			int temp = a[i];
			while (j >= increment && a[j - increment] > temp) {
				a[j] = a[j - increment];
				j = j - increment;
			}
			a[j] = temp;
		}
		if (increment == 2) {
			increment = 1;
		} else {
			increment *= (5.0 / 11);
		}
	}
}
Task: Rate counter





Java: import java.util.function.Consumer;

public class RateCounter {

    public static void main(String[] args) {
        for (double d : benchmark(10, x -> System.out.print(""), 10))
            System.out.println(d);
    }

    static double[] benchmark(int n, Consumer<Integer> f, int arg) {
        double[] timings = new double[n];
        for (int i = 0; i < n; i++) {
            long time = System.nanoTime();
            f.accept(arg);
            timings[i] = System.nanoTime() - time;
        }
        return timings;
    }
}
Task: Sierpinski arrowhead curve







Python: t = { 'x': 20, 'y': 30, 'a': 60 }

def setup():
    size(450, 400)
    background(0, 0, 200)
    stroke(-1)
    sc(7, 400, -60)

def sc(o, l, a, s = t, X = 'x', Y = 'y', A = 'a', HALF = .5):
    if o:
        o -= 1
        l *= HALF
        sc(o, l, -a)[A] += a
        sc(o, l, a)[A] += a
        sc(o, l, -a)
    else:
        x, y = s[X], s[Y]
        s[X] += cos(radians(s[A])) * l
        s[Y] += sin(radians(s[A])) * l
        line(x, y, s[X], s[Y])

    return s





Ada: with Ada.Command_Line;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with PDF_Out;

procedure Arrowhead_Curve is

   package Real_Math is
     new Ada.Numerics.Generic_Elementary_Functions (PDF_Out.Real);
   use Real_Math, PDF_Out, Ada.Command_Line, Ada.Text_IO;

   subtype Angle_Deg  is Real;
   type    Order_Type is range 0 .. 7;

   Purple : constant Color_Type := (0.7, 0.0, 0.5);
   Length : constant Real       := 340.0;
   Corner : constant Point      := (120.0, 480.0);

   Order     : Order_Type;
   Current   : Point      := (0.0, 0.0);
   Direction : Angle_Deg  := Angle_Deg'(0.0);
   Doc       : PDF_Out_File;

   procedure Curve (Order : Order_Type; Length : Real; Angle : Angle_Deg) is
   begin
      if Order = 0 then
         Current := Current + Length * Point'(Cos (Direction, 360.0),
                                              Sin (Direction, 360.0));
         Doc.Line (Corner + Current);
      else
         Curve (Order - 1, Length / 2.0, -Angle);  Direction := Direction + Angle;
         Curve (Order - 1, Length / 2.0,  Angle);  Direction := Direction + Angle;
         Curve (Order - 1, Length / 2.0, -Angle);
      end if;
   end Curve;

begin
   if Argument_Count /= 1 then
      Put_Line ("arrowhead_curve <order>");
      Put_Line ("  <order>   0 .. 7");
      Put_Line ("open sierpinski-arrowhead-curve.pdf to view ouput");
      return;
   end if;
   Order := Order_Type'Value (Argument (1));

   Doc.Create ("sierpinski-arrowhead-curve.pdf");
   Doc.Page_Setup (A4_Portrait);
   Doc.Margins (Margins_Type'(Left   => Cm_2_5,
                              others => One_cm));
   Doc.Stroking_Color (Purple);
   Doc.Line_Width (2.0);
   Doc.Move (Corner);
   if Order mod 2 = 0 then
      Direction := 0.0;
      Curve (Order, Length, 60.0);
   else
      Direction := 60.0;
      Curve (Order, Length, -60.0);
   end if;
   Doc.Finish_Path (Close_Path => False,
                    Rendering  => Stroke,
                    Rule       => Nonzero_Winding_Number);
   Doc.Close;
end Arrowhead_Curve;
Task: Hello world_Line printer







Python: lp = open("/dev/lp0")
lp.write("Hello World!\n")
lp.close()





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

procedure Print_Line is
   Printer : File_Type;
begin
   begin
      Open (Printer, Mode => Out_File, Name => "/dev/lp0");
   exception
      when others =>
         Put_Line ("Unable to open printer.");
         return;
   end;

   Set_Output (Printer);
   Put_Line ("Hello World!");
   Close (Printer);
end Print_Line;
Task: Magic squares of odd order







Python: >>> def magic(n):
    for row in range(1, n + 1):
        print(' '.join('%*i' % (len(str(n**2)), cell) for cell in
                       (n * ((row + col - 1 + n // 2) % n) +
                       ((row + 2 * col - 2) % n) + 1
                       for col in range(1, n + 1))))
    print('\nAll sum to magic number %i' % ((n * n + 1) * n // 2))

    
>>> for n in (5, 3, 7):
	print('\nOrder %i\n=======' % n)
	magic(n)

	

Order 5
=======
17 24  1  8 15
23  5  7 14 16
 4  6 13 20 22
10 12 19 21  3
11 18 25  2  9

All sum to magic number 65

Order 3
=======
8 1 6
3 5 7
4 9 2

All sum to magic number 15

Order 7
=======
30 39 48  1 10 19 28
38 47  7  9 18 27 29
46  6  8 17 26 35 37
 5 14 16 25 34 36 45
13 15 24 33 42 44  4
21 23 32 41 43  3 12
22 31 40 49  2 11 20

All sum to magic number 175
>>>





Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Magic_Square is
   N: constant Positive := Positive'Value(Ada.Command_Line.Argument(1));
   
   subtype Constants is Natural range 1 .. N*N;
   package CIO is new Ada.Text_IO.Integer_IO(Constants);
   Undef: constant Natural := 0;

   subtype Index is Natural range 0 .. N-1;
   function Inc(I: Index) return Index is (if I = N-1 then 0 else I+1);
   function Dec(I: Index) return Index is (if I = 0 then N-1 else I-1);
    
   A: array(Index, Index) of Natural := (others => (others => Undef));
     
  
   X: Index := 0; Y: Index := N/2; 
begin
   for I in Constants loop 
      A(X, Y) := I; 
      if A(Dec(X), Inc(Y)) = Undef then 
	 X := Dec(X); Y := Inc(Y); 
      else
	 X := Inc(X); 
      end if;
   end loop;
   
   for Row in Index loop 
      for Collumn in Index loop
	 CIO.Put(A(Row, Collumn), 
		 Width => (if N*N < 10 then 2 elsif N*N < 100 then 3 else 4));
      end loop;
      Ada.Text_IO.New_Line;
   end loop;
end Magic_Square;
Task: Sorting algorithms_Pancake sort







Python: tutor = False

def pancakesort(data):
    if len(data) <= 1:
        return data
    if tutor: print()
    for size in range(len(data), 1, -1):
        maxindex = max(range(size), key=data.__getitem__)
        if maxindex+1 != size:
            
            if maxindex != 0:
                
                if tutor: print('With: %r doflip  %i'
                                % ( ' '.join(str(x) for x in data), maxindex+1 ))
                data[:maxindex+1] = reversed(data[:maxindex+1])
            
            if tutor: print('With: %r  doflip %i'
                                % ( ' '.join(str(x) for x in data), size ))
            data[:size] = reversed(data[:size])
    if tutor: print()





Ada: with Ada.Text_IO;
procedure Pancake_Sort is
   generic
      type Element_Type is private;
      type Index_Type is range <>;
      type Array_Type is array (Index_Type range <>) of Element_Type;
      with function ">" (Left, Right : Element_Type) return Boolean is <>;
   procedure Pancake_Sort (Data: in out Array_Type);

   procedure Pancake_Sort (Data: in out Array_Type) is
      procedure Flip (Up_To : in Index_Type) is
         Temp : constant Array_Type := Data (Data'First .. Up_To);
      begin
         for I in Temp'Range loop
            Data (I) := Temp (Temp'First + Up_To - I);
         end loop;
      end Flip;
      Max_Index : Index_Type;
   begin
      for I in reverse Data'First + 1 .. Data'Last loop
         Max_Index := Data'First;
         for A in Data'First + 1 .. I loop
            if Data(A) > Data (Max_Index) then
               Max_Index := A;
            end if;
         end loop;
         if Max_Index /= I then
            if Max_Index > Data'First then
               Flip (Max_Index);
            end if;
            Flip (I);
         end if;
      end loop;
   end Pancake_Sort;

   type Integer_Array is array (Positive range <>) of Integer;
   procedure Int_Pancake_Sort is new Pancake_Sort (Integer, Positive, Integer_Array);
   Test_Array : Integer_Array := (3, 14, 1, 5, 9, 2, 6, 3);
begin
   Int_Pancake_Sort (Test_Array);
   for I in Test_Array'Range loop
      Ada.Text_IO.Put (Integer'Image (Test_Array (I)));
   end loop;
   Ada.Text_IO.New_Line;
end Pancake_Sort;
Task: Call a function







Python: def no_args():
    pass

no_args()

def fixed_args(x, y):
    print('x=%r, y=%r' % (x, y))

fixed_args(1, 2)        


fixed_args(y=2, x=1)


myargs=(1,2) 
fixed_args(*myargs)

def opt_args(x=1):
    print(x)

opt_args()              
opt_args(3.141)         

def var_args(*v):
    print(v)

var_args(1, 2, 3)       
var_args(1, (2,3))      
var_args()              


fixed_args(y=2, x=1)    


if 1:
    no_args()


assert no_args() is None

def return_something():
    return 1
x = return_something()

def is_builtin(x):
	print(x.__name__ in dir(__builtins__))

is_builtin(pow)         
is_builtin(is_builtin)  



def takes_anything(*args, **kwargs):
    for each in args:
        print(each)
    for key, value in sorted(kwargs.items()):
        print("%s:%s" % (key, value))
    
    wrapped_fn(*args, **kwargs)
    
    














Ada: S: String := Ada.Text_IO.Get_Line;
Task: Extract file extension







Python: import re
def extractExt(url):
  m = re.search(r'\.[A-Za-z0-9]+$', url)
  return m.group(0) if m else ""





Ada: with Ada.Text_IO;       use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
use Ada.Strings;
with Ada.Characters.Handling; use Ada.Characters.Handling;

procedure Main is
   function extension (S : in String) return String is
      P_Index : Natural;
   begin
      P_Index :=
        Index (Source => S, Pattern => ".", From => S'Last, Going => Backward);
      if P_Index = 0 then
         return "";
      else
         for C of S (P_Index + 1 .. S'Last) loop
            if not Is_Alphanumeric (C) then
               return "";
            end if;
         end loop;
         return S (P_Index .. S'Last);
      end if;
   end extension;
   F1 : String := "http://example.com/download.tar.gz";
   F2 : String := "CharacterModel.3DS";
   F3 : String := ".desktop";
   F4 : String := "document";
   F5 : String := "document.txt_backup";
   F6 : String := "/etc/pam.d/login:";
begin
   Put_Line (F1 & " -> " & extension (F1));
   Put_Line (F2 & " -> " & extension (F2));
   Put_Line (F3 & " -> " & extension (F3));
   Put_Line (F4 & " -> " & extension (F4));
   Put_Line (F5 & " -> " & extension (F5));
   Put_Line (F6 & " -> " & extension (F6));
end Main;
Task: Solve the no connection puzzle







Python: from __future__ import print_function
from itertools import permutations
from enum import Enum

A, B, C, D, E, F, G, H = Enum('Peg', 'A, B, C, D, E, F, G, H')

connections = ((A, C), (A, D), (A, E),
               (B, D), (B, E), (B, F),
               (G, C), (G, D), (G, E),
               (H, D), (H, E), (H, F),
               (C, D), (D, E), (E, F))


def ok(conn, perm):
    
    this, that = (c.value - 1 for c in conn)
    return abs(perm[this] - perm[that]) != 1


def solve():
    return [perm for perm in permutations(range(1, 9))
            if all(ok(conn, perm) for conn in connections)]


if __name__ == '__main__':
    solutions = solve()
    print("A, B, C, D, E, F, G, H =", ', '.join(str(i) for i in solutions[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;