WeixiangYan/CodeTransOcean huggingface dataset:
Task: Amb

C: typedef const char * amb_t;

amb_t amb(size_t argc, ...)
{
  amb_t *choices;
  va_list ap;
  int i;
  
  if(argc) {
    choices = malloc(argc*sizeof(amb_t));
    va_start(ap, argc);
    i = 0;
    do { choices[i] = va_arg(ap, amb_t); } while(++i < argc);
    va_end(ap);
    
    i = 0;
    do { TRY(choices[i]); } while(++i < argc);
    free(choices);
  }
  
  FAIL;
}

int joins(const char *left, const char *right) { return left[strlen(left)-1] == right[0]; }

int _main() {
  const char *w1,*w2,*w3,*w4;
  
  w1 = amb(3, "the", "that", "a");
  w2 = amb(3, "frog", "elephant", "thing");
  w3 = amb(3, "walked", "treaded", "grows");
  w4 = amb(2, "slowly", "quickly");
  
  if(!joins(w1, w2)) amb(0);
  if(!joins(w2, w3)) amb(0);
  if(!joins(w3, w4)) amb(0);
  
  printf("%s %s %s %s\n", w1, w2, w3, w4);
  
  return EXIT_SUCCESS;
}











Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_Amb is
   type Alternatives is array (Positive range <>) of Unbounded_String;

   type Amb (Count : Positive) is record
      This : Positive := 1;
      Left : access Amb; 
      List : Alternatives (1..Count);
   end record;
   
   function Image (L : Amb) return String is
   begin
      return To_String (L.List (L.This));
   end Image;

   function "/" (L, R : String) return Amb is
      Result : Amb (2);
   begin
      Append (Result.List (1), L);
      Append (Result.List (2), R);
      return Result;
   end "/";
   
   function "/" (L : Amb; R : String) return Amb is
      Result : Amb (L.Count + 1);
   begin
      Result.List (1..L.Count) := L.List ;
      Append (Result.List (Result.Count), R);
      return Result;
   end "/";

   function "=" (L, R : Amb) return Boolean is
      Left : Unbounded_String renames L.List (L.This);
   begin
      return Element (Left, Length (Left)) = Element (R.List (R.This), 1);
   end "=";
   
   procedure Failure (L : in out Amb) is
   begin
      loop
         if L.This < L.Count then
            L.This := L.This + 1;
         else
            L.This := 1;
            Failure (L.Left.all);
         end if;
         exit when L.Left = null or else L.Left.all = L;
      end loop;
   end Failure;

   procedure Join (L : access Amb; R : in out Amb) is
   begin
      R.Left := L;
      while L.all /= R loop
         Failure (R);
      end loop;
   end Join;

   W_1 : aliased Amb := "the" / "that" / "a";
   W_2 : aliased Amb := "frog" / "elephant" / "thing";
   W_3 : aliased Amb := "walked" / "treaded" / "grows";
   W_4 : aliased Amb := "slowly" / "quickly";
begin
   Join (W_1'Access, W_2);
   Join (W_2'Access, W_3);
   Join (W_3'Access, W_4);
   Put_Line (Image (W_1) & ' ' & Image (W_2) & ' ' & Image (W_3) & ' ' & Image (W_4));
end Test_Amb;
Task: Amb




Go: package main

import (
    "fmt"
    "sync"
)

func ambStrings(ss []string) chan []string {
    c := make(chan []string)
    go func() {
        for _, s := range ss {
            c <- []string{s}
        }
        close(c)
    }()
    return c
}

func ambChain(ss []string, cIn chan []string) chan []string {
    cOut := make(chan []string)
    go func() {
        var w sync.WaitGroup
        for chain := range cIn {
            w.Add(1)
            go func(chain []string) {
                for s1 := range ambStrings(ss) {
                    if s1[0][len(s1[0])-1] == chain[0][0] {
                        cOut <- append(s1, chain...)
                    }
                }
                w.Done()
            }(chain)
        }
        w.Wait()
        close(cOut)
    }()
    return cOut
}

func main() {
    s1 := []string{"the", "that", "a"}
    s2 := []string{"frog", "elephant", "thing"}
    s3 := []string{"walked", "treaded", "grows"}
    s4 := []string{"slowly", "quickly"}
    c := ambChain(s1, ambChain(s2, ambChain(s3, ambStrings(s4))))
    for s := range c {
        fmt.Println(s)
    }
}








Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_Amb is
   type Alternatives is array (Positive range <>) of Unbounded_String;

   type Amb (Count : Positive) is record
      This : Positive := 1;
      Left : access Amb; 
      List : Alternatives (1..Count);
   end record;
   
   function Image (L : Amb) return String is
   begin
      return To_String (L.List (L.This));
   end Image;

   function "/" (L, R : String) return Amb is
      Result : Amb (2);
   begin
      Append (Result.List (1), L);
      Append (Result.List (2), R);
      return Result;
   end "/";
   
   function "/" (L : Amb; R : String) return Amb is
      Result : Amb (L.Count + 1);
   begin
      Result.List (1..L.Count) := L.List ;
      Append (Result.List (Result.Count), R);
      return Result;
   end "/";

   function "=" (L, R : Amb) return Boolean is
      Left : Unbounded_String renames L.List (L.This);
   begin
      return Element (Left, Length (Left)) = Element (R.List (R.This), 1);
   end "=";
   
   procedure Failure (L : in out Amb) is
   begin
      loop
         if L.This < L.Count then
            L.This := L.This + 1;
         else
            L.This := 1;
            Failure (L.Left.all);
         end if;
         exit when L.Left = null or else L.Left.all = L;
      end loop;
   end Failure;

   procedure Join (L : access Amb; R : in out Amb) is
   begin
      R.Left := L;
      while L.all /= R loop
         Failure (R);
      end loop;
   end Join;

   W_1 : aliased Amb := "the" / "that" / "a";
   W_2 : aliased Amb := "frog" / "elephant" / "thing";
   W_3 : aliased Amb := "walked" / "treaded" / "grows";
   W_4 : aliased Amb := "slowly" / "quickly";
begin
   Join (W_1'Access, W_2);
   Join (W_2'Access, W_3);
   Join (W_3'Access, W_4);
   Put_Line (Image (W_1) & ' ' & Image (W_2) & ' ' & Image (W_3) & ' ' & Image (W_4));
end Test_Amb;
Task: Amb








VB: class ambiguous
	dim sRule

	public property let rule( x )
		sRule = x
	end property
	
	public default function amb(p1, p2)
		amb = eval(sRule)
	end function
end class




Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_Amb is
   type Alternatives is array (Positive range <>) of Unbounded_String;

   type Amb (Count : Positive) is record
      This : Positive := 1;
      Left : access Amb; 
      List : Alternatives (1..Count);
   end record;
   
   function Image (L : Amb) return String is
   begin
      return To_String (L.List (L.This));
   end Image;

   function "/" (L, R : String) return Amb is
      Result : Amb (2);
   begin
      Append (Result.List (1), L);
      Append (Result.List (2), R);
      return Result;
   end "/";
   
   function "/" (L : Amb; R : String) return Amb is
      Result : Amb (L.Count + 1);
   begin
      Result.List (1..L.Count) := L.List ;
      Append (Result.List (Result.Count), R);
      return Result;
   end "/";

   function "=" (L, R : Amb) return Boolean is
      Left : Unbounded_String renames L.List (L.This);
   begin
      return Element (Left, Length (Left)) = Element (R.List (R.This), 1);
   end "=";
   
   procedure Failure (L : in out Amb) is
   begin
      loop
         if L.This < L.Count then
            L.This := L.This + 1;
         else
            L.This := 1;
            Failure (L.Left.all);
         end if;
         exit when L.Left = null or else L.Left.all = L;
      end loop;
   end Failure;

   procedure Join (L : access Amb; R : in out Amb) is
   begin
      R.Left := L;
      while L.all /= R loop
         Failure (R);
      end loop;
   end Join;

   W_1 : aliased Amb := "the" / "that" / "a";
   W_2 : aliased Amb := "frog" / "elephant" / "thing";
   W_3 : aliased Amb := "walked" / "treaded" / "grows";
   W_4 : aliased Amb := "slowly" / "quickly";
begin
   Join (W_1'Access, W_2);
   Join (W_2'Access, W_3);
   Join (W_3'Access, W_4);
   Put_Line (Image (W_1) & ' ' & Image (W_2) & ' ' & Image (W_3) & ' ' & Image (W_4));
end Test_Amb;
Task: Amb

C: typedef const char * amb_t;

amb_t amb(size_t argc, ...)
{
  amb_t *choices;
  va_list ap;
  int i;
  
  if(argc) {
    choices = malloc(argc*sizeof(amb_t));
    va_start(ap, argc);
    i = 0;
    do { choices[i] = va_arg(ap, amb_t); } while(++i < argc);
    va_end(ap);
    
    i = 0;
    do { TRY(choices[i]); } while(++i < argc);
    free(choices);
  }
  
  FAIL;
}

int joins(const char *left, const char *right) { return left[strlen(left)-1] == right[0]; }

int _main() {
  const char *w1,*w2,*w3,*w4;
  
  w1 = amb(3, "the", "that", "a");
  w2 = amb(3, "frog", "elephant", "thing");
  w3 = amb(3, "walked", "treaded", "grows");
  w4 = amb(2, "slowly", "quickly");
  
  if(!joins(w1, w2)) amb(0);
  if(!joins(w2, w3)) amb(0);
  if(!joins(w3, w4)) amb(0);
  
  printf("%s %s %s %s\n", w1, w2, w3, w4);
  
  return EXIT_SUCCESS;
}
Task: Amb


C++: #include <iostream>
#include <string_view>
#include <boost/hana.hpp>
#include <boost/hana/experimental/printable.hpp>

using namespace std;
namespace hana = boost::hana;



constexpr auto Amb(auto constraint, auto&& ...params)
{
  
  auto possibleSolutions = hana::cartesian_product(hana::tuple(params...));

  
  auto foldOperation = [constraint](auto a, auto b)
  {
    bool meetsConstraint = constraint(a);
    return meetsConstraint ? a : b;
  };

  return hana::fold_right(possibleSolutions, foldOperation);
}

void AlgebraExample()
{
  
  constexpr hana::tuple x{1, 2, 3};
  constexpr hana::tuple y{7, 6, 4, 5};

  
  constexpr auto constraint = [](auto t)
  {
    return t[hana::size_c<0>] * t[hana::size_c<1>] == 8;
  };

  
  auto result = Amb(constraint, x, y);

  cout << "\nx = " << hana::experimental::print(x);
  cout << "\ny = " << hana::experimental::print(y);
  cout << "\nx * y == 8: " << hana::experimental::print(result);
}

void StringExample()
{
  
  constexpr hana::tuple words1 {"the"sv, "that"sv, "a"sv};
  constexpr hana::tuple words2 {"frog"sv, "elephant"sv, "thing"sv};
  constexpr hana::tuple words3 {"walked"sv, "treaded"sv, "grows"sv};
  constexpr hana::tuple words4 {"slowly"sv, "quickly"sv};

  
  
  constexpr auto constraint = [](const auto t)
  {
    auto adjacent = hana::zip(hana::drop_back(t), hana::drop_front(t));
    return hana::all_of(adjacent, [](auto t)
    {
      return t[hana::size_c<0>].back() == t[hana::size_c<1>].front();
    });
  };


  
  auto wordResult = Amb(constraint, words1, words2, words3, words4);

  cout << "\n\nWords 1: " << hana::experimental::print(words1);
  cout << "\nWords 2: " << hana::experimental::print(words2);
  cout << "\nWords 3: " << hana::experimental::print(words3);
  cout << "\nWords 4: " << hana::experimental::print(words4);
  cout << "\nSolution: " << hana::experimental::print(wordResult) << "\n";
}

int main()
{
  AlgebraExample();
  StringExample();
}
Task: Amb







Python: import itertools as _itertools
 
class Amb(object):
    def __init__(self):
        self._names2values   = {}       
        self._func           = None     
        self._valueiterator  = None     
        self._funcargnames   = None     
 
    def __call__(self, arg=None):
        if hasattr(arg, '__code__'):                
            
            
            
            globls = arg.__globals__ if hasattr(arg, '__globals__') else arg.func_globals
            
            argv = arg.__code__.co_varnames[:arg.__code__.co_argcount]
            for name in argv:
                if name not in self._names2values:
                    assert name in globls, \
                           "Global name %s not found in function globals" % name
                    self._names2values[name] = globls[name]
            
            valuesets = [self._names2values[name] for name in argv]
            self._valueiterator = _itertools.product(*valuesets)
            self._func = arg
            self._funcargnames = argv
            return self
        elif arg is not None:
            
            
            
            arg = frozenset(arg)
            return arg
        else:
            
            
            
            return self._nextinsearch()
 
    def _nextinsearch(self):
        arg = self._func
        globls = arg.__globals__
        argv = self._funcargnames
        found = False
        for values in self._valueiterator:
            if arg(*values):
                
                found = True
                for n, v in zip(argv, values):
                    globls[n] = v
                break
        if not found: raise StopIteration
        return values
 
    def __iter__(self):
        return self
 
    def __next__(self):
        return self()
    next = __next__ 
 
if __name__ == '__main__':
    if True:
        amb = Amb()
 
        print("\nSmall Pythagorean triples problem:")
        x = amb(range(1,11))
        y = amb(range(1,11))
        z = amb(range(1,11))
 
        for _dummy in amb( lambda x, y, z: x*x + y*y == z*z ):
            print ('%s %s %s' % (x, y, z))
 
 
    if True:
        amb = Amb()
 
        print("\nRosetta Code Amb problem:")
        w1 = amb(["the", "that", "a"])
        w2 = amb(["frog", "elephant", "thing"])
        w3 = amb(["walked", "treaded", "grows"])
        w4 = amb(["slowly", "quickly"])
 
        for _dummy in amb( lambda w1, w2, w3, w4: \
                             w1[-1] == w2[0] and \
                             w2[-1] == w3[0] and \
                             w3[-1] == w4[0] ):
            print ('%s %s %s %s' % (w1, w2, w3, w4))
 
    if True:
        amb = Amb()
 
        print("\nAmb problem from "
            "http://www.randomhacks.net/articles/2005/10/11/amb-operator:")
        x = amb([1, 2, 3])
        y = amb([4, 5, 6])
 
        for _dummy in amb( lambda x, y: x * y != 8 ):
            print ('%s %s' % (x, y))
Task: Amb








VB: class ambiguous
	dim sRule

	public property let rule( x )
		sRule = x
	end property
	
	public default function amb(p1, p2)
		amb = eval(sRule)
	end function
end class
Task: Amb




Go: package main

import (
    "fmt"
    "sync"
)

func ambStrings(ss []string) chan []string {
    c := make(chan []string)
    go func() {
        for _, s := range ss {
            c <- []string{s}
        }
        close(c)
    }()
    return c
}

func ambChain(ss []string, cIn chan []string) chan []string {
    cOut := make(chan []string)
    go func() {
        var w sync.WaitGroup
        for chain := range cIn {
            w.Add(1)
            go func(chain []string) {
                for s1 := range ambStrings(ss) {
                    if s1[0][len(s1[0])-1] == chain[0][0] {
                        cOut <- append(s1, chain...)
                    }
                }
                w.Done()
            }(chain)
        }
        w.Wait()
        close(cOut)
    }()
    return cOut
}

func main() {
    s1 := []string{"the", "that", "a"}
    s2 := []string{"frog", "elephant", "thing"}
    s3 := []string{"walked", "treaded", "grows"}
    s4 := []string{"slowly", "quickly"}
    c := ambChain(s1, ambChain(s2, ambChain(s3, ambStrings(s4))))
    for s := range c {
        fmt.Println(s)
    }
}
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared



C#: using System; using BI = System.Numerics.BigInteger;
class Program { static void Main(string[] args) {
    for (BI x = 3; BI.Log10(x) < 22; x = (x - 2) * 10 + 3)
      Console.WriteLine("{1,43} {0,-20}", x, x * x); } }









Ada: with Ada.Text_Io;
with Ada.Numerics.Big_Numbers.Big_Integers;

procedure Ones_Plus_Three is
   use Ada.Numerics.Big_Numbers.Big_Integers;
   use Ada.Text_Io;

   Root    : Big_Natural := 3;
   Squared : Big_Natural;
begin
   for N in 0 .. 8 loop
      Squared := Root**2;

      Put (To_String (Root, Width => 12));
      Put ("  ");
      Put (To_String (Squared, Width => 20));
      New_Line;

      Root := @ + 10**(N + 1);
   end loop;
end Ones_Plus_Three;
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared

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

uint64_t ones_plus_three(uint64_t ones) {
    uint64_t r = 0;
    while (ones--) r = r*10 + 1;
    return r*10 + 3;
}

int main() {
    uint64_t n;
    for (n=0; n<8; n++) {
        uint64_t x = ones_plus_three(n);
        printf("%8lu^2 = %15lu\n", x, x*x);
    }
    return 0;
}











Ada: with Ada.Text_Io;
with Ada.Numerics.Big_Numbers.Big_Integers;

procedure Ones_Plus_Three is
   use Ada.Numerics.Big_Numbers.Big_Integers;
   use Ada.Text_Io;

   Root    : Big_Natural := 3;
   Squared : Big_Natural;
begin
   for N in 0 .. 8 loop
      Squared := Root**2;

      Put (To_String (Root, Width => 12));
      Put ("  ");
      Put (To_String (Squared, Width => 20));
      New_Line;

      Root := @ + 10**(N + 1);
   end loop;
end Ones_Plus_Three;
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared




Go: package main

import (
    "fmt"
    "strconv"
    "strings"
)

func a(n int) {
    s, _ := strconv.Atoi(strings.Repeat("1", n) + "3")
    t := s * s
    fmt.Printf("%d %d\n", s, t)
}

func main() {
    for n := 0; n <= 7; n++ {
        a(n)
    }
}








Ada: with Ada.Text_Io;
with Ada.Numerics.Big_Numbers.Big_Integers;

procedure Ones_Plus_Three is
   use Ada.Numerics.Big_Numbers.Big_Integers;
   use Ada.Text_Io;

   Root    : Big_Natural := 3;
   Squared : Big_Natural;
begin
   for N in 0 .. 8 loop
      Squared := Root**2;

      Put (To_String (Root, Width => 12));
      Put ("  ");
      Put (To_String (Squared, Width => 20));
      New_Line;

      Root := @ + 10**(N + 1);
   end loop;
end Ones_Plus_Three;
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared







Python: [print("( " + "1"*i + "3 ) ^ 2 = " + str(int("1"*i + "3")**2)) for i in range(0,8)]





Ada: with Ada.Text_Io;
with Ada.Numerics.Big_Numbers.Big_Integers;

procedure Ones_Plus_Three is
   use Ada.Numerics.Big_Numbers.Big_Integers;
   use Ada.Text_Io;

   Root    : Big_Natural := 3;
   Squared : Big_Natural;
begin
   for N in 0 .. 8 loop
      Squared := Root**2;

      Put (To_String (Root, Width => 12));
      Put ("  ");
      Put (To_String (Squared, Width => 20));
      New_Line;

      Root := @ + 10**(N + 1);
   end loop;
end Ones_Plus_Three;
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared

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

uint64_t ones_plus_three(uint64_t ones) {
    uint64_t r = 0;
    while (ones--) r = r*10 + 1;
    return r*10 + 3;
}

int main() {
    uint64_t n;
    for (n=0; n<8; n++) {
        uint64_t x = ones_plus_three(n);
        printf("%8lu^2 = %15lu\n", x, x*x);
    }
    return 0;
}
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared



C#: using System; using BI = System.Numerics.BigInteger;
class Program { static void Main(string[] args) {
    for (BI x = 3; BI.Log10(x) < 22; x = (x - 2) * 10 + 3)
      Console.WriteLine("{1,43} {0,-20}", x, x * x); } }
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared







Python: [print("( " + "1"*i + "3 ) ^ 2 = " + str(int("1"*i + "3")**2)) for i in range(0,8)]
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared




Go: package main

import (
    "fmt"
    "strconv"
    "strings"
)

func a(n int) {
    s, _ := strconv.Atoi(strings.Repeat("1", n) + "3")
    t := s * s
    fmt.Printf("%d %d\n", s, t)
}

func main() {
    for n := 0; n <= 7; n++ {
        a(n)
    }
}
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared

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

uint64_t ones_plus_three(uint64_t ones) {
    uint64_t r = 0;
    while (ones--) r = r*10 + 1;
    return r*10 + 3;
}

int main() {
    uint64_t n;
    for (n=0; n<8; n++) {
        uint64_t x = ones_plus_three(n);
        printf("%8lu^2 = %15lu\n", x, x*x);
    }
    return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ONES-THREE-SQUARED.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 N                  PIC 9.
          03 ONES-3             PIC 9(9).
          03 SQUARE             PIC 9(15).
       01 FMT.
          03 FMT-ONES-3         PIC Z(7)9.
          03 FILLER             PIC X(5) VALUE "^2 = ".
          03 FMT-SQUARE         PIC Z(14)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM N-ONES-3 VARYING N FROM 0 BY 1 UNTIL N IS EQUAL TO 8.
           STOP RUN.

       N-ONES-3.
           MOVE ZERO TO ONES-3.
           PERFORM ADD-ONE N TIMES.
           MULTIPLY 10 BY ONES-3.
           ADD 3 TO ONES-3.
           MULTIPLY ONES-3 BY ONES-3 GIVING SQUARE.
           MOVE ONES-3 TO FMT-ONES-3.
           MOVE SQUARE TO FMT-SQUARE.
           DISPLAY FMT.

       ADD-ONE.
           MULTIPLY 10 BY ONES-3.
           ADD 1 TO ONES-3.
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared



C#: using System; using BI = System.Numerics.BigInteger;
class Program { static void Main(string[] args) {
    for (BI x = 3; BI.Log10(x) < 22; x = (x - 2) * 10 + 3)
      Console.WriteLine("{1,43} {0,-20}", x, x * x); } }







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ONES-THREE-SQUARED.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 N                  PIC 9.
          03 ONES-3             PIC 9(9).
          03 SQUARE             PIC 9(15).
       01 FMT.
          03 FMT-ONES-3         PIC Z(7)9.
          03 FILLER             PIC X(5) VALUE "^2 = ".
          03 FMT-SQUARE         PIC Z(14)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM N-ONES-3 VARYING N FROM 0 BY 1 UNTIL N IS EQUAL TO 8.
           STOP RUN.

       N-ONES-3.
           MOVE ZERO TO ONES-3.
           PERFORM ADD-ONE N TIMES.
           MULTIPLY 10 BY ONES-3.
           ADD 3 TO ONES-3.
           MULTIPLY ONES-3 BY ONES-3 GIVING SQUARE.
           MOVE ONES-3 TO FMT-ONES-3.
           MOVE SQUARE TO FMT-SQUARE.
           DISPLAY FMT.

       ADD-ONE.
           MULTIPLY 10 BY ONES-3.
           ADD 1 TO ONES-3.
Task: Show the (decimal) value of a number of 1s appended with a 3, then squared







Python: [print("( " + "1"*i + "3 ) ^ 2 = " + str(int("1"*i + "3")**2)) for i in range(0,8)]



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ONES-THREE-SQUARED.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 N                  PIC 9.
          03 ONES-3             PIC 9(9).
          03 SQUARE             PIC 9(15).
       01 FMT.
          03 FMT-ONES-3         PIC Z(7)9.
          03 FILLER             PIC X(5) VALUE "^2 = ".
          03 FMT-SQUARE         PIC Z(14)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM N-ONES-3 VARYING N FROM 0 BY 1 UNTIL N IS EQUAL TO 8.
           STOP RUN.

       N-ONES-3.
           MOVE ZERO TO ONES-3.
           PERFORM ADD-ONE N TIMES.
           MULTIPLY 10 BY ONES-3.
           ADD 3 TO ONES-3.
           MULTIPLY ONES-3 BY ONES-3 GIVING SQUARE.
           MOVE ONES-3 TO FMT-ONES-3.
           MOVE SQUARE TO FMT-SQUARE.
           DISPLAY FMT.

       ADD-ONE.
           MULTIPLY 10 BY ONES-3.
           ADD 1 TO ONES-3.