WeixiangYan/CodeTransOcean huggingface dataset:
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)))




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






PHP: function maxnum($nums) {
    usort($nums,  function ($x, $y) { return strcmp("$y$x", "$x$y"); });
    return implode('', $nums);
}

echo maxnum(array(1, 34, 3, 98, 9, 76, 45, 4)), "\n";
echo maxnum(array(54, 546, 548, 60)), "\n";





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






PHP: function maxnum($nums) {
    usort($nums,  function ($x, $y) { return strcmp("$y$x", "$x$y"); });
    return implode('', $nums);
}

echo maxnum(array(1, 34, 3, 98, 9, 76, 45, 4)), "\n";
echo maxnum(array(54, 546, 548, 60)), "\n";
Task: Largest int from concatenated ints






PHP: function maxnum($nums) {
    usort($nums,  function ($x, $y) { return strcmp("$y$x", "$x$y"); });
    return implode('', $nums);
}

echo maxnum(array(1, 34, 3, 98, 9, 76, 45, 4)), "\n";
echo maxnum(array(54, 546, 548, 60)), "\n";






Ada: function Order(Left, Right: Natural) return Boolean is
      ( (Img(Left) & Img(Right)) > (Img(Right) & Img(Left)) );
Task: Maximum triangle path sum



C#: using System;

namespace RosetaCode
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int[,] list = new int[18,19];
			string input = @"55
	                        94 48
	                       95 30 96
	                     77 71 26 67
	                    97 13 76 38 45
	                  07 36 79 16 37 68
	                 48 07 09 18 70 26 06
	               18 72 79 46 59 79 29 90
	              20 76 87 11 32 07 07 49 18
	            27 83 58 35 71 11 25 57 29 85
	           14 64 36 96 27 11 58 56 92 18 55
	         02 90 03 60 48 49 41 46 33 36 47 23
	        92 50 48 02 36 59 42 79 72 20 82 77 42
	      56 78 38 80 39 75 02 71 66 66 01 03 55 72
	     44 25 67 84 71 67 11 61 40 57 58 89 40 56 36
	   85 32 25 85 57 48 84 35 47 62 17 01 01 99 89 52
	  06 71 28 75 94 48 37 10 23 51 06 48 53 18 74 98 15
	27 02 92 23 08 71 76 84 15 52 92 63 81 10 44 10 69 93";
			var charArray = input.Split ('\n');

			for (int i=0; i < charArray.Length; i++) {
				var numArr = charArray[i].Trim().Split(' ');

				for (int j = 0; j<numArr.Length; j++)
				{
					int number = Convert.ToInt32 (numArr[j]);
					list [i, j] = number;
				}
			}

			for (int i = 16; i >= 0; i--) {
				for (int j = 0; j < 18; j++) {
					list[i,j] = Math.Max(list[i, j] + list[i+1, j], list[i,j] + list[i+1, j+1]);
				}
			}
			Console.WriteLine (string.Format("Maximum total: {0}", list [0, 0]));
		}
	}
}









Ada: with Ada.Text_Io; use Ada.Text_Io;
 
procedure Max_Sum is

   Triangle : array (Positive range <>) of integer :=
                                     (55,
                                    94, 48,
                                  95, 30, 96,
                                77, 71, 26, 67,
                              97, 13, 76, 38, 45,
                            07, 36, 79, 16, 37, 68,
                          48, 07, 09, 18, 70, 26, 06,
                        18, 72, 79, 46, 59, 79, 29, 90,
                      20, 76, 87, 11, 32, 07, 07, 49, 18,
                    27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
                  14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
                02, 90, 03, 60, 48, 49, 41, 46, 33, 36, 47, 23,
              92, 50, 48, 02, 36, 59, 42, 79, 72, 20, 82, 77, 42,
            56, 78, 38, 80, 39, 75, 02, 71, 66, 66, 01, 03, 55, 72,
          44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
        85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 01, 01, 99, 89, 52,
      06, 71, 28, 75, 94, 48, 37, 10, 23, 51, 06, 48, 53, 18, 74, 98, 15,
    27, 02, 92, 23, 08, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93);

   Last  : Integer := Triangle'Length;
   Tn    : Integer := 1;

begin
   while (Tn * (Tn + 1) / 2) < Last  loop
      Tn := Tn + 1;
   end loop;
   for N in reverse 2 .. Tn loop
      for I in 2 .. N loop
	 Triangle (Last - N) := Triangle (Last - N) +
	   Integer'Max(Triangle (Last - 1), Triangle (Last));
	 Last := Last - 1;
      end loop;
      Last := Last - 1;
   end loop;
   Put_Line(Integer'Image(Triangle(1)));
end Max_Sum;
Task: Maximum triangle path sum

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

#define max(x,y)  ((x) > (y) ? (x) : (y))

int tri[] = {
        55,
	94, 48,
	95, 30, 96,
	77, 71, 26, 67,
	97, 13, 76, 38, 45,
	7, 36, 79, 16, 37, 68,
	48, 7, 9, 18, 70, 26, 6,
	18, 72, 79, 46, 59, 79, 29, 90,
	20, 76, 87, 11, 32, 7, 7, 49, 18,
	27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
	14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
	2, 90, 3, 60, 48, 49, 41, 46, 33, 36, 47, 23,
	92, 50, 48, 2, 36, 59, 42, 79, 72, 20, 82, 77, 42,
	56, 78, 38, 80, 39, 75, 2, 71, 66, 66, 1, 3, 55, 72,
	44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
	85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 1, 1, 99, 89, 52,
	6, 71, 28, 75, 94, 48, 37, 10, 23, 51, 6, 48, 53, 18, 74, 98, 15,
	27, 2, 92, 23, 8, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93
};

int main(void)
{
    const int len  = sizeof(tri) / sizeof(tri[0]);
    const int base = (sqrt(8*len + 1) - 1) / 2;
    int step       = base - 1;
    int stepc      = 0;

    int i;
    for (i = len - base - 1; i >= 0; --i) {
        tri[i] += max(tri[i + step], tri[i + step + 1]);
        if (++stepc == step) {
            step--;
            stepc = 0;
        }
    }

    printf("%d\n", tri[0]);
    return 0;
}











Ada: with Ada.Text_Io; use Ada.Text_Io;
 
procedure Max_Sum is

   Triangle : array (Positive range <>) of integer :=
                                     (55,
                                    94, 48,
                                  95, 30, 96,
                                77, 71, 26, 67,
                              97, 13, 76, 38, 45,
                            07, 36, 79, 16, 37, 68,
                          48, 07, 09, 18, 70, 26, 06,
                        18, 72, 79, 46, 59, 79, 29, 90,
                      20, 76, 87, 11, 32, 07, 07, 49, 18,
                    27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
                  14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
                02, 90, 03, 60, 48, 49, 41, 46, 33, 36, 47, 23,
              92, 50, 48, 02, 36, 59, 42, 79, 72, 20, 82, 77, 42,
            56, 78, 38, 80, 39, 75, 02, 71, 66, 66, 01, 03, 55, 72,
          44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
        85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 01, 01, 99, 89, 52,
      06, 71, 28, 75, 94, 48, 37, 10, 23, 51, 06, 48, 53, 18, 74, 98, 15,
    27, 02, 92, 23, 08, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93);

   Last  : Integer := Triangle'Length;
   Tn    : Integer := 1;

begin
   while (Tn * (Tn + 1) / 2) < Last  loop
      Tn := Tn + 1;
   end loop;
   for N in reverse 2 .. Tn loop
      for I in 2 .. N loop
	 Triangle (Last - N) := Triangle (Last - N) +
	   Integer'Max(Triangle (Last - 1), Triangle (Last));
	 Last := Last - 1;
      end loop;
      Last := Last - 1;
   end loop;
   Put_Line(Integer'Image(Triangle(1)));
end Max_Sum;
Task: Maximum triangle path sum


C++: 
#include <iostream>

int main( int argc, char* argv[] )
{
    int triangle[] = 
    {
	55,
	94, 48,
	95, 30, 96,
	77, 71, 26, 67,
	97, 13, 76, 38, 45,
	7, 36, 79, 16, 37, 68,
	48, 7, 9, 18, 70, 26, 6,
	18, 72, 79, 46, 59, 79, 29, 90,
	20, 76, 87, 11, 32, 7, 7, 49, 18,
	27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
	14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
	2, 90, 3, 60, 48, 49, 41, 46, 33, 36, 47, 23,
	92, 50, 48, 2, 36, 59, 42, 79, 72, 20, 82, 77, 42,
	56, 78, 38, 80, 39, 75, 2, 71, 66, 66, 1, 3, 55, 72,
	44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
	85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 1, 1, 99, 89, 52,
	6, 71, 28, 75, 94, 48, 37, 10, 23, 51, 6, 48, 53, 18, 74, 98, 15,
	27, 2, 92, 23, 8, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93
    };

    const int size = sizeof( triangle ) / sizeof( int );
    const int tn = static_cast<int>(sqrt(2.0 * size));
    assert(tn * (tn + 1) == 2 * size);    

    
    for (int n = tn - 1; n > 0; --n)   
        for (int k = (n * (n-1)) / 2; k < (n * (n+1)) / 2; ++k) 
            triangle[k] += std::max(triangle[k + n], triangle[k + n + 1]);

    std::cout << "Maximum total: " << triangle[0] << "\n\n";
}










Ada: with Ada.Text_Io; use Ada.Text_Io;
 
procedure Max_Sum is

   Triangle : array (Positive range <>) of integer :=
                                     (55,
                                    94, 48,
                                  95, 30, 96,
                                77, 71, 26, 67,
                              97, 13, 76, 38, 45,
                            07, 36, 79, 16, 37, 68,
                          48, 07, 09, 18, 70, 26, 06,
                        18, 72, 79, 46, 59, 79, 29, 90,
                      20, 76, 87, 11, 32, 07, 07, 49, 18,
                    27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
                  14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
                02, 90, 03, 60, 48, 49, 41, 46, 33, 36, 47, 23,
              92, 50, 48, 02, 36, 59, 42, 79, 72, 20, 82, 77, 42,
            56, 78, 38, 80, 39, 75, 02, 71, 66, 66, 01, 03, 55, 72,
          44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
        85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 01, 01, 99, 89, 52,
      06, 71, 28, 75, 94, 48, 37, 10, 23, 51, 06, 48, 53, 18, 74, 98, 15,
    27, 02, 92, 23, 08, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93);

   Last  : Integer := Triangle'Length;
   Tn    : Integer := 1;

begin
   while (Tn * (Tn + 1) / 2) < Last  loop
      Tn := Tn + 1;
   end loop;
   for N in reverse 2 .. Tn loop
      for I in 2 .. N loop
	 Triangle (Last - N) := Triangle (Last - N) +
	   Integer'Max(Triangle (Last - 1), Triangle (Last));
	 Last := Last - 1;
      end loop;
      Last := Last - 1;
   end loop;
   Put_Line(Integer'Image(Triangle(1)));
end Max_Sum;
Task: Maximum triangle path sum




Go: package main

import (
    "fmt"
    "strconv"
    "strings"
)

const t = `               55
                        94 48
                       95 30 96
                     77 71 26 67
                    97 13 76 38 45
                  07 36 79 16 37 68
                 48 07 09 18 70 26 06
               18 72 79 46 59 79 29 90
              20 76 87 11 32 07 07 49 18
            27 83 58 35 71 11 25 57 29 85
           14 64 36 96 27 11 58 56 92 18 55
         02 90 03 60 48 49 41 46 33 36 47 23
        92 50 48 02 36 59 42 79 72 20 82 77 42
      56 78 38 80 39 75 02 71 66 66 01 03 55 72
     44 25 67 84 71 67 11 61 40 57 58 89 40 56 36
   85 32 25 85 57 48 84 35 47 62 17 01 01 99 89 52
  06 71 28 75 94 48 37 10 23 51 06 48 53 18 74 98 15
27 02 92 23 08 71 76 84 15 52 92 63 81 10 44 10 69 93`

func main() {
    lines := strings.Split(t, "\n")
    f := strings.Fields(lines[len(lines)-1])
    d := make([]int, len(f))
    var err error
    for i, s := range f {
        if d[i], err = strconv.Atoi(s); err != nil {
            panic(err)
        }
    }
    d1 := d[1:]
    var l, r, u int
    for row := len(lines) - 2; row >= 0; row-- {
        l = d[0]
        for i, s := range strings.Fields(lines[row]) {
            if u, err = strconv.Atoi(s); err != nil {
                panic(err)
            }
            if r = d1[i]; l > r {
                d[i] = u + l
            } else {
                d[i] = u + r
            }
            l = r
        }
    }
    fmt.Println(d[0])
}








Ada: with Ada.Text_Io; use Ada.Text_Io;
 
procedure Max_Sum is

   Triangle : array (Positive range <>) of integer :=
                                     (55,
                                    94, 48,
                                  95, 30, 96,
                                77, 71, 26, 67,
                              97, 13, 76, 38, 45,
                            07, 36, 79, 16, 37, 68,
                          48, 07, 09, 18, 70, 26, 06,
                        18, 72, 79, 46, 59, 79, 29, 90,
                      20, 76, 87, 11, 32, 07, 07, 49, 18,
                    27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
                  14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
                02, 90, 03, 60, 48, 49, 41, 46, 33, 36, 47, 23,
              92, 50, 48, 02, 36, 59, 42, 79, 72, 20, 82, 77, 42,
            56, 78, 38, 80, 39, 75, 02, 71, 66, 66, 01, 03, 55, 72,
          44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
        85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 01, 01, 99, 89, 52,
      06, 71, 28, 75, 94, 48, 37, 10, 23, 51, 06, 48, 53, 18, 74, 98, 15,
    27, 02, 92, 23, 08, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93);

   Last  : Integer := Triangle'Length;
   Tn    : Integer := 1;

begin
   while (Tn * (Tn + 1) / 2) < Last  loop
      Tn := Tn + 1;
   end loop;
   for N in reverse 2 .. Tn loop
      for I in 2 .. N loop
	 Triangle (Last - N) := Triangle (Last - N) +
	   Integer'Max(Triangle (Last - 1), Triangle (Last));
	 Last := Last - 1;
      end loop;
      Last := Last - 1;
   end loop;
   Put_Line(Integer'Image(Triangle(1)));
end Max_Sum;
Task: Maximum triangle path sum





Java: import java.nio.file.*;
import static java.util.Arrays.stream;

public class MaxPathSum {

    public static void main(String[] args) throws Exception {
        int[][] data = Files.lines(Paths.get("triangle.txt"))
                .map(s -> stream(s.trim().split("\\s+"))
                        .mapToInt(Integer::parseInt)
                        .toArray())
                .toArray(int[][]::new);

        for (int r = data.length - 1; r > 0; r--)
            for (int c = 0; c < data[r].length - 1; c++)
                data[r - 1][c] += Math.max(data[r][c], data[r][c + 1]);

        System.out.println(data[0][0]);
    }
}







Ada: with Ada.Text_Io; use Ada.Text_Io;
 
procedure Max_Sum is

   Triangle : array (Positive range <>) of integer :=
                                     (55,
                                    94, 48,
                                  95, 30, 96,
                                77, 71, 26, 67,
                              97, 13, 76, 38, 45,
                            07, 36, 79, 16, 37, 68,
                          48, 07, 09, 18, 70, 26, 06,
                        18, 72, 79, 46, 59, 79, 29, 90,
                      20, 76, 87, 11, 32, 07, 07, 49, 18,
                    27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
                  14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
                02, 90, 03, 60, 48, 49, 41, 46, 33, 36, 47, 23,
              92, 50, 48, 02, 36, 59, 42, 79, 72, 20, 82, 77, 42,
            56, 78, 38, 80, 39, 75, 02, 71, 66, 66, 01, 03, 55, 72,
          44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
        85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 01, 01, 99, 89, 52,
      06, 71, 28, 75, 94, 48, 37, 10, 23, 51, 06, 48, 53, 18, 74, 98, 15,
    27, 02, 92, 23, 08, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93);

   Last  : Integer := Triangle'Length;
   Tn    : Integer := 1;

begin
   while (Tn * (Tn + 1) / 2) < Last  loop
      Tn := Tn + 1;
   end loop;
   for N in reverse 2 .. Tn loop
      for I in 2 .. N loop
	 Triangle (Last - N) := Triangle (Last - N) +
	   Integer'Max(Triangle (Last - 1), Triangle (Last));
	 Last := Last - 1;
      end loop;
      Last := Last - 1;
   end loop;
   Put_Line(Integer'Image(Triangle(1)));
end Max_Sum;
Task: Maximum triangle path sum







Python: fun maxpathsum(t): 
    let a = val t
    for i in a.length-1..-1..1, c in linearindices a[r]:
        a[r, c] += max(a[r+1, c], a[r=1, c+1])
    return a[1, 1]

let test = [
    [55],
    [94, 48],
    [95, 30, 96],
    [77, 71, 26, 67],
    [97, 13, 76, 38, 45],
    [07, 36, 79, 16, 37, 68],
    [48, 07, 09, 18, 70, 26, 06],
    [18, 72, 79, 46, 59, 79, 29, 90],
    [20, 76, 87, 11, 32, 07, 07, 49, 18],
    [27, 83, 58, 35, 71, 11, 25, 57, 29, 85],
    [14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55],
    [02, 90, 03, 60, 48, 49, 41, 46, 33, 36, 47, 23],
    [92, 50, 48, 02, 36, 59, 42, 79, 72, 20, 82, 77, 42],
    [56, 78, 38, 80, 39, 75, 02, 71, 66, 66, 01, 03, 55, 72],
    [44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36],
    [85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 01, 01, 99, 89, 52],
    [06, 71, 28, 75, 94, 48, 37, 10, 23, 51, 06, 48, 53, 18, 74, 98, 15],
    [27, 02, 92, 23, 08, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93]
]

@print maxpathsum test





Ada: with Ada.Text_Io; use Ada.Text_Io;
 
procedure Max_Sum is

   Triangle : array (Positive range <>) of integer :=
                                     (55,
                                    94, 48,
                                  95, 30, 96,
                                77, 71, 26, 67,
                              97, 13, 76, 38, 45,
                            07, 36, 79, 16, 37, 68,
                          48, 07, 09, 18, 70, 26, 06,
                        18, 72, 79, 46, 59, 79, 29, 90,
                      20, 76, 87, 11, 32, 07, 07, 49, 18,
                    27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
                  14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
                02, 90, 03, 60, 48, 49, 41, 46, 33, 36, 47, 23,
              92, 50, 48, 02, 36, 59, 42, 79, 72, 20, 82, 77, 42,
            56, 78, 38, 80, 39, 75, 02, 71, 66, 66, 01, 03, 55, 72,
          44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
        85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 01, 01, 99, 89, 52,
      06, 71, 28, 75, 94, 48, 37, 10, 23, 51, 06, 48, 53, 18, 74, 98, 15,
    27, 02, 92, 23, 08, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93);

   Last  : Integer := Triangle'Length;
   Tn    : Integer := 1;

begin
   while (Tn * (Tn + 1) / 2) < Last  loop
      Tn := Tn + 1;
   end loop;
   for N in reverse 2 .. Tn loop
      for I in 2 .. N loop
	 Triangle (Last - N) := Triangle (Last - N) +
	   Integer'Max(Triangle (Last - 1), Triangle (Last));
	 Last := Last - 1;
      end loop;
      Last := Last - 1;
   end loop;
   Put_Line(Integer'Image(Triangle(1)));
end Max_Sum;