WeixiangYan/CodeTransOcean huggingface dataset:
Task: Password generator




Go: package main

import (
	"crypto/rand"
	"math/big"
	"strings"
	"flag"
	"math"
        "fmt" 
)

var lowercase = "abcdefghijklmnopqrstuvwxyz"
var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var numbers = "0123456789"
var signs = "!\"#$%&'()*+,-./:;<=>?@[]^_{|}~"
var similar = "Il1O05S2Z"

func check(e error){
	if e != nil {
		panic(e)
	}
}

func randstr(length int, alphastr string) string{
	alphabet := []byte(alphastr)
	pass := make([]byte,length)
	for i := 0; i < length; i++ {
		bign, err := rand.Int(rand.Reader, big.NewInt(int64(len(alphabet))))
		check(err)
		n := bign.Int64()
		pass[i] = alphabet[n]
	}
	return string(pass)
}

func verify(pass string,checkUpper bool,checkLower bool, checkNumber bool, checkSign bool) bool{
	isValid := true
	if(checkUpper){
		isValid = isValid && strings.ContainsAny(pass,uppercase)
	}
	if(checkLower){
		isValid = isValid && strings.ContainsAny(pass,lowercase)
	}
	if(checkNumber){
		isValid = isValid && strings.ContainsAny(pass,numbers)
	}
	if(checkSign){
		isValid = isValid && strings.ContainsAny(pass,signs)
	}
	return isValid
}


func main() {
	passCount := flag.Int("pc", 6, "Number of passwords")
	passLength := flag.Int("pl", 10, "Passwordlength")
	useUpper := flag.Bool("upper", true, "Enables or disables uppercase letters")
	useLower := flag.Bool("lower", true, "Enables or disables lowercase letters")
	useSign := flag.Bool("sign", true, "Enables or disables signs")
	useNumbers := flag.Bool("number", true, "Enables or disables numbers")
	useSimilar := flag.Bool("similar", true,"Enables or disables visually similar characters")
	flag.Parse()

	passAlphabet := ""
	if *useUpper {
		passAlphabet += uppercase
	}
	if *useLower {
		passAlphabet += lowercase
	}
	if *useSign {
		passAlphabet += signs
	}
	if *useNumbers {
		passAlphabet += numbers
	}
	if !*useSimilar {
		for _, r := range similar{
			passAlphabet = strings.Replace(passAlphabet,string(r),"", 1)
		}
	}
	fmt.Printf("Generating passwords with an average entropy of %.1f bits \n", math.Log2(float64(len(passAlphabet))) * float64(*passLength))
	for i := 0; i < *passCount;i++{
		passFound := false
		pass := ""
		for(!passFound){
			pass = randstr(*passLength,passAlphabet)
			passFound = verify(pass,*useUpper,*useLower,*useNumbers,*useSign)
		}
		fmt.Println(pass)
	}
}
Task: Largest int from concatenated ints



C#: using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var source1 = new int[] { 1, 34, 3, 98, 9, 76, 45, 4 };
        var source2 = new int[] { 54, 546, 548, 60 };

        var largest1 = LargestPossibleSequence(source1);
        var largest2 = LargestPossibleSequence(source2);

        Console.WriteLine("The largest possible integer from set 1 is: {0}", largest1);
        Console.WriteLine("The largest possible integer from set 2 is: {0}", largest2);
    }

    static long LargestPossibleSequence(int[] ints)
    {
        return long.Parse(string.Join("", ints.OrderBy(i => i, new IntConcatenationComparer()).Reverse()));
    }
}

class IntConcatenationComparer : IComparer<int>
{
    public int Compare(int x, int y)
    {
        var xy = int.Parse(x.ToString() + y.ToString());
        var yx = int.Parse(y.ToString() + x.ToString());

        return xy - yx;
    }
}









Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Largest int from concatenated ints

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

int catcmp(const void *a, const void *b)
{
	char ab[32], ba[32];
	sprintf(ab, "%d%d", *(int*)a, *(int*)b);
	sprintf(ba, "%d%d", *(int*)b, *(int*)a);
	return strcmp(ba, ab);
}

void maxcat(int *a, int len)
{
	int i;
	qsort(a, len, sizeof(int), catcmp);
	for (i = 0; i < len; i++)
		printf("%d", a[i]);
	putchar('\n');
}

int main(void)
{
	int x[] = {1, 34, 3, 98, 9, 76, 45, 4};
	int y[] = {54, 546, 548, 60};

	maxcat(x, sizeof(x)/sizeof(x[0]));
	maxcat(y, sizeof(y)/sizeof(y[0]));

	return 0;
}











Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Largest int from concatenated ints


C++: #include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>

std::string findLargestConcat ( std::vector< int > & mynumbers ) {
   std::vector<std::string> concatnumbers ;
   std::sort ( mynumbers.begin( ) , mynumbers.end( ) ) ;
   do {
      std::ostringstream numberstream ;
      for ( int i : mynumbers ) 
	 numberstream << i ;
      concatnumbers.push_back( numberstream.str( ) ) ;
   } while ( std::next_permutation( mynumbers.begin( ) ,
	    mynumbers.end( ) )) ;
   return *( std::max_element( concatnumbers.begin( ) ,
	 concatnumbers.end( ) ) ) ;
}

int main( ) {
   std::vector<int> mynumbers = { 98, 76 , 45 , 34, 9 , 4 , 3 , 1 } ;
   std::vector<int> othernumbers = { 54 , 546 , 548 , 60 } ;
   std::cout << "The largest concatenated int is " <<
      findLargestConcat( mynumbers ) << " !\n" ;
   std::cout << "And here it is " << findLargestConcat( othernumbers ) 
      << " !\n" ;
   return 0 ;
}










Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Largest int from concatenated ints




Go: 

package main

import (
    "fmt"
    "math/big"
    "sort"
    "strconv"
    "strings"
)

type c struct {
    i     int
    s, rs string
}

type cc []*c

func (c cc) Len() int           { return len(c) }
func (c cc) Less(i, j int) bool { return c[j].rs < c[i].rs }
func (c cc) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }


func li(is ...int) *big.Int {
    ps := make(cc, len(is))
    ss := make([]c, len(is))
    ml := 0
    for j, i := range is {
        p := &ss[j]
        ps[j] = p
        p.i = i
        p.s = strconv.Itoa(i)
        if len(p.s) > ml {
            ml = len(p.s)
        }
    }
    for _, p := range ps {
        p.rs = strings.Repeat(p.s, (ml+len(p.s)-1)/len(p.s))
    }
    sort.Sort(ps)
    s := make([]string, len(ps))
    for i, p := range ps {
        s[i] = p.s
    }
    b, _ := new(big.Int).SetString(strings.Join(s, ""), 10)
    return b
}

func main() {
    fmt.Println(li(1, 34, 3, 98, 9, 76, 45, 4))
    fmt.Println(li(54, 546, 548, 60))
}








Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Largest int from concatenated ints





Java: import java.util.*;

public class IntConcat {
 
    private static Comparator<Integer> sorter = new Comparator<Integer>(){
        @Override
        public int compare(Integer o1, Integer o2){
            String o1s = o1.toString();
            String o2s = o2.toString();
            
            if(o1s.length() == o2s.length()){
                return o2s.compareTo(o1s);
            }

            int mlen = Math.max(o1s.length(), o2s.length());
            while(o1s.length() < mlen * 2) o1s += o1s;
            while(o2s.length() < mlen * 2) o2s += o2s;
            
            return o2s.compareTo(o1s);
        }
    };
    
    public static String join(List<?> things){
        String output = "";
        for(Object obj:things){
            output += obj;
        }
        return output;
    }
    
    public static void main(String[] args){
        List<Integer> ints1 = new ArrayList<Integer>(Arrays.asList(1, 34, 3, 98, 9, 76, 45, 4));
        
        Collections.sort(ints1, sorter);
        System.out.println(join(ints1));
        
        List<Integer> ints2 = new ArrayList<Integer>(Arrays.asList(54, 546, 548, 60));
        
        Collections.sort(ints2, sorter);
        System.out.println(join(ints2));
    }
}







Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Largest int from concatenated ints







Python: try:
    cmp     
    def maxnum(x):
        return ''.join(sorted((str(n) for n in x),
                              cmp=lambda x,y:cmp(y+x, x+y)))
except NameError:
    
    from functools import cmp_to_key
    def cmp(x, y):
        return -1 if x<y else ( 0 if x==y else 1)
    def maxnum(x):
        return ''.join(sorted((str(n) for n in x),
                              key=cmp_to_key(lambda x,y:cmp(y+x, x+y))))

for numbers in [(1, 34, 3, 98, 9, 76, 45, 4), (54, 546, 548, 60)]:
    print('Numbers: %r\n  Largest integer: %15s' % (numbers, maxnum(numbers)))





Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Largest int from concatenated ints








VB: Function largestint(list)
	nums = Split(list,",")
	Do Until IsSorted = True
		IsSorted = True
		For i = 0 To UBound(nums)
			If i <> UBound(nums) Then
				a = nums(i)
				b = nums(i+1)
				If CLng(a&b) < CLng(b&a) Then
					tmpnum = nums(i)
					nums(i) = nums(i+1)
					nums(i+1) = tmpnum
					IsSorted = False
				End If
			End If
		Next
	Loop
	For j = 0 To UBound(nums)
		largestint = largestint & nums(j)
	Next
End Function

WScript.StdOut.Write largestint(WScript.Arguments(0))
WScript.StdOut.WriteLine




Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Largest int from concatenated ints

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

int catcmp(const void *a, const void *b)
{
	char ab[32], ba[32];
	sprintf(ab, "%d%d", *(int*)a, *(int*)b);
	sprintf(ba, "%d%d", *(int*)b, *(int*)a);
	return strcmp(ba, ab);
}

void maxcat(int *a, int len)
{
	int i;
	qsort(a, len, sizeof(int), catcmp);
	for (i = 0; i < len; i++)
		printf("%d", a[i]);
	putchar('\n');
}

int main(void)
{
	int x[] = {1, 34, 3, 98, 9, 76, 45, 4};
	int y[] = {54, 546, 548, 60};

	maxcat(x, sizeof(x)/sizeof(x[0]));
	maxcat(y, sizeof(y)/sizeof(y[0]));

	return 0;
}
Task: Largest int from concatenated ints



C#: using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var source1 = new int[] { 1, 34, 3, 98, 9, 76, 45, 4 };
        var source2 = new int[] { 54, 546, 548, 60 };

        var largest1 = LargestPossibleSequence(source1);
        var largest2 = LargestPossibleSequence(source2);

        Console.WriteLine("The largest possible integer from set 1 is: {0}", largest1);
        Console.WriteLine("The largest possible integer from set 2 is: {0}", largest2);
    }

    static long LargestPossibleSequence(int[] ints)
    {
        return long.Parse(string.Join("", ints.OrderBy(i => i, new IntConcatenationComparer()).Reverse()));
    }
}

class IntConcatenationComparer : IComparer<int>
{
    public int Compare(int x, int y)
    {
        var xy = int.Parse(x.ToString() + y.ToString());
        var yx = int.Parse(y.ToString() + x.ToString());

        return xy - yx;
    }
}
Task: Largest int from concatenated ints


C++: #include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>

std::string findLargestConcat ( std::vector< int > & mynumbers ) {
   std::vector<std::string> concatnumbers ;
   std::sort ( mynumbers.begin( ) , mynumbers.end( ) ) ;
   do {
      std::ostringstream numberstream ;
      for ( int i : mynumbers ) 
	 numberstream << i ;
      concatnumbers.push_back( numberstream.str( ) ) ;
   } while ( std::next_permutation( mynumbers.begin( ) ,
	    mynumbers.end( ) )) ;
   return *( std::max_element( concatnumbers.begin( ) ,
	 concatnumbers.end( ) ) ) ;
}

int main( ) {
   std::vector<int> mynumbers = { 98, 76 , 45 , 34, 9 , 4 , 3 , 1 } ;
   std::vector<int> othernumbers = { 54 , 546 , 548 , 60 } ;
   std::cout << "The largest concatenated int is " <<
      findLargestConcat( mynumbers ) << " !\n" ;
   std::cout << "And here it is " << findLargestConcat( othernumbers ) 
      << " !\n" ;
   return 0 ;
}
Task: Largest int from concatenated ints





Java: import java.util.*;

public class IntConcat {
 
    private static Comparator<Integer> sorter = new Comparator<Integer>(){
        @Override
        public int compare(Integer o1, Integer o2){
            String o1s = o1.toString();
            String o2s = o2.toString();
            
            if(o1s.length() == o2s.length()){
                return o2s.compareTo(o1s);
            }

            int mlen = Math.max(o1s.length(), o2s.length());
            while(o1s.length() < mlen * 2) o1s += o1s;
            while(o2s.length() < mlen * 2) o2s += o2s;
            
            return o2s.compareTo(o1s);
        }
    };
    
    public static String join(List<?> things){
        String output = "";
        for(Object obj:things){
            output += obj;
        }
        return output;
    }
    
    public static void main(String[] args){
        List<Integer> ints1 = new ArrayList<Integer>(Arrays.asList(1, 34, 3, 98, 9, 76, 45, 4));
        
        Collections.sort(ints1, sorter);
        System.out.println(join(ints1));
        
        List<Integer> ints2 = new ArrayList<Integer>(Arrays.asList(54, 546, 548, 60));
        
        Collections.sort(ints2, sorter);
        System.out.println(join(ints2));
    }
}
Task: Largest int from concatenated ints







Python: try:
    cmp     
    def maxnum(x):
        return ''.join(sorted((str(n) for n in x),
                              cmp=lambda x,y:cmp(y+x, x+y)))
except NameError:
    
    from functools import cmp_to_key
    def cmp(x, y):
        return -1 if x<y else ( 0 if x==y else 1)
    def maxnum(x):
        return ''.join(sorted((str(n) for n in x),
                              key=cmp_to_key(lambda x,y:cmp(y+x, x+y))))

for numbers in [(1, 34, 3, 98, 9, 76, 45, 4), (54, 546, 548, 60)]:
    print('Numbers: %r\n  Largest integer: %15s' % (numbers, maxnum(numbers)))
Task: Largest int from concatenated ints








VB: Function largestint(list)
	nums = Split(list,",")
	Do Until IsSorted = True
		IsSorted = True
		For i = 0 To UBound(nums)
			If i <> UBound(nums) Then
				a = nums(i)
				b = nums(i+1)
				If CLng(a&b) < CLng(b&a) Then
					tmpnum = nums(i)
					nums(i) = nums(i+1)
					nums(i+1) = tmpnum
					IsSorted = False
				End If
			End If
		Next
	Loop
	For j = 0 To UBound(nums)
		largestint = largestint & nums(j)
	Next
End Function

WScript.StdOut.Write largestint(WScript.Arguments(0))
WScript.StdOut.WriteLine
Task: Largest int from concatenated ints




Go: 

package main

import (
    "fmt"
    "math/big"
    "sort"
    "strconv"
    "strings"
)

type c struct {
    i     int
    s, rs string
}

type cc []*c

func (c cc) Len() int           { return len(c) }
func (c cc) Less(i, j int) bool { return c[j].rs < c[i].rs }
func (c cc) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }


func li(is ...int) *big.Int {
    ps := make(cc, len(is))
    ss := make([]c, len(is))
    ml := 0
    for j, i := range is {
        p := &ss[j]
        ps[j] = p
        p.i = i
        p.s = strconv.Itoa(i)
        if len(p.s) > ml {
            ml = len(p.s)
        }
    }
    for _, p := range ps {
        p.rs = strings.Repeat(p.s, (ml+len(p.s)-1)/len(p.s))
    }
    sort.Sort(ps)
    s := make([]string, len(ps))
    for i, p := range ps {
        s[i] = p.s
    }
    b, _ := new(big.Int).SetString(strings.Join(s, ""), 10)
    return b
}

func main() {
    fmt.Println(li(1, 34, 3, 98, 9, 76, 45, 4))
    fmt.Println(li(54, 546, 548, 60))
}
Task: Largest int from concatenated ints



C#: using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var source1 = new int[] { 1, 34, 3, 98, 9, 76, 45, 4 };
        var source2 = new int[] { 54, 546, 548, 60 };

        var largest1 = LargestPossibleSequence(source1);
        var largest2 = LargestPossibleSequence(source2);

        Console.WriteLine("The largest possible integer from set 1 is: {0}", largest1);
        Console.WriteLine("The largest possible integer from set 2 is: {0}", largest2);
    }

    static long LargestPossibleSequence(int[] ints)
    {
        return long.Parse(string.Join("", ints.OrderBy(i => i, new IntConcatenationComparer()).Reverse()));
    }
}

class IntConcatenationComparer : IComparer<int>
{
    public int Compare(int x, int y)
    {
        var xy = int.Parse(x.ToString() + y.ToString());
        var yx = int.Parse(y.ToString() + x.ToString());

        return xy - yx;
    }
}








Fortran:       SUBROUTINE SWAP(A,B)	
       INTEGER A,B,T
        T = B
        B = A
        A = T
      END

      SUBROUTINE BIGUP(TEXT,N)	
       CHARACTER*(*) TEXT(*)	
       INTEGER N		
       INTEGER XLAT(N),L(N)	
       INTEGER I,J,M		
       INTEGER TI,TJ		
       INTEGER LI,LJ		
       INTEGER MSG		
       COMMON /IODEV/ MSG	
        DO I = 1,N	
          XLAT(I) = I		
          L(I) = LEN_TRIM(TEXT(I))	
        END DO		
        WRITE (MSG,1) "Supplied",(TEXT(I)(1:L(I)), I = 1,N)	
    1   FORMAT (A12,":",<N>(A,","))	
Crude bubblesort. No attempt at noting the bounds of swaps made.
        DO M = N,1,-1	
          DO I = 2,M		
            J = I - 1		
            TI = XLAT(I)	
            TJ = XLAT(J)	
            LI = L(TI)		
            LJ = L(TJ)		
            IF (LI .EQ. LJ) THEN	
              IF (TEXT(TI).LT.TEXT(TJ)) CALL SWAP(XLAT(I),XLAT(J))	
             ELSE	
              IF (TEXT(TI)(1:LI)//TEXT(TJ)(1:LJ)	
     1        .LT.TEXT(TJ)(1:LJ)//TEXT(TI)(1:LI))	
     2        CALL SWAP(XLAT(I),XLAT(J))	
            END IF			
          END DO		
        END DO	
        WRITE (MSG,2) "Biggest",(TEXT(XLAT(I))(1:L(XLAT(I))),I = N,1,-1)	
    2   FORMAT (A12,":",<N>(A," "))	
      END	

      PROGRAM POKE
      CHARACTER*4 T1(10)	
      CHARACTER*4 T2(4)		
      INTEGER MSG
      COMMON /IODEV/ MSG
      DATA T1(1:8)/"1","34","3","98","9","76","45","4"/
      DATA T2/"54","546","548","60"/
      MSG = 6		
      WRITE (MSG,1)
    1 FORMAT ("Takes a list of integers and concatenates them so as ",
     1 "to produce the biggest possible number.",/,
     2 "The result is shown with spaces between the parts ",
     3 "to show provenance. Ignore them otherwise."/)
      CALL BIGUP(T1,8)

      WRITE (MSG,*)
      CALL BIGUP(T2,4)

      WRITE (MSG,*) "These are supplied in lexicographical order..."
      CALL BIGUP((/"5","54"/),2)

      WRITE (MSG,*) "But this is not necessarily the biggest order."
      CALL BIGUP((/"5","56"/),2)

      WRITE (MSG,*) "And for those who count..."
      DO I = 1,10
        WRITE (T1(I),"(I0)") I	
      END DO			
      CALL BIGUP(T1,10)
      END
Task: Largest int from concatenated ints


C++: #include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>

std::string findLargestConcat ( std::vector< int > & mynumbers ) {
   std::vector<std::string> concatnumbers ;
   std::sort ( mynumbers.begin( ) , mynumbers.end( ) ) ;
   do {
      std::ostringstream numberstream ;
      for ( int i : mynumbers ) 
	 numberstream << i ;
      concatnumbers.push_back( numberstream.str( ) ) ;
   } while ( std::next_permutation( mynumbers.begin( ) ,
	    mynumbers.end( ) )) ;
   return *( std::max_element( concatnumbers.begin( ) ,
	 concatnumbers.end( ) ) ) ;
}

int main( ) {
   std::vector<int> mynumbers = { 98, 76 , 45 , 34, 9 , 4 , 3 , 1 } ;
   std::vector<int> othernumbers = { 54 , 546 , 548 , 60 } ;
   std::cout << "The largest concatenated int is " <<
      findLargestConcat( mynumbers ) << " !\n" ;
   std::cout << "And here it is " << findLargestConcat( othernumbers ) 
      << " !\n" ;
   return 0 ;
}









Fortran:       SUBROUTINE SWAP(A,B)	
       INTEGER A,B,T
        T = B
        B = A
        A = T
      END

      SUBROUTINE BIGUP(TEXT,N)	
       CHARACTER*(*) TEXT(*)	
       INTEGER N		
       INTEGER XLAT(N),L(N)	
       INTEGER I,J,M		
       INTEGER TI,TJ		
       INTEGER LI,LJ		
       INTEGER MSG		
       COMMON /IODEV/ MSG	
        DO I = 1,N	
          XLAT(I) = I		
          L(I) = LEN_TRIM(TEXT(I))	
        END DO		
        WRITE (MSG,1) "Supplied",(TEXT(I)(1:L(I)), I = 1,N)	
    1   FORMAT (A12,":",<N>(A,","))	
Crude bubblesort. No attempt at noting the bounds of swaps made.
        DO M = N,1,-1	
          DO I = 2,M		
            J = I - 1		
            TI = XLAT(I)	
            TJ = XLAT(J)	
            LI = L(TI)		
            LJ = L(TJ)		
            IF (LI .EQ. LJ) THEN	
              IF (TEXT(TI).LT.TEXT(TJ)) CALL SWAP(XLAT(I),XLAT(J))	
             ELSE	
              IF (TEXT(TI)(1:LI)//TEXT(TJ)(1:LJ)	
     1        .LT.TEXT(TJ)(1:LJ)//TEXT(TI)(1:LI))	
     2        CALL SWAP(XLAT(I),XLAT(J))	
            END IF			
          END DO		
        END DO	
        WRITE (MSG,2) "Biggest",(TEXT(XLAT(I))(1:L(XLAT(I))),I = N,1,-1)	
    2   FORMAT (A12,":",<N>(A," "))	
      END	

      PROGRAM POKE
      CHARACTER*4 T1(10)	
      CHARACTER*4 T2(4)		
      INTEGER MSG
      COMMON /IODEV/ MSG
      DATA T1(1:8)/"1","34","3","98","9","76","45","4"/
      DATA T2/"54","546","548","60"/
      MSG = 6		
      WRITE (MSG,1)
    1 FORMAT ("Takes a list of integers and concatenates them so as ",
     1 "to produce the biggest possible number.",/,
     2 "The result is shown with spaces between the parts ",
     3 "to show provenance. Ignore them otherwise."/)
      CALL BIGUP(T1,8)

      WRITE (MSG,*)
      CALL BIGUP(T2,4)

      WRITE (MSG,*) "These are supplied in lexicographical order..."
      CALL BIGUP((/"5","54"/),2)

      WRITE (MSG,*) "But this is not necessarily the biggest order."
      CALL BIGUP((/"5","56"/),2)

      WRITE (MSG,*) "And for those who count..."
      DO I = 1,10
        WRITE (T1(I),"(I0)") I	
      END DO			
      CALL BIGUP(T1,10)
      END
Task: Largest int from concatenated ints

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

int catcmp(const void *a, const void *b)
{
	char ab[32], ba[32];
	sprintf(ab, "%d%d", *(int*)a, *(int*)b);
	sprintf(ba, "%d%d", *(int*)b, *(int*)a);
	return strcmp(ba, ab);
}

void maxcat(int *a, int len)
{
	int i;
	qsort(a, len, sizeof(int), catcmp);
	for (i = 0; i < len; i++)
		printf("%d", a[i]);
	putchar('\n');
}

int main(void)
{
	int x[] = {1, 34, 3, 98, 9, 76, 45, 4};
	int y[] = {54, 546, 548, 60};

	maxcat(x, sizeof(x)/sizeof(x[0]));
	maxcat(y, sizeof(y)/sizeof(y[0]));

	return 0;
}










Fortran:       SUBROUTINE SWAP(A,B)	
       INTEGER A,B,T
        T = B
        B = A
        A = T
      END

      SUBROUTINE BIGUP(TEXT,N)	
       CHARACTER*(*) TEXT(*)	
       INTEGER N		
       INTEGER XLAT(N),L(N)	
       INTEGER I,J,M		
       INTEGER TI,TJ		
       INTEGER LI,LJ		
       INTEGER MSG		
       COMMON /IODEV/ MSG	
        DO I = 1,N	
          XLAT(I) = I		
          L(I) = LEN_TRIM(TEXT(I))	
        END DO		
        WRITE (MSG,1) "Supplied",(TEXT(I)(1:L(I)), I = 1,N)	
    1   FORMAT (A12,":",<N>(A,","))	
Crude bubblesort. No attempt at noting the bounds of swaps made.
        DO M = N,1,-1	
          DO I = 2,M		
            J = I - 1		
            TI = XLAT(I)	
            TJ = XLAT(J)	
            LI = L(TI)		
            LJ = L(TJ)		
            IF (LI .EQ. LJ) THEN	
              IF (TEXT(TI).LT.TEXT(TJ)) CALL SWAP(XLAT(I),XLAT(J))	
             ELSE	
              IF (TEXT(TI)(1:LI)//TEXT(TJ)(1:LJ)	
     1        .LT.TEXT(TJ)(1:LJ)//TEXT(TI)(1:LI))	
     2        CALL SWAP(XLAT(I),XLAT(J))	
            END IF			
          END DO		
        END DO	
        WRITE (MSG,2) "Biggest",(TEXT(XLAT(I))(1:L(XLAT(I))),I = N,1,-1)	
    2   FORMAT (A12,":",<N>(A," "))	
      END	

      PROGRAM POKE
      CHARACTER*4 T1(10)	
      CHARACTER*4 T2(4)		
      INTEGER MSG
      COMMON /IODEV/ MSG
      DATA T1(1:8)/"1","34","3","98","9","76","45","4"/
      DATA T2/"54","546","548","60"/
      MSG = 6		
      WRITE (MSG,1)
    1 FORMAT ("Takes a list of integers and concatenates them so as ",
     1 "to produce the biggest possible number.",/,
     2 "The result is shown with spaces between the parts ",
     3 "to show provenance. Ignore them otherwise."/)
      CALL BIGUP(T1,8)

      WRITE (MSG,*)
      CALL BIGUP(T2,4)

      WRITE (MSG,*) "These are supplied in lexicographical order..."
      CALL BIGUP((/"5","54"/),2)

      WRITE (MSG,*) "But this is not necessarily the biggest order."
      CALL BIGUP((/"5","56"/),2)

      WRITE (MSG,*) "And for those who count..."
      DO I = 1,10
        WRITE (T1(I),"(I0)") I	
      END DO			
      CALL BIGUP(T1,10)
      END