kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Boolean values
C#: bool? value = null

Java: module GeorgeBoole
    {
    @Inject Console console;

    void run()
        {
        Boolean f = False;
        assert !f == True;

        
        
        assert True.and(False) == True & False == False;
        assert True.or(False)  == True | False == True;
        assert True.xor(False) == True ^ False == True;
        assert True.not() == ~True == False;

        console.print($"0==1 = {0==1}");
        console.print($"!False = {!False}");
        }
    }
Task: Boolean values
C#: bool? value = null

Python: >>> True
True
>>> not True
False
>>> 
>>> False + 0
0
>>> True + 0
1
>>> False + 0j
0j
>>> True * 3.141
3.141
>>> 
>>> not 0
True
>>> not not 0
False
>>> not 1234
False
>>> bool(0.0)
False
>>> bool(0j)
False
>>> bool(1+2j)
True
>>> 
>>> bool([])
False
>>> bool([None])
True
>>> 'I contain something' if (None,) else 'I am empty'
'I contain something'
>>> bool({})
False
>>> bool("")
False
>>> bool("False")
True
Task: Boolean values
C#: bool? value = null

VB: Dim a As Integer
Dim b As Boolean
Debug.Print b
a = b
Debug.Print a
b = True
Debug.Print b
a = b
Debug.Print a
Task: Boolean values
Go:  
package main

import (
	"fmt"
	"reflect"
	"strconv"
)

func main() {
	var n bool = true
	fmt.Println(n)        
	fmt.Printf("%T\n", n) 
	n = !n
	fmt.Println(n) 

	x := 5
	y := 8
	fmt.Println("x == y:", x == y) 
	fmt.Println("x < y:", x < y)   

	fmt.Println("\nConvert String into Boolean Data type\n")
	str1 := "japan"
	fmt.Println("Before :", reflect.TypeOf(str1)) 
	bolStr, _ := strconv.ParseBool(str1)
	fmt.Println("After :", reflect.TypeOf(bolStr)) 
}

Java: module GeorgeBoole
    {
    @Inject Console console;

    void run()
        {
        Boolean f = False;
        assert !f == True;

        
        
        assert True.and(False) == True & False == False;
        assert True.or(False)  == True | False == True;
        assert True.xor(False) == True ^ False == True;
        assert True.not() == ~True == False;

        console.print($"0==1 = {0==1}");
        console.print($"!False = {!False}");
        }
    }
Task: Boolean values
Java: module GeorgeBoole
    {
    @Inject Console console;

    void run()
        {
        Boolean f = False;
        assert !f == True;

        
        
        assert True.and(False) == True & False == False;
        assert True.or(False)  == True | False == True;
        assert True.xor(False) == True ^ False == True;
        assert True.not() == ~True == False;

        console.print($"0==1 = {0==1}");
        console.print($"!False = {!False}");
        }
    }

Python: >>> True
True
>>> not True
False
>>> 
>>> False + 0
0
>>> True + 0
1
>>> False + 0j
0j
>>> True * 3.141
3.141
>>> 
>>> not 0
True
>>> not not 0
False
>>> not 1234
False
>>> bool(0.0)
False
>>> bool(0j)
False
>>> bool(1+2j)
True
>>> 
>>> bool([])
False
>>> bool([None])
True
>>> 'I contain something' if (None,) else 'I am empty'
'I contain something'
>>> bool({})
False
>>> bool("")
False
>>> bool("False")
True
Task: Boolean values
Java: module GeorgeBoole
    {
    @Inject Console console;

    void run()
        {
        Boolean f = False;
        assert !f == True;

        
        
        assert True.and(False) == True & False == False;
        assert True.or(False)  == True | False == True;
        assert True.xor(False) == True ^ False == True;
        assert True.not() == ~True == False;

        console.print($"0==1 = {0==1}");
        console.print($"!False = {!False}");
        }
    }

VB: Dim a As Integer
Dim b As Boolean
Debug.Print b
a = b
Debug.Print a
b = True
Debug.Print b
a = b
Debug.Print a
Task: Boolean values
Go:  
package main

import (
	"fmt"
	"reflect"
	"strconv"
)

func main() {
	var n bool = true
	fmt.Println(n)        
	fmt.Printf("%T\n", n) 
	n = !n
	fmt.Println(n) 

	x := 5
	y := 8
	fmt.Println("x == y:", x == y) 
	fmt.Println("x < y:", x < y)   

	fmt.Println("\nConvert String into Boolean Data type\n")
	str1 := "japan"
	fmt.Println("Before :", reflect.TypeOf(str1)) 
	bolStr, _ := strconv.ParseBool(str1)
	fmt.Println("After :", reflect.TypeOf(bolStr)) 
}

Python: >>> True
True
>>> not True
False
>>> 
>>> False + 0
0
>>> True + 0
1
>>> False + 0j
0j
>>> True * 3.141
3.141
>>> 
>>> not 0
True
>>> not not 0
False
>>> not 1234
False
>>> bool(0.0)
False
>>> bool(0j)
False
>>> bool(1+2j)
True
>>> 
>>> bool([])
False
>>> bool([None])
True
>>> 'I contain something' if (None,) else 'I am empty'
'I contain something'
>>> bool({})
False
>>> bool("")
False
>>> bool("False")
True
Task: Boolean values
Go:  
package main

import (
	"fmt"
	"reflect"
	"strconv"
)

func main() {
	var n bool = true
	fmt.Println(n)        
	fmt.Printf("%T\n", n) 
	n = !n
	fmt.Println(n) 

	x := 5
	y := 8
	fmt.Println("x == y:", x == y) 
	fmt.Println("x < y:", x < y)   

	fmt.Println("\nConvert String into Boolean Data type\n")
	str1 := "japan"
	fmt.Println("Before :", reflect.TypeOf(str1)) 
	bolStr, _ := strconv.ParseBool(str1)
	fmt.Println("After :", reflect.TypeOf(bolStr)) 
}

VB: Dim a As Integer
Dim b As Boolean
Debug.Print b
a = b
Debug.Print a
b = True
Debug.Print b
a = b
Debug.Print a
Task: Boolean values
Python: >>> True
True
>>> not True
False
>>> 
>>> False + 0
0
>>> True + 0
1
>>> False + 0j
0j
>>> True * 3.141
3.141
>>> 
>>> not 0
True
>>> not not 0
False
>>> not 1234
False
>>> bool(0.0)
False
>>> bool(0j)
False
>>> bool(1+2j)
True
>>> 
>>> bool([])
False
>>> bool([None])
True
>>> 'I contain something' if (None,) else 'I am empty'
'I contain something'
>>> bool({})
False
>>> bool("")
False
>>> bool("False")
True

VB: Dim a As Integer
Dim b As Boolean
Debug.Print b
a = b
Debug.Print a
b = True
Debug.Print b
a = b
Debug.Print a
Task: Boolean values
C: int a = 0;
int b = 1;
int c;
string str1 = "initialized string";
string str2; 

if (a) {puts("first test a is false");}         
if (b) {puts("second test b is true");}         
if (c) {puts("third test b is false");}         
if (!defined(c)) {puts("fourth test is true");} 
if (str1) {puts("fifth test str1 is true");}    
if (str2) {puts("sixth test str2 is false");}   

Java: module GeorgeBoole
    {
    @Inject Console console;

    void run()
        {
        Boolean f = False;
        assert !f == True;

        
        
        assert True.and(False) == True & False == False;
        assert True.or(False)  == True | False == True;
        assert True.xor(False) == True ^ False == True;
        assert True.not() == ~True == False;

        console.print($"0==1 = {0==1}");
        console.print($"!False = {!False}");
        }
    }
Task: Boolean values
C: int a = 0;
int b = 1;
int c;
string str1 = "initialized string";
string str2; 

if (a) {puts("first test a is false");}         
if (b) {puts("second test b is true");}         
if (c) {puts("third test b is false");}         
if (!defined(c)) {puts("fourth test is true");} 
if (str1) {puts("fifth test str1 is true");}    
if (str2) {puts("sixth test str2 is false");}   

Python: >>> True
True
>>> not True
False
>>> 
>>> False + 0
0
>>> True + 0
1
>>> False + 0j
0j
>>> True * 3.141
3.141
>>> 
>>> not 0
True
>>> not not 0
False
>>> not 1234
False
>>> bool(0.0)
False
>>> bool(0j)
False
>>> bool(1+2j)
True
>>> 
>>> bool([])
False
>>> bool([None])
True
>>> 'I contain something' if (None,) else 'I am empty'
'I contain something'
>>> bool({})
False
>>> bool("")
False
>>> bool("False")
True
Task: Stair-climbing puzzle
C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}

C#: void step_up() {
    while (!step()) step_up();
}
Task: Stair-climbing puzzle
C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}

C++: void step_up()
{
  while (!step()) step_up();
}
Task: Stair-climbing puzzle
C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}

Go: func step_up(){for !step(){step_up()}}
Task: Stair-climbing puzzle
C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}

Java: public void stepUp() {
  while (!step()) stepUp();
}
Task: Stair-climbing puzzle
C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}

Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1
Task: Stair-climbing puzzle
C#: void step_up() {
    while (!step()) step_up();
}

C++: void step_up()
{
  while (!step()) step_up();
}
Task: Stair-climbing puzzle
C++: void step_up()
{
  while (!step()) step_up();
}

Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1
Task: Stair-climbing puzzle
C#: void step_up() {
    while (!step()) step_up();
}

Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1
Task: Stair-climbing puzzle
Go: func step_up(){for !step(){step_up()}}

Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1
Task: Stair-climbing puzzle
Java: public void stepUp() {
  while (!step()) stepUp();
}

Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1
Task: Dutch national flag problem
C: #include <stdio.h> 
#include <stdlib.h> 
#include <stdbool.h> 
#include <time.h> 

#define NUMBALLS 5 

int compar(const void *a, const void *b){
	char c1=*(const char*)a, c2=*(const char*)b; 
	return c1-c2;
}

_Bool issorted(char *balls){
	int i,state;
	state=0;
	for(i=0;i<NUMBALLS;i++){
		if(balls[i]<state)return false;
		if(balls[i]>state)state=balls[i];
	}
	return true;
}

void printout(char *balls){
	int i;
	char str[NUMBALLS+1];
	for(i=0;i<NUMBALLS;i++)str[i]=balls[i]==0?'r':balls[i]==1?'w':'b';
	printf("%s\n",str);
}

int main(void) {
	char balls[NUMBALLS]; 
	int i;
	srand(time(NULL)); 
	rand(); 
	        
	
	for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	while(issorted(balls)){ 
		printf("Accidentally still sorted: ");
		printout(balls);
		for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	}
	printf("Non-sorted: ");
	printout(balls);
	qsort(balls,NUMBALLS,sizeof(char),compar); 
	if(issorted(balls)){ 
		printf("Sorted: ");
		printout(balls);
	} else {
		printf("Sort failed: ");
		printout(balls);
	}
	return 0;
}

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


template <typename BidIt, typename T>
void dnf_partition(BidIt first, BidIt last, const T& low, const T& high)
{
    for (BidIt next = first; next != last; ) {
        if (*next < low) {
            std::iter_swap(first++, next++);
        } else if (!(*next < high)) {
            std::iter_swap(next, --last);
        } else {
            ++next;
        }
    }
}

enum Colors { RED, WHITE, BLUE };

void print(const Colors *balls, size_t size)
{
    static const char *label[] = { "red", "white", "blue" };

    std::cout << "Balls:";
    for (size_t i = 0; i < size; ++i) {
        std::cout << ' ' << label[balls[i]];
    }
    std::cout << "\nSorted: " << std::boolalpha << std::is_sorted(balls, balls + size) << '\n';
}

int main()
{
    Colors balls[] = { RED, WHITE, BLUE, RED, WHITE, BLUE, RED, WHITE, BLUE };

    std::random_shuffle(balls, balls + 9);
    print(balls, 9);

    dnf_partition(balls, balls + 9, WHITE, BLUE);
    print(balls, 9);
}
Task: Dutch national flag problem
C: #include <stdio.h> 
#include <stdlib.h> 
#include <stdbool.h> 
#include <time.h> 

#define NUMBALLS 5 

int compar(const void *a, const void *b){
	char c1=*(const char*)a, c2=*(const char*)b; 
	return c1-c2;
}

_Bool issorted(char *balls){
	int i,state;
	state=0;
	for(i=0;i<NUMBALLS;i++){
		if(balls[i]<state)return false;
		if(balls[i]>state)state=balls[i];
	}
	return true;
}

void printout(char *balls){
	int i;
	char str[NUMBALLS+1];
	for(i=0;i<NUMBALLS;i++)str[i]=balls[i]==0?'r':balls[i]==1?'w':'b';
	printf("%s\n",str);
}

int main(void) {
	char balls[NUMBALLS]; 
	int i;
	srand(time(NULL)); 
	rand(); 
	        
	
	for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	while(issorted(balls)){ 
		printf("Accidentally still sorted: ");
		printout(balls);
		for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	}
	printf("Non-sorted: ");
	printout(balls);
	qsort(balls,NUMBALLS,sizeof(char),compar); 
	if(issorted(balls)){ 
		printf("Sorted: ");
		printout(balls);
	} else {
		printf("Sort failed: ");
		printout(balls);
	}
	return 0;
}

Java: import java.util.Arrays;
import java.util.Random;

public class DutchNationalFlag {
    enum DutchColors {
        RED, WHITE, BLUE
    }

    public static void main(String[] args){
        DutchColors[] balls = new DutchColors[12];
        DutchColors[] values = DutchColors.values();
        Random rand = new Random();

        for (int i = 0; i < balls.length; i++)
            balls[i]=values[rand.nextInt(values.length)];
        System.out.println("Before: " + Arrays.toString(balls));

        Arrays.sort(balls);
        System.out.println("After:  " + Arrays.toString(balls));

        boolean sorted = true;
        for (int i = 1; i < balls.length; i++ ){
            if (balls[i-1].compareTo(balls[i]) > 0){
                sorted=false;
                break;
            }
        }
        System.out.println("Correctly sorted: " + sorted);
    }
}
Task: Dutch national flag problem
C: #include <stdio.h> 
#include <stdlib.h> 
#include <stdbool.h> 
#include <time.h> 

#define NUMBALLS 5 

int compar(const void *a, const void *b){
	char c1=*(const char*)a, c2=*(const char*)b; 
	return c1-c2;
}

_Bool issorted(char *balls){
	int i,state;
	state=0;
	for(i=0;i<NUMBALLS;i++){
		if(balls[i]<state)return false;
		if(balls[i]>state)state=balls[i];
	}
	return true;
}

void printout(char *balls){
	int i;
	char str[NUMBALLS+1];
	for(i=0;i<NUMBALLS;i++)str[i]=balls[i]==0?'r':balls[i]==1?'w':'b';
	printf("%s\n",str);
}

int main(void) {
	char balls[NUMBALLS]; 
	int i;
	srand(time(NULL)); 
	rand(); 
	        
	
	for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	while(issorted(balls)){ 
		printf("Accidentally still sorted: ");
		printout(balls);
		for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	}
	printf("Non-sorted: ");
	printout(balls);
	qsort(balls,NUMBALLS,sizeof(char),compar); 
	if(issorted(balls)){ 
		printf("Sorted: ");
		printout(balls);
	} else {
		printf("Sort failed: ");
		printout(balls);
	}
	return 0;
}

Python: import random

colours_in_order = 'Red White Blue'.split()

def dutch_flag_sort(items, order=colours_in_order):
    'return sort of items using the given order'
    reverse_index = dict((x,i) for i,x in enumerate(order))
    return sorted(items, key=lambda x: reverse_index[x])

def dutch_flag_check(items, order=colours_in_order):
    'Return True if each item of items is in the given order'
    reverse_index = dict((x,i) for i,x in enumerate(order))
    order_of_items = [reverse_index[item] for item in items]
    return all(x <= y for x, y in zip(order_of_items, order_of_items[1:]))

def random_balls(mx=5):
    'Select from 1 to mx balls of each colour, randomly'
    balls = sum([[colour] * random.randint(1, mx)
                 for colour in colours_in_order], [])
    random.shuffle(balls)
    return balls

def main():
    
    while True:
        balls = random_balls()
        if not dutch_flag_check(balls):
            break
    print("Original Ball order:", balls)
    sorted_balls = dutch_flag_sort(balls)
    print("Sorted Ball Order:", sorted_balls)
    assert dutch_flag_check(sorted_balls), 'Whoops. Not sorted!'

if __name__ == '__main__':
    main()
Task: Dutch national flag problem
C: #include <stdio.h> 
#include <stdlib.h> 
#include <stdbool.h> 
#include <time.h> 

#define NUMBALLS 5 

int compar(const void *a, const void *b){
	char c1=*(const char*)a, c2=*(const char*)b; 
	return c1-c2;
}

_Bool issorted(char *balls){
	int i,state;
	state=0;
	for(i=0;i<NUMBALLS;i++){
		if(balls[i]<state)return false;
		if(balls[i]>state)state=balls[i];
	}
	return true;
}

void printout(char *balls){
	int i;
	char str[NUMBALLS+1];
	for(i=0;i<NUMBALLS;i++)str[i]=balls[i]==0?'r':balls[i]==1?'w':'b';
	printf("%s\n",str);
}

int main(void) {
	char balls[NUMBALLS]; 
	int i;
	srand(time(NULL)); 
	rand(); 
	        
	
	for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	while(issorted(balls)){ 
		printf("Accidentally still sorted: ");
		printout(balls);
		for(i=0;i<NUMBALLS;i++)balls[i]=(double)rand()/RAND_MAX*3;
	}
	printf("Non-sorted: ");
	printout(balls);
	qsort(balls,NUMBALLS,sizeof(char),compar); 
	if(issorted(balls)){ 
		printf("Sorted: ");
		printout(balls);
	} else {
		printf("Sort failed: ");
		printout(balls);
	}
	return 0;
}

VB: 


Function build_unsort(n)
	flag = Array("red","white","blue")
	Set random = CreateObject("System.Random")
	Dim arr()
	ReDim arr(n)
	For i = 0 To n
		arr(i) = flag(random.Next_2(0,3))
	Next
	build_unsort = arr
End Function


Function sort(arr)
	lo = 0
	mi = 0
	hi = UBound(arr)
	Do While mi <= hi 
		Select Case arr(mi)
			Case "red"
				tmp = arr(lo)
				arr(lo) = arr(mi)
				arr(mi) = tmp
				lo = lo + 1
				mi = mi + 1
			Case "white"
				mi = mi + 1
			Case "blue"
				tmp = arr(mi)
				arr(mi) = arr(hi)
				arr(hi) = tmp
				hi = hi - 1
		End Select 
	Loop
	sort = Join(arr,",")
End Function

unsort = build_unsort(11)
WScript.StdOut.Write "Unsorted: " & Join(unsort,",")
WScript.StdOut.WriteLine
WScript.StdOut.Write "Sorted: " & sort(unsort)
WScript.StdOut.WriteLine
Task: Dutch national flag problem
C++: #include <algorithm>
#include <iostream>


template <typename BidIt, typename T>
void dnf_partition(BidIt first, BidIt last, const T& low, const T& high)
{
    for (BidIt next = first; next != last; ) {
        if (*next < low) {
            std::iter_swap(first++, next++);
        } else if (!(*next < high)) {
            std::iter_swap(next, --last);
        } else {
            ++next;
        }
    }
}

enum Colors { RED, WHITE, BLUE };

void print(const Colors *balls, size_t size)
{
    static const char *label[] = { "red", "white", "blue" };

    std::cout << "Balls:";
    for (size_t i = 0; i < size; ++i) {
        std::cout << ' ' << label[balls[i]];
    }
    std::cout << "\nSorted: " << std::boolalpha << std::is_sorted(balls, balls + size) << '\n';
}

int main()
{
    Colors balls[] = { RED, WHITE, BLUE, RED, WHITE, BLUE, RED, WHITE, BLUE };

    std::random_shuffle(balls, balls + 9);
    print(balls, 9);

    dnf_partition(balls, balls + 9, WHITE, BLUE);
    print(balls, 9);
}

Java: import java.util.Arrays;
import java.util.Random;

public class DutchNationalFlag {
    enum DutchColors {
        RED, WHITE, BLUE
    }

    public static void main(String[] args){
        DutchColors[] balls = new DutchColors[12];
        DutchColors[] values = DutchColors.values();
        Random rand = new Random();

        for (int i = 0; i < balls.length; i++)
            balls[i]=values[rand.nextInt(values.length)];
        System.out.println("Before: " + Arrays.toString(balls));

        Arrays.sort(balls);
        System.out.println("After:  " + Arrays.toString(balls));

        boolean sorted = true;
        for (int i = 1; i < balls.length; i++ ){
            if (balls[i-1].compareTo(balls[i]) > 0){
                sorted=false;
                break;
            }
        }
        System.out.println("Correctly sorted: " + sorted);
    }
}
Task: Dutch national flag problem
C++: #include <algorithm>
#include <iostream>


template <typename BidIt, typename T>
void dnf_partition(BidIt first, BidIt last, const T& low, const T& high)
{
    for (BidIt next = first; next != last; ) {
        if (*next < low) {
            std::iter_swap(first++, next++);
        } else if (!(*next < high)) {
            std::iter_swap(next, --last);
        } else {
            ++next;
        }
    }
}

enum Colors { RED, WHITE, BLUE };

void print(const Colors *balls, size_t size)
{
    static const char *label[] = { "red", "white", "blue" };

    std::cout << "Balls:";
    for (size_t i = 0; i < size; ++i) {
        std::cout << ' ' << label[balls[i]];
    }
    std::cout << "\nSorted: " << std::boolalpha << std::is_sorted(balls, balls + size) << '\n';
}

int main()
{
    Colors balls[] = { RED, WHITE, BLUE, RED, WHITE, BLUE, RED, WHITE, BLUE };

    std::random_shuffle(balls, balls + 9);
    print(balls, 9);

    dnf_partition(balls, balls + 9, WHITE, BLUE);
    print(balls, 9);
}

Python: import random

colours_in_order = 'Red White Blue'.split()

def dutch_flag_sort(items, order=colours_in_order):
    'return sort of items using the given order'
    reverse_index = dict((x,i) for i,x in enumerate(order))
    return sorted(items, key=lambda x: reverse_index[x])

def dutch_flag_check(items, order=colours_in_order):
    'Return True if each item of items is in the given order'
    reverse_index = dict((x,i) for i,x in enumerate(order))
    order_of_items = [reverse_index[item] for item in items]
    return all(x <= y for x, y in zip(order_of_items, order_of_items[1:]))

def random_balls(mx=5):
    'Select from 1 to mx balls of each colour, randomly'
    balls = sum([[colour] * random.randint(1, mx)
                 for colour in colours_in_order], [])
    random.shuffle(balls)
    return balls

def main():
    
    while True:
        balls = random_balls()
        if not dutch_flag_check(balls):
            break
    print("Original Ball order:", balls)
    sorted_balls = dutch_flag_sort(balls)
    print("Sorted Ball Order:", sorted_balls)
    assert dutch_flag_check(sorted_balls), 'Whoops. Not sorted!'

if __name__ == '__main__':
    main()
Task: Dutch national flag problem
C++: #include <algorithm>
#include <iostream>


template <typename BidIt, typename T>
void dnf_partition(BidIt first, BidIt last, const T& low, const T& high)
{
    for (BidIt next = first; next != last; ) {
        if (*next < low) {
            std::iter_swap(first++, next++);
        } else if (!(*next < high)) {
            std::iter_swap(next, --last);
        } else {
            ++next;
        }
    }
}

enum Colors { RED, WHITE, BLUE };

void print(const Colors *balls, size_t size)
{
    static const char *label[] = { "red", "white", "blue" };

    std::cout << "Balls:";
    for (size_t i = 0; i < size; ++i) {
        std::cout << ' ' << label[balls[i]];
    }
    std::cout << "\nSorted: " << std::boolalpha << std::is_sorted(balls, balls + size) << '\n';
}

int main()
{
    Colors balls[] = { RED, WHITE, BLUE, RED, WHITE, BLUE, RED, WHITE, BLUE };

    std::random_shuffle(balls, balls + 9);
    print(balls, 9);

    dnf_partition(balls, balls + 9, WHITE, BLUE);
    print(balls, 9);
}

VB: 


Function build_unsort(n)
	flag = Array("red","white","blue")
	Set random = CreateObject("System.Random")
	Dim arr()
	ReDim arr(n)
	For i = 0 To n
		arr(i) = flag(random.Next_2(0,3))
	Next
	build_unsort = arr
End Function


Function sort(arr)
	lo = 0
	mi = 0
	hi = UBound(arr)
	Do While mi <= hi 
		Select Case arr(mi)
			Case "red"
				tmp = arr(lo)
				arr(lo) = arr(mi)
				arr(mi) = tmp
				lo = lo + 1
				mi = mi + 1
			Case "white"
				mi = mi + 1
			Case "blue"
				tmp = arr(mi)
				arr(mi) = arr(hi)
				arr(hi) = tmp
				hi = hi - 1
		End Select 
	Loop
	sort = Join(arr,",")
End Function

unsort = build_unsort(11)
WScript.StdOut.Write "Unsorted: " & Join(unsort,",")
WScript.StdOut.WriteLine
WScript.StdOut.Write "Sorted: " & sort(unsort)
WScript.StdOut.WriteLine