WeixiangYan/CodeTransOcean huggingface dataset:
Task: Langton's ant







Python: 





STEP = 100
count = 0

def setup():
    global x, y, direction

    
    
    size(100, 100, P2D)

    background(255)
    x = width / 2
    y = height / 2
    direction = 0

def draw():
    global count
    for i in range(STEP):
        count += 1
        pix = get(x, y) != -1 
        setBool(x, y, pix)

        turn(pix)
        move()

        if (x < 0 or y < 0 or x >= width or y >= height):
            println("finished")
            noLoop()
            break

    if count % 1000 == 0:
        println("iteration {}".format(count))

def move():
    global x, y
    if direction == 0:
        y -= 1
    elif direction == 1:
        x -= 1
    elif direction == 2:
        y += 1
    elif direction == 3:
        x += 1

def turn(rightleft):
    global direction
    direction += 1 if rightleft else -1
    if direction == -1:
        direction = 3
    if direction == 4:
        direction = 0

def setBool(x, y, white):
    set(x, y, -1 if white else 0)


VB: Option Explicit

Sub Ant()
  Dim TablDatas(1 To 200, 1 To 256) As String, sDir As String, sFile As String, Str As String
  Dim ColA As Integer, LigA As Long, ColF As Integer, LigF As Long, i As Long, j As Integer, Num As Long
  Dim Top As Boolean, Left As Boolean, Bottom As Boolean, Right As Boolean
    
    
    Select Case Int(Rnd(4) * 4)
      Case 0: Top = True
      Case 1: Right = True
      Case 2: Bottom = True
      Case 3: Left = True
    End Select
      
    LigF = 80
    ColF = 50
    For i = 1 To 200
        For j = 1 To 256
            TablDatas(i, j) = " "
        Next
    Next
    
    sDir = "/Users/mjreed/Desktop/"
    
    sFile = "Langton_Ant.txt"
    
    
    Dim Dir As String
    For i = 1 To 15000
        LigA = LigF
        ColA = ColF
       
        If LigA = 1 Or ColA = 1 Or ColA = 256 Or LigA = 200 Then GoTo Fin
        If TablDatas(LigA, ColA) = " " Then
            TablDatas(LigA, ColA) = "#"
            Select Case True
                Case Top: Top = False: Right = True: LigF = LigA: ColF = ColA + 1
                Case Left: Left = False: Top = True: LigF = LigA - 1: ColF = ColA
                Case Bottom: Bottom = False: Left = True: LigF = LigA: ColF = ColA - 1
                Case Right: Right = False: Bottom = True: LigF = LigA + 1: ColF = ColA
            End Select
        Else
            TablDatas(LigA, ColA) = " "
            Select Case True
                Case Top: Top = False: Left = True: LigF = LigA: ColF = ColA - 1
                Case Left: Left = False: Bottom = True: LigF = LigA + 1: ColF = ColA
                Case Bottom: Bottom = False: Right = True: LigF = LigA: ColF = ColA + 1
                Case Right: Right = False: Top = True: LigF = LigA - 1: ColF = ColA
            End Select
        End If
    Next i
Fin:
    
    Num = FreeFile
    Open sDir & sFile For Output As #Num
    
    For i = 1 To UBound(TablDatas, 1)
        Str = vbNullString
        For j = 1 To UBound(TablDatas, 2)
            Str = Str & TablDatas(i, j)
        Next j
        Print #Num, Str
    Next i
    Close #Num
    Exit Sub
End Sub
Task: Langton's ant

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int w = 0, h = 0;
unsigned char *pix;

void refresh(int x, int y)
{
	int i, j, k;
	printf("\033[H");
	for (i = k = 0; i < h; putchar('\n'), i++)
		for (j = 0; j < w; j++, k++)
			putchar(pix[k] ? '#' : ' ');
}

void walk()
{
	int dx = 0, dy = 1, i, k;
	int x = w / 2, y = h / 2;

	pix = calloc(1, w * h);
	printf("\033[H\033[J");

	while (1) {
		i = (y * w + x);
		if (pix[i]) k = dx, dx = -dy, dy = k;
		else	    k = dy, dy = -dx, dx = k;

		pix[i] = !pix[i];
		printf("\033[%d;%dH%c", y + 1, x + 1, pix[i] ? '#' : ' ');

		x += dx, y += dy;

		k = 0;
		if (x < 0) {
			memmove(pix + 1, pix, w * h - 1);
			for (i = 0; i < w * h; i += w) pix[i] = 0;
			x++, k = 1;
		}
		else if (x >= w) {
			memmove(pix, pix + 1, w * h - 1);
			for (i = w-1; i < w * h; i += w) pix[i] = 0;
			x--, k = 1;
		}

		if (y >= h) {
			memmove(pix, pix + w, w * (h - 1));
			memset(pix + w * (h - 1), 0, w);
			y--, k = 1;
		}
		else if (y < 0) {
			memmove(pix + w, pix, w * (h - 1));
			memset(pix, 0, w);
			y++, k = 1;
		}
		if (k) refresh(x, y);
		printf("\033[%d;%dH\033[31m@\033[m", y + 1, x + 1);

		fflush(stdout);
		usleep(10000);
	}
}

int main(int c, char **v)
{
	if (c > 1) w = atoi(v[1]);
	if (c > 2) h = atoi(v[2]);
	if (w < 40) w = 40;
	if (h < 25) h = 25;

	walk();
	return 0;
}





Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Langton extends JFrame{
	private JPanel planePanel;
	private static final int ZOOM = 4;
	
	public Langton(final boolean[][] plane){
		planePanel = new JPanel(){
			@Override
			public void paint(Graphics g) {
				for(int y = 0; y < plane.length;y++){
					for(int x = 0; x < plane[0].length;x++){
						g.setColor(plane[y][x] ? Color.BLACK : Color.WHITE);
						g.fillRect(x * ZOOM, y * ZOOM, ZOOM, ZOOM);
					}
				}
				
				g.setColor(Color.GREEN);
				g.fillRect(plane[0].length / 2 * ZOOM,
				           plane.length / 2 * ZOOM, ZOOM/2, ZOOM/2);
			}
		};
		planePanel.setSize(plane[0].length - 1, plane.length - 1);
		add(planePanel);
		setSize(ZOOM * plane[0].length, ZOOM * plane.length + 30);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	public static void main(String[] args){
		new Langton(runAnt(100, 100));
	}

	private static boolean[][] runAnt(int height, int width){
		boolean[][] plane = new boolean[height][width];
		int antX = width/2, antY = height/2;
		int xChange = 0, yChange = -1; 
		while(antX < width && antY < height && antX >= 0 && antY >= 0){
			if(plane[antY][antX]){
				
				if(xChange == 0){ 
					xChange = yChange;
					yChange = 0;
				}else{ 
					yChange = -xChange;
					xChange = 0;
				}
			}else{
				
				if(xChange == 0){ 
					xChange = -yChange;
					yChange = 0;
				}else{ 
					yChange = xChange;
					xChange = 0;
				}
			}
			plane[antY][antX] = !plane[antY][antX];
			antX += xChange;
			antY += yChange;
		}
		return plane;
	}
}
Task: Langton's ant





Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Langton extends JFrame{
	private JPanel planePanel;
	private static final int ZOOM = 4;
	
	public Langton(final boolean[][] plane){
		planePanel = new JPanel(){
			@Override
			public void paint(Graphics g) {
				for(int y = 0; y < plane.length;y++){
					for(int x = 0; x < plane[0].length;x++){
						g.setColor(plane[y][x] ? Color.BLACK : Color.WHITE);
						g.fillRect(x * ZOOM, y * ZOOM, ZOOM, ZOOM);
					}
				}
				
				g.setColor(Color.GREEN);
				g.fillRect(plane[0].length / 2 * ZOOM,
				           plane.length / 2 * ZOOM, ZOOM/2, ZOOM/2);
			}
		};
		planePanel.setSize(plane[0].length - 1, plane.length - 1);
		add(planePanel);
		setSize(ZOOM * plane[0].length, ZOOM * plane.length + 30);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	public static void main(String[] args){
		new Langton(runAnt(100, 100));
	}

	private static boolean[][] runAnt(int height, int width){
		boolean[][] plane = new boolean[height][width];
		int antX = width/2, antY = height/2;
		int xChange = 0, yChange = -1; 
		while(antX < width && antY < height && antX >= 0 && antY >= 0){
			if(plane[antY][antX]){
				
				if(xChange == 0){ 
					xChange = yChange;
					yChange = 0;
				}else{ 
					yChange = -xChange;
					xChange = 0;
				}
			}else{
				
				if(xChange == 0){ 
					xChange = -yChange;
					yChange = 0;
				}else{ 
					yChange = xChange;
					xChange = 0;
				}
			}
			plane[antY][antX] = !plane[antY][antX];
			antX += xChange;
			antY += yChange;
		}
		return plane;
	}
}



Python: 





STEP = 100
count = 0

def setup():
    global x, y, direction

    
    
    size(100, 100, P2D)

    background(255)
    x = width / 2
    y = height / 2
    direction = 0

def draw():
    global count
    for i in range(STEP):
        count += 1
        pix = get(x, y) != -1 
        setBool(x, y, pix)

        turn(pix)
        move()

        if (x < 0 or y < 0 or x >= width or y >= height):
            println("finished")
            noLoop()
            break

    if count % 1000 == 0:
        println("iteration {}".format(count))

def move():
    global x, y
    if direction == 0:
        y -= 1
    elif direction == 1:
        x -= 1
    elif direction == 2:
        y += 1
    elif direction == 3:
        x += 1

def turn(rightleft):
    global direction
    direction += 1 if rightleft else -1
    if direction == -1:
        direction = 3
    if direction == 4:
        direction = 0

def setBool(x, y, white):
    set(x, y, -1 if white else 0)
Task: Langton's ant

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int w = 0, h = 0;
unsigned char *pix;

void refresh(int x, int y)
{
	int i, j, k;
	printf("\033[H");
	for (i = k = 0; i < h; putchar('\n'), i++)
		for (j = 0; j < w; j++, k++)
			putchar(pix[k] ? '#' : ' ');
}

void walk()
{
	int dx = 0, dy = 1, i, k;
	int x = w / 2, y = h / 2;

	pix = calloc(1, w * h);
	printf("\033[H\033[J");

	while (1) {
		i = (y * w + x);
		if (pix[i]) k = dx, dx = -dy, dy = k;
		else	    k = dy, dy = -dx, dx = k;

		pix[i] = !pix[i];
		printf("\033[%d;%dH%c", y + 1, x + 1, pix[i] ? '#' : ' ');

		x += dx, y += dy;

		k = 0;
		if (x < 0) {
			memmove(pix + 1, pix, w * h - 1);
			for (i = 0; i < w * h; i += w) pix[i] = 0;
			x++, k = 1;
		}
		else if (x >= w) {
			memmove(pix, pix + 1, w * h - 1);
			for (i = w-1; i < w * h; i += w) pix[i] = 0;
			x--, k = 1;
		}

		if (y >= h) {
			memmove(pix, pix + w, w * (h - 1));
			memset(pix + w * (h - 1), 0, w);
			y--, k = 1;
		}
		else if (y < 0) {
			memmove(pix + w, pix, w * (h - 1));
			memset(pix, 0, w);
			y++, k = 1;
		}
		if (k) refresh(x, y);
		printf("\033[%d;%dH\033[31m@\033[m", y + 1, x + 1);

		fflush(stdout);
		usleep(10000);
	}
}

int main(int c, char **v)
{
	if (c > 1) w = atoi(v[1]);
	if (c > 2) h = atoi(v[2]);
	if (w < 40) w = 40;
	if (h < 25) h = 25;

	walk();
	return 0;
}






PHP: 
define('dest_name', 'output.png'); // destination image
define('width', 100);
define('height', 100);

$x = 50;
$y = 70;
$dir = 0; // 0-up, 1-left, 2-down, 3-right
$field = array();
$step_count = 0; 

while(0 <= $x && $x <= width && 0 <= $y && $y <= height){
	if(isset($field[$x][$y])){
		unset($field[$x][$y]);
		$dir = ($dir + 3) % 4;
	}else{
		$field[$x][$y] = true;
		$dir = ($dir + 1) % 4;
	}
	switch($dir){
		case 0: $y++; break;
		case 1: $x--; break;
		case 2: $y--; break;
		case 3: $x++; break;
	}
	$step_count++;
}

$img = imagecreatetruecolor(width, height);
$white = imagecolorallocate($img, 255, 255, 255);
for($x = 0; $x < width; $x++){	
	for($y = 0; $y < height; $y++){
		if(isset($field[$x][$y])){
			imagesetpixel($img, $x, $y, $white);
		}
	}
}

$color = array();
$color[0] = imagecolorallocate($img, 255, 0, 0);
$color[1] = imagecolorallocate($img, 0, 255, 0);
$color[2] = imagecolorallocate($img, 0, 0, 255);
$print_array = array(
	0 => 'Langton`s Ant', 1=>'PHP Version', 2=>'Steps: ' . $step_count
);
foreach($print_array as $key => $line){
	imagestring($img, 3, 3, 3 + $key*11, $line, $color[$key]);
}

imagepng($img, dest_name);
Task: Langton's ant




Go: package main

import (
    "fmt"
    "image"
    "image/color"
    "image/draw"
    "image/png"
    "os"
)

const (
    up = iota
    rt
    dn
    lt
)

func main() {
    bounds := image.Rect(0, 0, 100, 100)
    im := image.NewGray(bounds)
    gBlack := color.Gray{0}
    gWhite := color.Gray{255}
    draw.Draw(im, bounds, image.NewUniform(gWhite), image.ZP, draw.Src)
    pos := image.Point{50, 50}
    dir := up
    for pos.In(bounds) {
        switch im.At(pos.X, pos.Y).(color.Gray).Y {
        case gBlack.Y:
            im.SetGray(pos.X, pos.Y, gWhite)
            dir--
        case gWhite.Y:
            im.SetGray(pos.X, pos.Y, gBlack)
            dir++
        }
        if dir&1 == 1 {
            pos.X += 1 - dir&2
        } else {
            pos.Y -= 1 - dir&2
        }
    }
    f, err := os.Create("ant.png")
    if err != nil {
        fmt.Println(err)
        return
    }
    if err = png.Encode(f, im); err != nil {
        fmt.Println(err)
    }
    if err = f.Close(); err != nil {
        fmt.Println(err)
    }
}



PHP: 
define('dest_name', 'output.png'); // destination image
define('width', 100);
define('height', 100);

$x = 50;
$y = 70;
$dir = 0; // 0-up, 1-left, 2-down, 3-right
$field = array();
$step_count = 0; 

while(0 <= $x && $x <= width && 0 <= $y && $y <= height){
	if(isset($field[$x][$y])){
		unset($field[$x][$y]);
		$dir = ($dir + 3) % 4;
	}else{
		$field[$x][$y] = true;
		$dir = ($dir + 1) % 4;
	}
	switch($dir){
		case 0: $y++; break;
		case 1: $x--; break;
		case 2: $y--; break;
		case 3: $x++; break;
	}
	$step_count++;
}

$img = imagecreatetruecolor(width, height);
$white = imagecolorallocate($img, 255, 255, 255);
for($x = 0; $x < width; $x++){	
	for($y = 0; $y < height; $y++){
		if(isset($field[$x][$y])){
			imagesetpixel($img, $x, $y, $white);
		}
	}
}

$color = array();
$color[0] = imagecolorallocate($img, 255, 0, 0);
$color[1] = imagecolorallocate($img, 0, 255, 0);
$color[2] = imagecolorallocate($img, 0, 0, 255);
$print_array = array(
	0 => 'Langton`s Ant', 1=>'PHP Version', 2=>'Steps: ' . $step_count
);
foreach($print_array as $key => $line){
	imagestring($img, 3, 3, 3 + $key*11, $line, $color[$key]);
}

imagepng($img, dest_name);
Task: Langton's ant





Java: import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Langton extends JFrame{
	private JPanel planePanel;
	private static final int ZOOM = 4;
	
	public Langton(final boolean[][] plane){
		planePanel = new JPanel(){
			@Override
			public void paint(Graphics g) {
				for(int y = 0; y < plane.length;y++){
					for(int x = 0; x < plane[0].length;x++){
						g.setColor(plane[y][x] ? Color.BLACK : Color.WHITE);
						g.fillRect(x * ZOOM, y * ZOOM, ZOOM, ZOOM);
					}
				}
				
				g.setColor(Color.GREEN);
				g.fillRect(plane[0].length / 2 * ZOOM,
				           plane.length / 2 * ZOOM, ZOOM/2, ZOOM/2);
			}
		};
		planePanel.setSize(plane[0].length - 1, plane.length - 1);
		add(planePanel);
		setSize(ZOOM * plane[0].length, ZOOM * plane.length + 30);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	public static void main(String[] args){
		new Langton(runAnt(100, 100));
	}

	private static boolean[][] runAnt(int height, int width){
		boolean[][] plane = new boolean[height][width];
		int antX = width/2, antY = height/2;
		int xChange = 0, yChange = -1; 
		while(antX < width && antY < height && antX >= 0 && antY >= 0){
			if(plane[antY][antX]){
				
				if(xChange == 0){ 
					xChange = yChange;
					yChange = 0;
				}else{ 
					yChange = -xChange;
					xChange = 0;
				}
			}else{
				
				if(xChange == 0){ 
					xChange = -yChange;
					yChange = 0;
				}else{ 
					yChange = xChange;
					xChange = 0;
				}
			}
			plane[antY][antX] = !plane[antY][antX];
			antX += xChange;
			antY += yChange;
		}
		return plane;
	}
}


PHP: 
define('dest_name', 'output.png'); // destination image
define('width', 100);
define('height', 100);

$x = 50;
$y = 70;
$dir = 0; // 0-up, 1-left, 2-down, 3-right
$field = array();
$step_count = 0; 

while(0 <= $x && $x <= width && 0 <= $y && $y <= height){
	if(isset($field[$x][$y])){
		unset($field[$x][$y]);
		$dir = ($dir + 3) % 4;
	}else{
		$field[$x][$y] = true;
		$dir = ($dir + 1) % 4;
	}
	switch($dir){
		case 0: $y++; break;
		case 1: $x--; break;
		case 2: $y--; break;
		case 3: $x++; break;
	}
	$step_count++;
}

$img = imagecreatetruecolor(width, height);
$white = imagecolorallocate($img, 255, 255, 255);
for($x = 0; $x < width; $x++){	
	for($y = 0; $y < height; $y++){
		if(isset($field[$x][$y])){
			imagesetpixel($img, $x, $y, $white);
		}
	}
}

$color = array();
$color[0] = imagecolorallocate($img, 255, 0, 0);
$color[1] = imagecolorallocate($img, 0, 255, 0);
$color[2] = imagecolorallocate($img, 0, 0, 255);
$print_array = array(
	0 => 'Langton`s Ant', 1=>'PHP Version', 2=>'Steps: ' . $step_count
);
foreach($print_array as $key => $line){
	imagestring($img, 3, 3, 3 + $key*11, $line, $color[$key]);
}

imagepng($img, dest_name);
Task: Langton's ant






PHP: 
define('dest_name', 'output.png'); // destination image
define('width', 100);
define('height', 100);

$x = 50;
$y = 70;
$dir = 0; // 0-up, 1-left, 2-down, 3-right
$field = array();
$step_count = 0; 

while(0 <= $x && $x <= width && 0 <= $y && $y <= height){
	if(isset($field[$x][$y])){
		unset($field[$x][$y]);
		$dir = ($dir + 3) % 4;
	}else{
		$field[$x][$y] = true;
		$dir = ($dir + 1) % 4;
	}
	switch($dir){
		case 0: $y++; break;
		case 1: $x--; break;
		case 2: $y--; break;
		case 3: $x++; break;
	}
	$step_count++;
}

$img = imagecreatetruecolor(width, height);
$white = imagecolorallocate($img, 255, 255, 255);
for($x = 0; $x < width; $x++){	
	for($y = 0; $y < height; $y++){
		if(isset($field[$x][$y])){
			imagesetpixel($img, $x, $y, $white);
		}
	}
}

$color = array();
$color[0] = imagecolorallocate($img, 255, 0, 0);
$color[1] = imagecolorallocate($img, 0, 255, 0);
$color[2] = imagecolorallocate($img, 0, 0, 255);
$print_array = array(
	0 => 'Langton`s Ant', 1=>'PHP Version', 2=>'Steps: ' . $step_count
);
foreach($print_array as $key => $line){
	imagestring($img, 3, 3, 3 + $key*11, $line, $color[$key]);
}

imagepng($img, dest_name);


Python: 





STEP = 100
count = 0

def setup():
    global x, y, direction

    
    
    size(100, 100, P2D)

    background(255)
    x = width / 2
    y = height / 2
    direction = 0

def draw():
    global count
    for i in range(STEP):
        count += 1
        pix = get(x, y) != -1 
        setBool(x, y, pix)

        turn(pix)
        move()

        if (x < 0 or y < 0 or x >= width or y >= height):
            println("finished")
            noLoop()
            break

    if count % 1000 == 0:
        println("iteration {}".format(count))

def move():
    global x, y
    if direction == 0:
        y -= 1
    elif direction == 1:
        x -= 1
    elif direction == 2:
        y += 1
    elif direction == 3:
        x += 1

def turn(rightleft):
    global direction
    direction += 1 if rightleft else -1
    if direction == -1:
        direction = 3
    if direction == 4:
        direction = 0

def setBool(x, y, white):
    set(x, y, -1 if white else 0)
Task: Anagrams


C++: #include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iterator>
 
int main() {
  std::ifstream in("unixdict.txt");
  typedef  std::map<std::string, std::vector<std::string> > AnagramMap;
  AnagramMap anagrams;
 
  std::string word;
  size_t count = 0;
  while (std::getline(in, word)) {
    std::string key = word;
    std::sort(key.begin(), key.end());
    
    AnagramMap::mapped_type & v = anagrams[key];
    v.push_back(word);
    count = std::max(count, v.size());
  }
 
  in.close();
 
  for (AnagramMap::const_iterator it = anagrams.begin(), e = anagrams.end();
       it != e; it++)
    if (it->second.size() >= count) {
      std::copy(it->second.begin(), it->second.end(),
                std::ostream_iterator<std::string>(std::cout, ", "));
      std::cout << std::endl;
    }
  return 0;
}




Java: import java.net.*;
import java.io.*;
import java.util.*;
 
public class WordsOfEqChars {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http:
        InputStreamReader isr = new InputStreamReader(url.openStream());
        BufferedReader reader = new BufferedReader(isr);

        Map<String, Collection<String>> anagrams = new HashMap<String, Collection<String>>();
        String word;
        int count = 0;
        while ((word = reader.readLine()) != null) {
            char[] chars = word.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            if (!anagrams.containsKey(key))
                anagrams.put(key, new ArrayList<String>());
            anagrams.get(key).add(word);
            count = Math.max(count, anagrams.get(key).size());
        }

        reader.close();

        for (Collection<String> ana : anagrams.values())
            if (ana.size() >= count)
                System.out.println(ana);
    }   
}
Task: Anagrams


C++: #include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iterator>
 
int main() {
  std::ifstream in("unixdict.txt");
  typedef  std::map<std::string, std::vector<std::string> > AnagramMap;
  AnagramMap anagrams;
 
  std::string word;
  size_t count = 0;
  while (std::getline(in, word)) {
    std::string key = word;
    std::sort(key.begin(), key.end());
    
    AnagramMap::mapped_type & v = anagrams[key];
    v.push_back(word);
    count = std::max(count, v.size());
  }
 
  in.close();
 
  for (AnagramMap::const_iterator it = anagrams.begin(), e = anagrams.end();
       it != e; it++)
    if (it->second.size() >= count) {
      std::copy(it->second.begin(), it->second.end(),
                std::ostream_iterator<std::string>(std::cout, ", "));
      std::cout << std::endl;
    }
  return 0;
}






Python: >>> import urllib.request
>>> from collections import defaultdict
>>> words = urllib.request.urlopen('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt').read().split()
>>> anagram = defaultdict(list) 
>>> for word in words:
	anagram[tuple(sorted(word))].append( word )

	
>>> count = max(len(ana) for ana in anagram.values())
>>> for ana in anagram.values():
	if len(ana) >= count:
		print ([x.decode() for x in ana])
Task: Anagrams


C++: #include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iterator>
 
int main() {
  std::ifstream in("unixdict.txt");
  typedef  std::map<std::string, std::vector<std::string> > AnagramMap;
  AnagramMap anagrams;
 
  std::string word;
  size_t count = 0;
  while (std::getline(in, word)) {
    std::string key = word;
    std::sort(key.begin(), key.end());
    
    AnagramMap::mapped_type & v = anagrams[key];
    v.push_back(word);
    count = std::max(count, v.size());
  }
 
  in.close();
 
  for (AnagramMap::const_iterator it = anagrams.begin(), e = anagrams.end();
       it != e; it++)
    if (it->second.size() >= count) {
      std::copy(it->second.begin(), it->second.end(),
                std::ostream_iterator<std::string>(std::cout, ", "));
      std::cout << std::endl;
    }
  return 0;
}







VB: dim x as integer, y as integer
dim SortX as integer
dim StrOutPut as string
dim Count as integer
dim MaxCount as integer

dim AnaList as QStringlist
dim wordlist as QStringlist
dim Templist as QStringlist
dim Charlist as Qstringlist


function sortChars(expr as string) as string
    Charlist.clear
    for SortX = 1 to len(expr)
         Charlist.AddItems expr[SortX]
    next
    charlist.sort
    result = Charlist.text - chr$(10) - chr$(13)
end function
 

    wordlist.loadfromfile ("unixdict.txt")

    
    for x = 0 to wordlist.itemcount-1
        AnaList.AddItems sortChars(wordlist.item(x))
    next
       
    
    analist.sort
    MaxCount = 0
    
    for x = 0 to AnaList.Itemcount-1
        Count = 0
        for y = x+1 to AnaList.Itemcount-1
            if AnaList.item(y) = AnaList.item(x) then
                inc(count)
            else
                if count > MaxCount then 
                    Templist.clear
                    MaxCount = Count
                    Templist.AddItems AnaList.item(x)
                elseif count = MaxCount then
                    Templist.AddItems AnaList.item(x)
                end if
                exit for
            end if
        next
    next
       
    
    for x = 0 to Templist.Itemcount-1
        for y = 0 to wordlist.Itemcount-1 
            if Templist.item(x) = sortChars(wordlist.item(y)) then
                StrOutPut = StrOutPut + wordlist.item(y) + "  "
            end if
        next
        StrOutPut = StrOutPut + chr$(13) + chr$(10)
    next

ShowMessage StrOutPut 
End