WeixiangYan/CodeTransOcean huggingface dataset:
Task: Van Eck sequence








VB: Imports System.Linq
Module Module1
    Dim h() As Integer
    Sub sho(i As Integer)
        Console.WriteLine(String.Join(" ", h.Skip(i).Take(10)))
    End Sub
    Sub Main()
        Dim a, b, c, d, f, g As Integer : g = 1000
        h = new Integer(g){} : a = 0 : b = 1 : For c = 2 To g
            f = h(b) : For d = a To 0 Step -1
                If f = h(d) Then h(c) = b - d: Exit For
            Next : a = b : b = c : Next : sho(0) : sho(990)
    End Sub
End Module


COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. VAN-ECK.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
            02 ECK      PIC 999 OCCURS 1000 TIMES.
            02 I        PIC 9999.
            02 J        PIC 9999.
        01 OUTPUT-FORMAT.
            02 ITEM     PIC ZZ9.
            02 IDX      PIC ZZZ9.
        
        PROCEDURE DIVISION.
        B.  PERFORM GENERATE-ECK.
            PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
            PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
            STOP RUN.
        
        SHOW.
            MOVE I TO IDX.
            MOVE ECK(I) TO ITEM.
            DISPLAY 'ECK(' IDX ') = ' ITEM.
        
        GENERATE-ECK SECTION.
        B.  SET ECK(1) TO 0.
            SET I TO 1.
            PERFORM GENERATE-TERM 
                VARYING I FROM 2 BY 1 UNTIL I = 1001.
            
        GENERATE-TERM SECTION.
        B.  SUBTRACT 2 FROM I GIVING J.
        LOOP.
            IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
            IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
            SUBTRACT 1 FROM J.
            GO TO LOOP.
        
        TERM-IS-NEW.
            SET ECK(I) TO 0.
            GO TO DONE.
         
        TERM-IS-OLD.
            COMPUTE ECK(I) = (I - J) - 1.
            
        DONE. EXIT.
Task: Van Eck sequence




Go: package main

import "fmt"

func main() {
    const max = 1000
    a := make([]int, max) 
    for n := 0; n < max-1; n++ {
        for m := n - 1;  m >= 0; m-- {
            if a[m] == a[n] {
                a[n+1] = n - m
                break
            }    
        }
    }
    fmt.Println("The first ten terms of the Van Eck sequence are:")
    fmt.Println(a[:10])
    fmt.Println("\nTerms 991 to 1000 of the sequence are:")
    fmt.Println(a[990:])
}






COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. VAN-ECK.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
            02 ECK      PIC 999 OCCURS 1000 TIMES.
            02 I        PIC 9999.
            02 J        PIC 9999.
        01 OUTPUT-FORMAT.
            02 ITEM     PIC ZZ9.
            02 IDX      PIC ZZZ9.
        
        PROCEDURE DIVISION.
        B.  PERFORM GENERATE-ECK.
            PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
            PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
            STOP RUN.
        
        SHOW.
            MOVE I TO IDX.
            MOVE ECK(I) TO ITEM.
            DISPLAY 'ECK(' IDX ') = ' ITEM.
        
        GENERATE-ECK SECTION.
        B.  SET ECK(1) TO 0.
            SET I TO 1.
            PERFORM GENERATE-TERM 
                VARYING I FROM 2 BY 1 UNTIL I = 1001.
            
        GENERATE-TERM SECTION.
        B.  SUBTRACT 2 FROM I GIVING J.
        LOOP.
            IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
            IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
            SUBTRACT 1 FROM J.
            GO TO LOOP.
        
        TERM-IS-NEW.
            SET ECK(I) TO 0.
            GO TO DONE.
         
        TERM-IS-OLD.
            COMPUTE ECK(I) = (I - J) - 1.
            
        DONE. EXIT.
Task: Bitmap_Midpoint circle algorithm

C: void raster_circle(
        image img,
        unsigned int x0,
        unsigned int y0,
        unsigned int radius,
        color_component r,
        color_component g,
        color_component b );











Ada: procedure Circle
          (  Picture : in out Image;
             Center  : Point;
             Radius  : Natural;
             Color   : Pixel
          )  is
   F     : Integer := 1 - Radius;
   ddF_X : Integer := 0;
   ddF_Y : Integer := -2 * Radius;
   X     : Integer := 0;
   Y     : Integer := Radius;
begin 
   Picture (Center.X, Center.Y + Radius) := Color;
   Picture (Center.X, Center.Y - Radius) := Color;
   Picture (Center.X + Radius, Center.Y) := Color;
   Picture (Center.X - Radius, Center.Y) := Color; 
   while X < Y loop
      if F >= 0 then
         Y := Y - 1;
         ddF_Y := ddF_Y + 2;
         F := F + ddF_Y;
      end if;
      X := X + 1;
      ddF_X := ddF_X + 2;
      F := F + ddF_X + 1;    
      Picture (Center.X + X, Center.Y + Y) := Color;
      Picture (Center.X - X, Center.Y + Y) := Color;
      Picture (Center.X + X, Center.Y - Y) := Color;
      Picture (Center.X - X, Center.Y - Y) := Color;
      Picture (Center.X + Y, Center.Y + X) := Color;
      Picture (Center.X - Y, Center.Y + X) := Color;
      Picture (Center.X + Y, Center.Y - X) := Color;
      Picture (Center.X - Y, Center.Y - X) := Color;
   end loop;
end Circle;
Task: Bitmap_Midpoint circle algorithm




Go: package raster






func (b *Bitmap) Circle(x, y, r int, p Pixel) {
    if r < 0 {
        return
    }
    
    x1, y1, err := -r, 0, 2-2*r
    for {
        b.SetPx(x-x1, y+y1, p)
        b.SetPx(x-y1, y-x1, p)
        b.SetPx(x+x1, y-y1, p)
        b.SetPx(x+y1, y+x1, p)
        r = err
        if r > x1 {
            x1++
            err += x1*2 + 1
        }
        if r <= y1 {
            y1++
            err += y1*2 + 1
        }
        if x1 >= 0 {
            break
        }
    }
}

func (b *Bitmap) CircleRgb(x, y, r int, c Rgb) {
    b.Circle(x, y, r, c.Pixel())
}








Ada: procedure Circle
          (  Picture : in out Image;
             Center  : Point;
             Radius  : Natural;
             Color   : Pixel
          )  is
   F     : Integer := 1 - Radius;
   ddF_X : Integer := 0;
   ddF_Y : Integer := -2 * Radius;
   X     : Integer := 0;
   Y     : Integer := Radius;
begin 
   Picture (Center.X, Center.Y + Radius) := Color;
   Picture (Center.X, Center.Y - Radius) := Color;
   Picture (Center.X + Radius, Center.Y) := Color;
   Picture (Center.X - Radius, Center.Y) := Color; 
   while X < Y loop
      if F >= 0 then
         Y := Y - 1;
         ddF_Y := ddF_Y + 2;
         F := F + ddF_Y;
      end if;
      X := X + 1;
      ddF_X := ddF_X + 2;
      F := F + ddF_X + 1;    
      Picture (Center.X + X, Center.Y + Y) := Color;
      Picture (Center.X - X, Center.Y + Y) := Color;
      Picture (Center.X + X, Center.Y - Y) := Color;
      Picture (Center.X - X, Center.Y - Y) := Color;
      Picture (Center.X + Y, Center.Y + X) := Color;
      Picture (Center.X - Y, Center.Y + X) := Color;
      Picture (Center.X + Y, Center.Y - X) := Color;
      Picture (Center.X - Y, Center.Y - X) := Color;
   end loop;
end Circle;
Task: Bitmap_Midpoint circle algorithm





Java: import java.awt.Color;

public class MidPointCircle {
	private BasicBitmapStorage image;

	public MidPointCircle(final int imageWidth, final int imageHeight) {
		this.image = new BasicBitmapStorage(imageWidth, imageHeight);
	}

	private void drawCircle(final int centerX, final int centerY, final int radius) {
		int d = (5 - r * 4)/4;
		int x = 0;
		int y = radius;
		Color circleColor = Color.white;

		do {
			image.setPixel(centerX + x, centerY + y, circleColor);
			image.setPixel(centerX + x, centerY - y, circleColor);
			image.setPixel(centerX - x, centerY + y, circleColor);
			image.setPixel(centerX - x, centerY - y, circleColor);
			image.setPixel(centerX + y, centerY + x, circleColor);
			image.setPixel(centerX + y, centerY - x, circleColor);
			image.setPixel(centerX - y, centerY + x, circleColor);
			image.setPixel(centerX - y, centerY - x, circleColor);
			if (d < 0) {
				d += 2 * x + 1;
			} else {
				d += 2 * (x - y) + 1;
				y--;
			}
			x++;
		} while (x <= y);

	}
}







Ada: procedure Circle
          (  Picture : in out Image;
             Center  : Point;
             Radius  : Natural;
             Color   : Pixel
          )  is
   F     : Integer := 1 - Radius;
   ddF_X : Integer := 0;
   ddF_Y : Integer := -2 * Radius;
   X     : Integer := 0;
   Y     : Integer := Radius;
begin 
   Picture (Center.X, Center.Y + Radius) := Color;
   Picture (Center.X, Center.Y - Radius) := Color;
   Picture (Center.X + Radius, Center.Y) := Color;
   Picture (Center.X - Radius, Center.Y) := Color; 
   while X < Y loop
      if F >= 0 then
         Y := Y - 1;
         ddF_Y := ddF_Y + 2;
         F := F + ddF_Y;
      end if;
      X := X + 1;
      ddF_X := ddF_X + 2;
      F := F + ddF_X + 1;    
      Picture (Center.X + X, Center.Y + Y) := Color;
      Picture (Center.X - X, Center.Y + Y) := Color;
      Picture (Center.X + X, Center.Y - Y) := Color;
      Picture (Center.X - X, Center.Y - Y) := Color;
      Picture (Center.X + Y, Center.Y + X) := Color;
      Picture (Center.X - Y, Center.Y + X) := Color;
      Picture (Center.X + Y, Center.Y - X) := Color;
      Picture (Center.X - Y, Center.Y - X) := Color;
   end loop;
end Circle;
Task: Bitmap_Midpoint circle algorithm







Python: def circle(self, x0, y0, radius, colour=black):
    f = 1 - radius
    ddf_x = 1
    ddf_y = -2 * radius
    x = 0
    y = radius
    self.set(x0, y0 + radius, colour)
    self.set(x0, y0 - radius, colour)
    self.set(x0 + radius, y0, colour)
    self.set(x0 - radius, y0, colour)

    while x < y:
        if f >= 0: 
            y -= 1
            ddf_y += 2
            f += ddf_y
        x += 1
        ddf_x += 2
        f += ddf_x    
        self.set(x0 + x, y0 + y, colour)
        self.set(x0 - x, y0 + y, colour)
        self.set(x0 + x, y0 - y, colour)
        self.set(x0 - x, y0 - y, colour)
        self.set(x0 + y, y0 + x, colour)
        self.set(x0 - y, y0 + x, colour)
        self.set(x0 + y, y0 - x, colour)
        self.set(x0 - y, y0 - x, colour)
Bitmap.circle = circle

bitmap = Bitmap(25,25)
bitmap.circle(x0=12, y0=12, radius=12)
bitmap.chardisplay()







Ada: procedure Circle
          (  Picture : in out Image;
             Center  : Point;
             Radius  : Natural;
             Color   : Pixel
          )  is
   F     : Integer := 1 - Radius;
   ddF_X : Integer := 0;
   ddF_Y : Integer := -2 * Radius;
   X     : Integer := 0;
   Y     : Integer := Radius;
begin 
   Picture (Center.X, Center.Y + Radius) := Color;
   Picture (Center.X, Center.Y - Radius) := Color;
   Picture (Center.X + Radius, Center.Y) := Color;
   Picture (Center.X - Radius, Center.Y) := Color; 
   while X < Y loop
      if F >= 0 then
         Y := Y - 1;
         ddF_Y := ddF_Y + 2;
         F := F + ddF_Y;
      end if;
      X := X + 1;
      ddF_X := ddF_X + 2;
      F := F + ddF_X + 1;    
      Picture (Center.X + X, Center.Y + Y) := Color;
      Picture (Center.X - X, Center.Y + Y) := Color;
      Picture (Center.X + X, Center.Y - Y) := Color;
      Picture (Center.X - X, Center.Y - Y) := Color;
      Picture (Center.X + Y, Center.Y + X) := Color;
      Picture (Center.X - Y, Center.Y + X) := Color;
      Picture (Center.X + Y, Center.Y - X) := Color;
      Picture (Center.X - Y, Center.Y - X) := Color;
   end loop;
end Circle;
Task: Bitmap_Midpoint circle algorithm

C: void raster_circle(
        image img,
        unsigned int x0,
        unsigned int y0,
        unsigned int radius,
        color_component r,
        color_component g,
        color_component b );
Task: Bitmap_Midpoint circle algorithm



C#:         
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        public static void DrawCircle(this GenericImage image, int centerX, int centerY, int radius, Color color)
        {
            int d = (5 - radius * 4) / 4;
            int x = 0;
            int y = radius;

            do
            {
                
                
                if (centerX + x >= 0 && centerX + x <= image.Width - 1 && centerY + y >= 0 && centerY + y <= image.Height - 1) image[centerX + x, centerY + y] = color;
                if (centerX + x >= 0 && centerX + x <= image.Width - 1 && centerY - y >= 0 && centerY - y <= image.Height - 1) image[centerX + x, centerY - y] = color;
                if (centerX - x >= 0 && centerX - x <= image.Width - 1 && centerY + y >= 0 && centerY + y <= image.Height - 1) image[centerX - x, centerY + y] = color;
                if (centerX - x >= 0 && centerX - x <= image.Width - 1 && centerY - y >= 0 && centerY - y <= image.Height - 1) image[centerX - x, centerY - y] = color;
                if (centerX + y >= 0 && centerX + y <= image.Width - 1 && centerY + x >= 0 && centerY + x <= image.Height - 1) image[centerX + y, centerY + x] = color;
                if (centerX + y >= 0 && centerX + y <= image.Width - 1 && centerY - x >= 0 && centerY - x <= image.Height - 1) image[centerX + y, centerY - x] = color;
                if (centerX - y >= 0 && centerX - y <= image.Width - 1 && centerY + x >= 0 && centerY + x <= image.Height - 1) image[centerX - y, centerY + x] = color;
                if (centerX - y >= 0 && centerX - y <= image.Width - 1 && centerY - x >= 0 && centerY - x <= image.Height - 1) image[centerX - y, centerY - x] = color;
                if (d < 0)
                {
                    d += 2 * x + 1;
                }
                else
                {
                    d += 2 * (x - y) + 1;
                    y--;
                }
                x++;
            } while (x <= y);
        }
Task: Bitmap_Midpoint circle algorithm





Java: import java.awt.Color;

public class MidPointCircle {
	private BasicBitmapStorage image;

	public MidPointCircle(final int imageWidth, final int imageHeight) {
		this.image = new BasicBitmapStorage(imageWidth, imageHeight);
	}

	private void drawCircle(final int centerX, final int centerY, final int radius) {
		int d = (5 - radius * 4)/4;
		int x = 0;
		int y = radius;
		Color circleColor = Color.white;

		do {
			image.setPixel(centerX + x, centerY + y, circleColor);
			image.setPixel(centerX + x, centerY - y, circleColor);
			image.setPixel(centerX - x, centerY + y, circleColor);
			image.setPixel(centerX - x, centerY - y, circleColor);
			image.setPixel(centerX + y, centerY + x, circleColor);
			image.setPixel(centerX + y, centerY - x, circleColor);
			image.setPixel(centerX - y, centerY + x, circleColor);
			image.setPixel(centerX - y, centerY - x, circleColor);
			if (d < 0) {
				d += 2 * x + 1;
			} else {
				d += 2 * (x - y) + 1;
				y--;
			}
			x++;
		} while (x <= y);

	}
}
Task: Bitmap_Midpoint circle algorithm







Python: def circle(self, x0, y0, radius, colour=black):
    f = 1 - radius
    ddf_x = 1
    ddf_y = -2 * radius
    x = 0
    y = radius
    self.set(x0, y0 + radius, colour)
    self.set(x0, y0 - radius, colour)
    self.set(x0 + radius, y0, colour)
    self.set(x0 - radius, y0, colour)

    while x < y:
        if f >= 0: 
            y -= 1
            ddf_y += 2
            f += ddf_y
        x += 1
        ddf_x += 2
        f += ddf_x    
        self.set(x0 + x, y0 + y, colour)
        self.set(x0 - x, y0 + y, colour)
        self.set(x0 + x, y0 - y, colour)
        self.set(x0 - x, y0 - y, colour)
        self.set(x0 + y, y0 + x, colour)
        self.set(x0 - y, y0 + x, colour)
        self.set(x0 + y, y0 - x, colour)
        self.set(x0 - y, y0 - x, colour)
Bitmap.circle = circle

bitmap = Bitmap(25,25)
bitmap.circle(x0=12, y0=12, radius=12)
bitmap.chardisplay()
Task: Bitmap_Midpoint circle algorithm




Go: package raster






func (b *Bitmap) Circle(x, y, r int, p Pixel) {
    if r < 0 {
        return
    }
    
    x1, y1, err := -r, 0, 2-2*r
    for {
        b.SetPx(x-x1, y+y1, p)
        b.SetPx(x-y1, y-x1, p)
        b.SetPx(x+x1, y-y1, p)
        b.SetPx(x+y1, y+x1, p)
        r = err
        if r > x1 {
            x1++
            err += x1*2 + 1
        }
        if r <= y1 {
            y1++
            err += y1*2 + 1
        }
        if x1 >= 0 {
            break
        }
    }
}

func (b *Bitmap) CircleRgb(x, y, r int, c Rgb) {
    b.Circle(x, y, r, c.Pixel())
}
Task: Bitmap_Midpoint circle algorithm



C#:         
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        public static void DrawCircle(this GenericImage image, int centerX, int centerY, int radius, Color color)
        {
            int d = (5 - radius * 4) / 4;
            int x = 0;
            int y = radius;

            do
            {
                
                
                if (centerX + x >= 0 && centerX + x <= image.Width - 1 && centerY + y >= 0 && centerY + y <= image.Height - 1) image[centerX + x, centerY + y] = color;
                if (centerX + x >= 0 && centerX + x <= image.Width - 1 && centerY - y >= 0 && centerY - y <= image.Height - 1) image[centerX + x, centerY - y] = color;
                if (centerX - x >= 0 && centerX - x <= image.Width - 1 && centerY + y >= 0 && centerY + y <= image.Height - 1) image[centerX - x, centerY + y] = color;
                if (centerX - x >= 0 && centerX - x <= image.Width - 1 && centerY - y >= 0 && centerY - y <= image.Height - 1) image[centerX - x, centerY - y] = color;
                if (centerX + y >= 0 && centerX + y <= image.Width - 1 && centerY + x >= 0 && centerY + x <= image.Height - 1) image[centerX + y, centerY + x] = color;
                if (centerX + y >= 0 && centerX + y <= image.Width - 1 && centerY - x >= 0 && centerY - x <= image.Height - 1) image[centerX + y, centerY - x] = color;
                if (centerX - y >= 0 && centerX - y <= image.Width - 1 && centerY + x >= 0 && centerY + x <= image.Height - 1) image[centerX - y, centerY + x] = color;
                if (centerX - y >= 0 && centerX - y <= image.Width - 1 && centerY - x >= 0 && centerY - x <= image.Height - 1) image[centerX - y, centerY - x] = color;
                if (d < 0)
                {
                    d += 2 * x + 1;
                }
                else
                {
                    d += 2 * (x - y) + 1;
                    y--;
                }
                x++;
            } while (x <= y);
        }








Fortran: interface draw_circle
   module procedure draw_circle_sc, draw_circle_rgb
end interface

private :: plot, draw_circle_toch
Task: Bitmap_Midpoint circle algorithm

C: void raster_circle(
        image img,
        unsigned int x0,
        unsigned int y0,
        unsigned int radius,
        color_component r,
        color_component g,
        color_component b );










Fortran: interface draw_circle
   module procedure draw_circle_sc, draw_circle_rgb
end interface

private :: plot, draw_circle_toch
Task: Bitmap_Midpoint circle algorithm




Go: package raster






func (b *Bitmap) Circle(x, y, r int, p Pixel) {
    if r < 0 {
        return
    }
    
    x1, y1, err := -r, 0, 2-2*r
    for {
        b.SetPx(x-x1, y+y1, p)
        b.SetPx(x-y1, y-x1, p)
        b.SetPx(x+x1, y-y1, p)
        b.SetPx(x+y1, y+x1, p)
        r = err
        if r > x1 {
            x1++
            err += x1*2 + 1
        }
        if r <= y1 {
            y1++
            err += y1*2 + 1
        }
        if x1 >= 0 {
            break
        }
    }
}

func (b *Bitmap) CircleRgb(x, y, r int, c Rgb) {
    b.Circle(x, y, r, c.Pixel())
}







Fortran: interface draw_circle
   module procedure draw_circle_sc, draw_circle_rgb
end interface

private :: plot, draw_circle_toch
Task: Bitmap_Midpoint circle algorithm





Java: import java.awt.Color;

public class MidPointCircle {
	private BasicBitmapStorage image;

	public MidPointCircle(final int imageWidth, final int imageHeight) {
		this.image = new BasicBitmapStorage(imageWidth, imageHeight);
	}

	private void drawCircle(final int centerX, final int centerY, final int radius) {
		int d = (5 - radius * 4)/4;
		int x = 0;
		int y = radius;
		Color circleColor = Color.white;

		do {
			image.setPixel(centerX + x, centerY + y, circleColor);
			image.setPixel(centerX + x, centerY - y, circleColor);
			image.setPixel(centerX - x, centerY + y, circleColor);
			image.setPixel(centerX - x, centerY - y, circleColor);
			image.setPixel(centerX + y, centerY + x, circleColor);
			image.setPixel(centerX + y, centerY - x, circleColor);
			image.setPixel(centerX - y, centerY + x, circleColor);
			image.setPixel(centerX - y, centerY - x, circleColor);
			if (d < 0) {
				d += 2 * x + 1;
			} else {
				d += 2 * (x - y) + 1;
				y--;
			}
			x++;
		} while (x <= y);

	}
}






Fortran: interface draw_circle
   module procedure draw_circle_sc, draw_circle_rgb
end interface

private :: plot, draw_circle_toch
Task: Bitmap_Midpoint circle algorithm







Python: def circle(self, x0, y0, radius, colour=black):
    f = 1 - radius
    ddf_x = 1
    ddf_y = -2 * radius
    x = 0
    y = radius
    self.set(x0, y0 + radius, colour)
    self.set(x0, y0 - radius, colour)
    self.set(x0 + radius, y0, colour)
    self.set(x0 - radius, y0, colour)

    while x < y:
        if f >= 0: 
            y -= 1
            ddf_y += 2
            f += ddf_y
        x += 1
        ddf_x += 2
        f += ddf_x    
        self.set(x0 + x, y0 + y, colour)
        self.set(x0 - x, y0 + y, colour)
        self.set(x0 + x, y0 - y, colour)
        self.set(x0 - x, y0 - y, colour)
        self.set(x0 + y, y0 + x, colour)
        self.set(x0 - y, y0 + x, colour)
        self.set(x0 + y, y0 - x, colour)
        self.set(x0 - y, y0 - x, colour)
Bitmap.circle = circle

bitmap = Bitmap(25,25)
bitmap.circle(x0=12, y0=12, radius=12)
bitmap.chardisplay()






Fortran: interface draw_circle
   module procedure draw_circle_sc, draw_circle_rgb
end interface

private :: plot, draw_circle_toch
Task: Permutations



C#: public static class Extension
{
    public static IEnumerable<IEnumerable<T>> Permutations<T>(this IEnumerable<T> values) where T : IComparable<T>
    {
        if (values.Count() == 1)
            return new[] { values };
        return values.SelectMany(v => Permutations(values.Where(x => x.CompareTo(v) != 0)), (v, p) => p.Prepend(v));
    }
}









Ada: generic
   N: positive;
package Generic_Perm is
   subtype Element is Positive range 1 .. N;
   type Permutation is array(Element) of Element;
   
   procedure Set_To_First(P: out Permutation; Is_Last: out Boolean);
   procedure Go_To_Next(P: in out Permutation; Is_Last: out Boolean); 
end Generic_Perm;
Task: Permutations

C: #include <stdio.h>
int main (int argc, char *argv[]) {

	if (argc < 2) {
        printf("Enter an argument. Example 1234 or dcba:\n");
        return 0;
	}

        int x;
        for (x = 0; argv[1][x] != '\0'; x++);

	int f, v, m;
	 for(f=0; f < x; f++) {
    	 for(v = x-1; v > f; v-- ) {
     	 if (argv[1][v-1] > argv[1][v]) {
	m=argv[1][v-1];
	argv[1][v-1]=argv[1][v];
	argv[1][v]=m;
    }
  }
}


    char a[x];
	int k=0;
	int fact=k+1;
             while (k!=x) {
                   a[k]=argv[1][k];
               	   k++;
		  fact = k*fact;
                   }
                   a[k]='\0';

           int i, j;
           int y=0;
           char c;
          while (y != fact) {
          printf("%s\n", a);
          i=x-2;
          while(a[i] > a[i+1] ) i--;
          j=x-1;
          while(a[j] < a[i] ) j--;
      c=a[j];
      a[j]=a[i];
      a[i]=c;
i++;
for (j = x-1; j > i; i++, j--) {
  c = a[i];
  a[i] = a[j];
  a[j] = c;
      }
y++;
   }
}











Ada: generic
   N: positive;
package Generic_Perm is
   subtype Element is Positive range 1 .. N;
   type Permutation is array(Element) of Element;
   
   procedure Set_To_First(P: out Permutation; Is_Last: out Boolean);
   procedure Go_To_Next(P: in out Permutation; Is_Last: out Boolean); 
end Generic_Perm;