WeixiangYan/CodeTransOcean huggingface dataset:
Task: Square but not cube



C#: using System;
using System.Collections.Generic;
using static System.Console;
using static System.Linq.Enumerable;

public static class SquareButNotCube
{
    public static void Main() {
        var squares = from i in Integers() select i * i;
        var cubes = from i in Integers() select i * i * i;

        foreach (var x in Merge().Take(33)) {
            WriteLine(x.isCube ? x.n + " (also cube)" : x.n + "");
        }
        
        IEnumerable<int> Integers() {
            for (int i = 1; ;i++) yield return i;
        }

        IEnumerable<(int n, bool isCube)> Merge() {
            using (var s = squares.GetEnumerator())
            using (var c = cubes.GetEnumerator()) {
                s.MoveNext();
                c.MoveNext();
                while (true) {
                    if (s.Current < c.Current) {
                        yield return (s.Current, false);
                        s.MoveNext();
                    } else if (s.Current == c.Current) {
                        yield return (s.Current, true);
                        s.MoveNext();
                        c.MoveNext();
                    } else {
                        c.MoveNext();
                    }
                }
            }
        }

    }
}









Ada: with Ada.Text_IO;

procedure Square_But_Not_Cube is

   function Is_Cube (N : in Positive) return Boolean is
      Cube : Positive;
   begin
      for I in Positive loop
         Cube := I**3;
         if Cube = N    then  return True;
         elsif Cube > N then  return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Cube;

   procedure Show (Limit : in Natural) is
      Count  : Natural := 0;
      Square : Natural;
      use Ada.Text_IO;
   begin
      for N in Positive loop
         Square := N**2;
         if not Is_Cube (Square) then
            Count := Count + 1;
            Put (Square'Image);
            exit when Count = Limit;
         end if;
      end loop;
      New_Line;
   end Show;

begin
   Show (Limit => 30);
end Square_But_Not_Cube;
Task: Square but not cube

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

int main() {
    int n = 1, count = 0, sq, cr;
    for ( ; count < 30; ++n) {
        sq = n * n;
        cr = (int)cbrt((double)sq);
        if (cr * cr * cr != sq) {
            count++;
            printf("%d\n", sq);
        }
        else {
            printf("%d is square and cube\n", sq);
        }
    }
    return 0;
}











Ada: with Ada.Text_IO;

procedure Square_But_Not_Cube is

   function Is_Cube (N : in Positive) return Boolean is
      Cube : Positive;
   begin
      for I in Positive loop
         Cube := I**3;
         if Cube = N    then  return True;
         elsif Cube > N then  return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Cube;

   procedure Show (Limit : in Natural) is
      Count  : Natural := 0;
      Square : Natural;
      use Ada.Text_IO;
   begin
      for N in Positive loop
         Square := N**2;
         if not Is_Cube (Square) then
            Count := Count + 1;
            Put (Square'Image);
            exit when Count = Limit;
         end if;
      end loop;
      New_Line;
   end Show;

begin
   Show (Limit => 30);
end Square_But_Not_Cube;
Task: Square but not cube


C++: #include <iostream>
#include <cmath>

int main() {
    int n = 1;
    int count = 0;
    int sq;
    int cr;

    for (; count < 30; ++n) {
        sq = n * n;
        cr = cbrt(sq);
        if (cr * cr * cr != sq) {
            count++;
            std::cout << sq << '\n';
        } else {
            std::cout << sq << " is square and cube\n";
        }
    }

    return 0;
}










Ada: with Ada.Text_IO;

procedure Square_But_Not_Cube is

   function Is_Cube (N : in Positive) return Boolean is
      Cube : Positive;
   begin
      for I in Positive loop
         Cube := I**3;
         if Cube = N    then  return True;
         elsif Cube > N then  return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Cube;

   procedure Show (Limit : in Natural) is
      Count  : Natural := 0;
      Square : Natural;
      use Ada.Text_IO;
   begin
      for N in Positive loop
         Square := N**2;
         if not Is_Cube (Square) then
            Count := Count + 1;
            Put (Square'Image);
            exit when Count = Limit;
         end if;
      end loop;
      New_Line;
   end Show;

begin
   Show (Limit => 30);
end Square_But_Not_Cube;
Task: Square but not cube




Go: package main

import (
    "fmt"
    "math"
)

func main() {
    for n, count := 1, 0; count < 30; n++ {
        sq := n * n
        cr := int(math.Cbrt(float64(sq)))
        if cr*cr*cr != sq {
            count++
            fmt.Println(sq)
        } else {
            fmt.Println(sq, "is square and cube")
        }
    }
}








Ada: with Ada.Text_IO;

procedure Square_But_Not_Cube is

   function Is_Cube (N : in Positive) return Boolean is
      Cube : Positive;
   begin
      for I in Positive loop
         Cube := I**3;
         if Cube = N    then  return True;
         elsif Cube > N then  return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Cube;

   procedure Show (Limit : in Natural) is
      Count  : Natural := 0;
      Square : Natural;
      use Ada.Text_IO;
   begin
      for N in Positive loop
         Square := N**2;
         if not Is_Cube (Square) then
            Count := Count + 1;
            Put (Square'Image);
            exit when Count = Limit;
         end if;
      end loop;
      New_Line;
   end Show;

begin
   Show (Limit => 30);
end Square_But_Not_Cube;
Task: Square but not cube





Java: public class SquaresCubes {
    public static boolean isPerfectCube(long n) {
        long c = (long)Math.cbrt((double)n);
        return ((c * c * c) == n);
    }
    
    public static void main(String... args) {
        long n = 1;
        int squareOnlyCount = 0;
        int squareCubeCount = 0;
        while ((squareOnlyCount < 30) || (squareCubeCount < 3)) {
            long sq = n * n;
            if (isPerfectCube(sq)) {
                squareCubeCount++;
                System.out.println("Square and cube: " + sq);
            }
            else {
                squareOnlyCount++;
                System.out.println("Square: " + sq);
            }
            n++;
        }
    }
}







Ada: with Ada.Text_IO;

procedure Square_But_Not_Cube is

   function Is_Cube (N : in Positive) return Boolean is
      Cube : Positive;
   begin
      for I in Positive loop
         Cube := I**3;
         if Cube = N    then  return True;
         elsif Cube > N then  return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Cube;

   procedure Show (Limit : in Natural) is
      Count  : Natural := 0;
      Square : Natural;
      use Ada.Text_IO;
   begin
      for N in Positive loop
         Square := N**2;
         if not Is_Cube (Square) then
            Count := Count + 1;
            Put (Square'Image);
            exit when Count = Limit;
         end if;
      end loop;
      New_Line;
   end Show;

begin
   Show (Limit => 30);
end Square_But_Not_Cube;
Task: Square but not cube







Python: 
def nonCubeSquares(n):
    upto = enumFromTo(1)
    ns = upto(n)
    setCubes = set(x ** 3 for x in ns)
    ms = upto(n + len(set(x * x for x in ns).intersection(
        setCubes
    )))
    return list(tuple([x * x, x in setCubes]) for x in ms)



def squareListing(xs):
    justifyIdx = justifyRight(len(str(1 + len(xs))))(' ')
    justifySqr = justifyRight(1 + len(str(xs[-1][0])))(' ')
    return list(
        '(' + str(1 + idx) + '^2 = ' + str(n) +
        ' = ' + str(round(n ** (1 / 3))) + '^3)' if bln else (
            justifyIdx(1 + idx) + ' ->' +
            justifySqr(n)
        )
        for idx, (n, bln) in enumerate(xs)
    )


def main():
    print(
        unlines(
            squareListing(
                nonCubeSquares(30)
            )
        )
    )





def enumFromTo(m):
    return lambda n: list(range(m, 1 + n))



def justifyRight(n):
    return lambda cFiller: lambda a: (
        ((n * cFiller) + str(a))[-n:]
    )



def unlines(xs):
    return '\n'.join(xs)


main()





Ada: with Ada.Text_IO;

procedure Square_But_Not_Cube is

   function Is_Cube (N : in Positive) return Boolean is
      Cube : Positive;
   begin
      for I in Positive loop
         Cube := I**3;
         if Cube = N    then  return True;
         elsif Cube > N then  return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Cube;

   procedure Show (Limit : in Natural) is
      Count  : Natural := 0;
      Square : Natural;
      use Ada.Text_IO;
   begin
      for N in Positive loop
         Square := N**2;
         if not Is_Cube (Square) then
            Count := Count + 1;
            Put (Square'Image);
            exit when Count = Limit;
         end if;
      end loop;
      New_Line;
   end Show;

begin
   Show (Limit => 30);
end Square_But_Not_Cube;
Task: Square but not cube








VB: Module Module1

  
  
  
  

  
  Function ChkFlg(flag As Integer, ByRef mask As Integer) As Boolean
    ChkFlg = (flag And mask) = mask : mask <<= 1
  End Function

  Sub SwoC(limit As Integer)
    Dim count, square, delta, cube, d1, d2, flag, mask As Integer, s as string = ""
    count = 1 : square = 1 : delta = 1 : cube = 1 : d1 = 1 : d2 = 0
    While count <= limit
      flag = {5, 7, 2}(1 + square.CompareTo(cube))
      If flag = 7 Then s = String. Format("   {0} (also cube)", square)
      If flag = 5 Then s = String.Format("{0,-2} {1}", count, square) : count += 1
      mask = 1 : If ChkFlg(flag, mask) Then delta += 2 : square += delta
      If ChkFlg(flag, mask) Then d2 += 6 : d1 += d2 : cube += d1
      If ChkFlg(flag, mask) Then Console.WriteLine(s)
    End While
  End Sub

  Sub Main()
    SwoC(30)
  End Sub

End Module




Ada: with Ada.Text_IO;

procedure Square_But_Not_Cube is

   function Is_Cube (N : in Positive) return Boolean is
      Cube : Positive;
   begin
      for I in Positive loop
         Cube := I**3;
         if Cube = N    then  return True;
         elsif Cube > N then  return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Cube;

   procedure Show (Limit : in Natural) is
      Count  : Natural := 0;
      Square : Natural;
      use Ada.Text_IO;
   begin
      for N in Positive loop
         Square := N**2;
         if not Is_Cube (Square) then
            Count := Count + 1;
            Put (Square'Image);
            exit when Count = Limit;
         end if;
      end loop;
      New_Line;
   end Show;

begin
   Show (Limit => 30);
end Square_But_Not_Cube;
Task: Square but not cube

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

int main() {
    int n = 1, count = 0, sq, cr;
    for ( ; count < 30; ++n) {
        sq = n * n;
        cr = (int)cbrt((double)sq);
        if (cr * cr * cr != sq) {
            count++;
            printf("%d\n", sq);
        }
        else {
            printf("%d is square and cube\n", sq);
        }
    }
    return 0;
}
Task: Square but not cube



C#: using System;
using System.Collections.Generic;
using static System.Console;
using static System.Linq.Enumerable;

public static class SquareButNotCube
{
    public static void Main() {
        var squares = from i in Integers() select i * i;
        var cubes = from i in Integers() select i * i * i;

        foreach (var x in Merge().Take(33)) {
            WriteLine(x.isCube ? x.n + " (also cube)" : x.n + "");
        }
        
        IEnumerable<int> Integers() {
            for (int i = 1; ;i++) yield return i;
        }

        IEnumerable<(int n, bool isCube)> Merge() {
            using (var s = squares.GetEnumerator())
            using (var c = cubes.GetEnumerator()) {
                s.MoveNext();
                c.MoveNext();
                while (true) {
                    if (s.Current < c.Current) {
                        yield return (s.Current, false);
                        s.MoveNext();
                    } else if (s.Current == c.Current) {
                        yield return (s.Current, true);
                        s.MoveNext();
                        c.MoveNext();
                    } else {
                        c.MoveNext();
                    }
                }
            }
        }

    }
}
Task: Square but not cube


C++: #include <iostream>
#include <cmath>

int main() {
    int n = 1;
    int count = 0;
    int sq;
    int cr;

    for (; count < 30; ++n) {
        sq = n * n;
        cr = cbrt(sq);
        if (cr * cr * cr != sq) {
            count++;
            std::cout << sq << '\n';
        } else {
            std::cout << sq << " is square and cube\n";
        }
    }

    return 0;
}
Task: Square but not cube





Java: public class SquaresCubes {
    public static boolean isPerfectCube(long n) {
        long c = (long)Math.cbrt((double)n);
        return ((c * c * c) == n);
    }
    
    public static void main(String... args) {
        long n = 1;
        int squareOnlyCount = 0;
        int squareCubeCount = 0;
        while ((squareOnlyCount < 30) || (squareCubeCount < 3)) {
            long sq = n * n;
            if (isPerfectCube(sq)) {
                squareCubeCount++;
                System.out.println("Square and cube: " + sq);
            }
            else {
                squareOnlyCount++;
                System.out.println("Square: " + sq);
            }
            n++;
        }
    }
}
Task: Square but not cube







Python: 
def nonCubeSquares(n):
    upto = enumFromTo(1)
    ns = upto(n)
    setCubes = set(x ** 3 for x in ns)
    ms = upto(n + len(set(x * x for x in ns).intersection(
        setCubes
    )))
    return list(tuple([x * x, x in setCubes]) for x in ms)



def squareListing(xs):
    justifyIdx = justifyRight(len(str(1 + len(xs))))(' ')
    justifySqr = justifyRight(1 + len(str(xs[-1][0])))(' ')
    return list(
        '(' + str(1 + idx) + '^2 = ' + str(n) +
        ' = ' + str(round(n ** (1 / 3))) + '^3)' if bln else (
            justifyIdx(1 + idx) + ' ->' +
            justifySqr(n)
        )
        for idx, (n, bln) in enumerate(xs)
    )


def main():
    print(
        unlines(
            squareListing(
                nonCubeSquares(30)
            )
        )
    )





def enumFromTo(m):
    return lambda n: list(range(m, 1 + n))



def justifyRight(n):
    return lambda cFiller: lambda a: (
        ((n * cFiller) + str(a))[-n:]
    )



def unlines(xs):
    return '\n'.join(xs)


main()
Task: Square but not cube








VB: Module Module1

  
  
  
  

  
  Function ChkFlg(flag As Integer, ByRef mask As Integer) As Boolean
    ChkFlg = (flag And mask) = mask : mask <<= 1
  End Function

  Sub SwoC(limit As Integer)
    Dim count, square, delta, cube, d1, d2, flag, mask As Integer, s as string = ""
    count = 1 : square = 1 : delta = 1 : cube = 1 : d1 = 1 : d2 = 0
    While count <= limit
      flag = {5, 7, 2}(1 + square.CompareTo(cube))
      If flag = 7 Then s = String. Format("   {0} (also cube)", square)
      If flag = 5 Then s = String.Format("{0,-2} {1}", count, square) : count += 1
      mask = 1 : If ChkFlg(flag, mask) Then delta += 2 : square += delta
      If ChkFlg(flag, mask) Then d2 += 6 : d1 += d2 : cube += d1
      If ChkFlg(flag, mask) Then Console.WriteLine(s)
    End While
  End Sub

  Sub Main()
    SwoC(30)
  End Sub

End Module
Task: Square but not cube




Go: package main

import (
    "fmt"
    "math"
)

func main() {
    for n, count := 1, 0; count < 30; n++ {
        sq := n * n
        cr := int(math.Cbrt(float64(sq)))
        if cr*cr*cr != sq {
            count++
            fmt.Println(sq)
        } else {
            fmt.Println(sq, "is square and cube")
        }
    }
}
Task: Square but not cube

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

int main() {
    int n = 1, count = 0, sq, cr;
    for ( ; count < 30; ++n) {
        sq = n * n;
        cr = (int)cbrt((double)sq);
        if (cr * cr * cr != sq) {
            count++;
            printf("%d\n", sq);
        }
        else {
            printf("%d is square and cube\n", sq);
        }
    }
    return 0;
}









COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. SQUARE-NOT-CUBE.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
           02 SQ-ROOT       PIC 9999 COMP VALUE 1.
           02 CUBE-ROOT     PIC 9999 COMP VALUE 1.
           02 SQUARE        PIC 9999 COMP VALUE 1.
           02 CUBE          PIC 9999 COMP VALUE 1.
           02 SEEN          PIC 99   COMP VALUE 0.
        01 OUTPUT-FORMAT.
           02 OUT-NUM       PIC ZZZ9.
        
        PROCEDURE DIVISION.
        SQUARE-STEP.
            COMPUTE SQUARE = SQ-ROOT ** 2.
        CUBE-STEP.
            IF SQUARE IS GREATER THAN CUBE
                ADD 1 TO CUBE-ROOT
                COMPUTE CUBE = CUBE-ROOT ** 3
                GO TO CUBE-STEP.
            IF SQUARE IS NOT EQUAL TO CUBE
                ADD 1 TO SEEN
                MOVE SQUARE TO OUT-NUM
                DISPLAY OUT-NUM.
            ADD 1 TO SQ-ROOT.
            IF SEEN IS LESS THAN 30 GO TO SQUARE-STEP.
            STOP RUN.
Task: Square but not cube



C#: using System;
using System.Collections.Generic;
using static System.Console;
using static System.Linq.Enumerable;

public static class SquareButNotCube
{
    public static void Main() {
        var squares = from i in Integers() select i * i;
        var cubes = from i in Integers() select i * i * i;

        foreach (var x in Merge().Take(33)) {
            WriteLine(x.isCube ? x.n + " (also cube)" : x.n + "");
        }
        
        IEnumerable<int> Integers() {
            for (int i = 1; ;i++) yield return i;
        }

        IEnumerable<(int n, bool isCube)> Merge() {
            using (var s = squares.GetEnumerator())
            using (var c = cubes.GetEnumerator()) {
                s.MoveNext();
                c.MoveNext();
                while (true) {
                    if (s.Current < c.Current) {
                        yield return (s.Current, false);
                        s.MoveNext();
                    } else if (s.Current == c.Current) {
                        yield return (s.Current, true);
                        s.MoveNext();
                        c.MoveNext();
                    } else {
                        c.MoveNext();
                    }
                }
            }
        }

    }
}







COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. SQUARE-NOT-CUBE.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
           02 SQ-ROOT       PIC 9999 COMP VALUE 1.
           02 CUBE-ROOT     PIC 9999 COMP VALUE 1.
           02 SQUARE        PIC 9999 COMP VALUE 1.
           02 CUBE          PIC 9999 COMP VALUE 1.
           02 SEEN          PIC 99   COMP VALUE 0.
        01 OUTPUT-FORMAT.
           02 OUT-NUM       PIC ZZZ9.
        
        PROCEDURE DIVISION.
        SQUARE-STEP.
            COMPUTE SQUARE = SQ-ROOT ** 2.
        CUBE-STEP.
            IF SQUARE IS GREATER THAN CUBE
                ADD 1 TO CUBE-ROOT
                COMPUTE CUBE = CUBE-ROOT ** 3
                GO TO CUBE-STEP.
            IF SQUARE IS NOT EQUAL TO CUBE
                ADD 1 TO SEEN
                MOVE SQUARE TO OUT-NUM
                DISPLAY OUT-NUM.
            ADD 1 TO SQ-ROOT.
            IF SEEN IS LESS THAN 30 GO TO SQUARE-STEP.
            STOP RUN.
Task: Square but not cube


C++: #include <iostream>
#include <cmath>

int main() {
    int n = 1;
    int count = 0;
    int sq;
    int cr;

    for (; count < 30; ++n) {
        sq = n * n;
        cr = cbrt(sq);
        if (cr * cr * cr != sq) {
            count++;
            std::cout << sq << '\n';
        } else {
            std::cout << sq << " is square and cube\n";
        }
    }

    return 0;
}








COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. SQUARE-NOT-CUBE.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
           02 SQ-ROOT       PIC 9999 COMP VALUE 1.
           02 CUBE-ROOT     PIC 9999 COMP VALUE 1.
           02 SQUARE        PIC 9999 COMP VALUE 1.
           02 CUBE          PIC 9999 COMP VALUE 1.
           02 SEEN          PIC 99   COMP VALUE 0.
        01 OUTPUT-FORMAT.
           02 OUT-NUM       PIC ZZZ9.
        
        PROCEDURE DIVISION.
        SQUARE-STEP.
            COMPUTE SQUARE = SQ-ROOT ** 2.
        CUBE-STEP.
            IF SQUARE IS GREATER THAN CUBE
                ADD 1 TO CUBE-ROOT
                COMPUTE CUBE = CUBE-ROOT ** 3
                GO TO CUBE-STEP.
            IF SQUARE IS NOT EQUAL TO CUBE
                ADD 1 TO SEEN
                MOVE SQUARE TO OUT-NUM
                DISPLAY OUT-NUM.
            ADD 1 TO SQ-ROOT.
            IF SEEN IS LESS THAN 30 GO TO SQUARE-STEP.
            STOP RUN.
Task: Square but not cube





Java: public class SquaresCubes {
    public static boolean isPerfectCube(long n) {
        long c = (long)Math.cbrt((double)n);
        return ((c * c * c) == n);
    }
    
    public static void main(String... args) {
        long n = 1;
        int squareOnlyCount = 0;
        int squareCubeCount = 0;
        while ((squareOnlyCount < 30) || (squareCubeCount < 3)) {
            long sq = n * n;
            if (isPerfectCube(sq)) {
                squareCubeCount++;
                System.out.println("Square and cube: " + sq);
            }
            else {
                squareOnlyCount++;
                System.out.println("Square: " + sq);
            }
            n++;
        }
    }
}





COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. SQUARE-NOT-CUBE.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
           02 SQ-ROOT       PIC 9999 COMP VALUE 1.
           02 CUBE-ROOT     PIC 9999 COMP VALUE 1.
           02 SQUARE        PIC 9999 COMP VALUE 1.
           02 CUBE          PIC 9999 COMP VALUE 1.
           02 SEEN          PIC 99   COMP VALUE 0.
        01 OUTPUT-FORMAT.
           02 OUT-NUM       PIC ZZZ9.
        
        PROCEDURE DIVISION.
        SQUARE-STEP.
            COMPUTE SQUARE = SQ-ROOT ** 2.
        CUBE-STEP.
            IF SQUARE IS GREATER THAN CUBE
                ADD 1 TO CUBE-ROOT
                COMPUTE CUBE = CUBE-ROOT ** 3
                GO TO CUBE-STEP.
            IF SQUARE IS NOT EQUAL TO CUBE
                ADD 1 TO SEEN
                MOVE SQUARE TO OUT-NUM
                DISPLAY OUT-NUM.
            ADD 1 TO SQ-ROOT.
            IF SEEN IS LESS THAN 30 GO TO SQUARE-STEP.
            STOP RUN.