WeixiangYan/CodeTransOcean huggingface dataset:
Task: Additive primes







Python: def is_prime(n: int) -> bool:
    if n <= 3:
        return n > 1
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i ** 2 <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def digit_sum(n: int) -> int:
    sum = 0
    while n > 0:
        sum += n % 10
        n //= 10
    return sum

def main() -> None:
    additive_primes = 0
    for i in range(2, 500):
        if is_prime(i) and is_prime(digit_sum(i)):
            additive_primes += 1
            print(i, end=" ")
    print(f"\nFound {additive_primes} additive primes less than 500")

if __name__ == "__main__":
    main()





Ada: with Ada.Text_Io;

procedure Additive_Primes is

   Last    : constant := 499;
   Columns : constant := 12;

   type Prime_List is array (2 .. Last) of Boolean;

   function Get_Primes return Prime_List is
      Prime : Prime_List := (others => True);
   begin
      for P in Prime'Range loop
         if Prime (P) then
            for N in 2 .. Positive'Last loop
               exit when N * P not in Prime'Range;
               Prime (N * P) := False;
            end loop;
         end if;
      end loop;
      return Prime;
   end Get_Primes;

   function Sum_Of (N : Natural) return Natural is
      Image : constant String := Natural'Image (N);
      Sum   : Natural := 0;
   begin
      for Char of Image loop
         Sum := Sum + (if Char in '0' .. '9'
                       then Natural'Value ("" & Char)
                       else 0);
      end loop;
      return Sum;
   end Sum_Of;

   package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
   use Ada.Text_Io, Natural_Io;

   Prime : constant Prime_List := Get_Primes;
   Count : Natural := 0;
begin
   Put_Line ("Additive primes <500:");
   for N in Prime'Range loop
      if Prime (N) and then Prime (Sum_Of (N)) then
         Count := Count + 1;
         Put (N, Width => 5);
         if Count mod Columns = 0 then
            New_Line;
         end if;
      end if;
   end loop;
   New_Line;

   Put ("There are ");
   Put (Count, Width => 2);
   Put (" additive primes.");
   New_Line;
end Additive_Primes;
Task: Case-sensitivity of identifiers







Python: >>> dog = 'Benjamin'; Dog = 'Samba'; DOG = 'Bernie'
>>> print ('The three dogs are named ',dog,', ',Dog,', and ',DOG)
The three dogs are named  Benjamin ,  Samba , and  Bernie
>>>





Ada: with Ada.Text_IO;
procedure Dogs is
   Dog : String := "Bernie";
begin
   Ada.Text_IO.Put_Line ("There is just one dog named " & DOG);
end Dogs;
Task: Extra primes







Python: from itertools import *
from functools import reduce

class Sieve(object):
    
    def __init__(self):
        self._primes = []
        self._comps = {}
        self._max = 2;
    
    def isprime(self, n):
        
        if n >= self._max: self._genprimes(n)
        return n >= 2 and n in self._primes
    
    def _genprimes(self, max):
        while self._max <= max:
            if self._max not in self._comps:
                self._primes.append(self._max)
                self._comps[self._max*self._max] = [self._max]
            else:
                for p in self._comps[self._max]:
                    ps = self._comps.setdefault(self._max+p, [])
                    ps.append(p)
                del self._comps[self._max]
            self._max += 1
                
def extra_primes():
    
    d = [2,3,5,7]
    s = Sieve()
    for cand in chain.from_iterable(product(d, repeat=r) for r in count(1)):
        num = reduce(lambda x, y: x*10+y, cand)
        if s.isprime(num) and s.isprime(sum(cand)): yield num
        
for n in takewhile(lambda n: n < 10000, extra_primes()):
    print(n)





Ada: with Ada.Text_Io;

procedure Extra_Primes is

   type Number   is new Long_Integer range 0 .. Long_Integer'Last;

   package Number_Io is new Ada.Text_Io.Integer_Io (Number);

   function Is_Prime (A : Number) return Boolean is
      D : Number;
   begin
      if A < 2       then return False; end if;
      if A in 2 .. 3 then return True;  end if;
      if A mod 2 = 0 then return False; end if;
      if A mod 3 = 0 then return False; end if;
      D := 5;
      while D * D <= A loop
         if A mod D = 0 then
            return False;
         end if;
         D := D + 2;
         if A mod D = 0 then
            return False;
         end if;
         D := D + 4;
      end loop;
      return True;
   end Is_Prime;

   subtype Digit is Number range 0 .. 9;
   type Digit_Array is array (Positive range <>) of Digit;

   function To_Digits (N : Number) return Digit_Array is
      Image : constant String := Number'Image (N);
      Res   : Digit_Array (2 .. Image'Last);
   begin
      for A in Image'First + 1 .. Image'Last loop
         Res (A) := Character'Pos (Image (A)) - Character'Pos ('0');
      end loop;
      return Res;
   end To_Digits;

   function All_Prime (Dig : Digit_Array) return Boolean is
     (for all D of Dig => Is_Prime (D));

   function Sum_Of (Dig : Digit_Array) return Number is
      Sum : Number := 0;
   begin
      for D of Dig loop
         Sum := Sum + D;
      end loop;
      return Sum;
   end Sum_Of;

   use Ada.Text_Io;
   Count : Natural := 0;
begin
   for N in Number range 1 .. 9_999 loop
      if Is_Prime (N) then
         declare
            Dig : constant Digit_Array := To_Digits (N);
         begin
            if All_Prime (Dig) and Is_Prime (Sum_Of (Dig)) then
               Count := Count + 1;
               Number_Io.Put (N, Width => 4); Put ("  ");
               if Count mod 8 = 0 then
                  New_Line;
               end if;
            end if;
         end;
      end if;
   end loop;
   New_Line;
   Put_Line (Count'Image & " extra primes.");
end Extra_Primes;
Task: Common sorted list







Python: 

from itertools import chain




def main():
    

    print(
        sorted(nub(concat([
            [5, 1, 3, 8, 9, 4, 8, 7],
            [3, 5, 9, 8, 4],
            [1, 3, 7, 9]
        ])))
    )






def concat(xs):
    
    return list(chain(*xs))



def nub(xs):
    
    return list(dict.fromkeys(xs))



if __name__ == '__main__':
    main()





Ada: with Ada.Text_Io;
with Ada.Containers.Vectors;

procedure Sorted is

   package Integer_Vectors is
     new Ada.Containers.Vectors (Index_Type   => Positive,
                                 Element_Type => Integer);
   use Integer_Vectors;

   package Vector_Sorting is
     new Integer_Vectors.Generic_Sorting;
   use Vector_Sorting;

   procedure Unique (Vec : in out Vector) is
      Res : Vector;
   begin
      for E of Vec loop
         if Res.Is_Empty or else Res.Last_Element /= E then
            Res.Append (E);
         end if;
      end loop;
      Vec := Res;
   end Unique;

   procedure Put (Vec : Vector) is
      use Ada.Text_Io;
   begin
      Put ("[");
      for E of Vec loop
         Put (E'Image);  Put (" ");
      end loop;
      Put ("]");
      New_Line;
   end Put;

   A : constant Vector := 5 & 1 & 3 & 8 & 9 & 4 & 8 & 7;
   B : constant Vector := 3 & 5 & 9 & 8 & 4;
   C : constant Vector := 1 & 3 & 7 & 9;
   R : Vector          := A & B & C;
begin
   Sort (R);
   Unique (R);
   Put (R);
end Sorted;
Task: Sorting algorithms_Stooge sort







Python: >>> data = [1, 4, 5, 3, -6, 3, 7, 10, -2, -5, 7, 5, 9, -3, 7]
>>> def stoogesort(L, i=0, j=None):
	if j is None:
		j = len(L) - 1
	if L[j] < L[i]:
		L[i], L[j] = L[j], L[i]
	if j - i > 1:
		t = (j - i + 1) // 3
		stoogesort(L, i  , j-t)
		stoogesort(L, i+t, j  )
		stoogesort(L, i  , j-t)
	return L

>>> stoogesort(data)
[-6, -5, -3, -2, 1, 3, 3, 4, 5, 5, 7, 7, 7, 9, 10]





Ada: with Ada.Text_IO;
procedure Stooge is
   type Integer_Array is array (Positive range <>) of Integer;
   procedure Swap (Left, Right : in out Integer) is
      Temp : Integer := Left;
   begin
      Left  := Right;
      Right := Temp;
   end Swap;
   procedure Stooge_Sort (List : in out Integer_Array) is
      T : Natural := List'Length / 3;
   begin
      if List (List'Last) < List (List'First) then
         Swap (List (List'Last), List (List'First));
      end if;
      if List'Length > 2 then
         Stooge_Sort (List (List'First     .. List'Last - T));
         Stooge_Sort (List (List'First + T .. List'Last));
         Stooge_Sort (List (List'First     .. List'Last - T));
      end if;
   end Stooge_Sort;
   Test_Array : Integer_Array := (1, 4, 5, 3, -6, 3, 7, 10, -2, -5, 7, 5, 9, -3, 7);
begin
   Stooge_Sort (Test_Array);
   for I in Test_Array'Range loop
      Ada.Text_IO.Put (Integer'Image (Test_Array (I)));
      if I /= Test_Array'Last then
         Ada.Text_IO.Put (", ");
      end if;
   end loop;
   Ada.Text_IO.New_Line;
end Stooge;
Task: Truncate a file







Python: def truncate_file(name, length):
    if not os.path.isfile(name):
        return False
    if length >= os.path.getsize(name):
        return False
    with open(name, 'ab') as f:
        f.truncate(length)
    return True





Ada: with Ada.Command_Line, Ada.Sequential_IO, Ada.Directories;

procedure Truncate_File is

   type Byte is mod 256;
   for Byte'Size use 8;

   package Byte_IO is new Ada.Sequential_IO(Byte);

   function Arg(N: Positive) return String renames Ada.Command_Line.Argument;
   function Args return Natural renames Ada.Command_Line.Argument_Count;

begin
   
   if Args < 2 or else Args > 3 then
      raise Program_Error
        with "usage: truncate_file <filename> <length> [<temp_file>]";
   end if;

   
   declare
      File_Name: String := Arg(1);
      Temp_Name: String := (if Args = 2 then Arg(1) & ".tmp" else Arg(3));
                             
      File, Temp: Byte_IO.File_Type;
      Count: Natural := Natural'Value(Arg(2));
      Value: Byte;
   begin
      
      Byte_IO.Open  (File => File, Mode => Byte_IO.In_File,  Name => File_Name);
      Byte_IO.Create(File => Temp, Mode => Byte_IO.Out_File, Name => Temp_Name);

      
      while (not Byte_IO.End_Of_File(File)) and Count > 0 loop
         Byte_IO.Read (File, Value);
         Byte_IO.Write(Temp, Value);
         Count := Count - 1;
      end loop;

      
      Byte_IO.Close(Temp);
      Byte_IO.Close(File);

      if Count = 0 then 
         
         Ada.Directories.Delete_File(Name => File_Name);
         Ada.Directories.Rename(Old_Name => Temp_Name, New_Name => File_Name);
      else 
         
         Ada.Directories.Delete_File(Name => Temp_Name);
         raise Program_Error
           with "Size of """ & File_Name & """ less than " & Arg(2);
      end if;
   end;
end Truncate_File;
Task: Sorting algorithms_Shell sort







Python: def shell(seq):
    inc = len(seq) // 2
    while inc:
        for i, el in enumerate(seq[inc:], inc):
            while i >= inc and seq[i - inc] > el:
                seq[i] = seq[i - inc]
                i -= inc
            seq[i] = el
        inc = 1 if inc == 2 else inc * 5 // 11





Ada: generic
   type Element_Type is digits <>;
   type Index_Type is (<>);
   type Array_Type is array(Index_Type range <>) of Element_Type;
package Shell_Sort is
   procedure Sort(Item : in out Array_Type);
end Shell_Sort;
Task: Formal power series







Python: 

from itertools import islice
from fractions import Fraction
from functools import reduce
try:
    from itertools import izip as zip 
except:
    pass

def head(n):
    
    return lambda seq: islice(seq, n)

def pipe(gen, *cmds):
    
    return reduce(lambda gen, cmd: cmd(gen), cmds, gen)

def sinepower():
    n = 0
    fac = 1
    sign = +1
    zero = 0
    yield zero
    while True:
        n +=1
        fac *= n
        yield Fraction(1, fac*sign)
        sign = -sign
        n +=1
        fac *= n
        yield zero
def cosinepower():
    n = 0
    fac = 1
    sign = +1
    yield Fraction(1,fac)
    zero = 0
    while True:
        n +=1
        fac *= n
        yield zero
        sign = -sign
        n +=1
        fac *= n
        yield Fraction(1, fac*sign)
def pluspower(*powergenerators):
    for elements in zip(*powergenerators):
        yield sum(elements)
def minuspower(*powergenerators):
    for elements in zip(*powergenerators):
        yield elements[0] - sum(elements[1:])
def mulpower(fgen,ggen):
    'From: http://en.wikipedia.org/wiki/Power_series
    a,b = [],[]
    for f,g in zip(fgen, ggen):
        a.append(f)
        b.append(g)
        yield sum(f*g for f,g in zip(a, reversed(b)))
def constpower(n):
    yield n
    while True:
        yield 0
def diffpower(gen):
    'differentiatiate power series'
    next(gen)
    for n, an in enumerate(gen, start=1):
        yield an*n
def intgpower(k=0):
    'integrate power series with constant k'
    def _intgpower(gen):
        yield k
        for n, an in enumerate(gen, start=1):
            yield an * Fraction(1,n)
    return _intgpower


print("cosine")
c = list(pipe(cosinepower(), head(10)))
print(c)
print("sine")
s = list(pipe(sinepower(), head(10)))
print(s)

integc = list(pipe(cosinepower(),intgpower(0), head(10)))

integs1 = list(minuspower(pipe(constpower(1), head(10)),
                          pipe(sinepower(),intgpower(0), head(10))))

assert s == integc, "The integral of cos should be sin"
assert c == integs1, "1 minus the integral of sin should be cos"





Ada: with Generic_Rational;

generic
   with package Rational_Numbers is new Generic_Rational (<>);
package Generic_Taylor_Series is
   use Rational_Numbers;
   type Taylor_Series is array (Natural range <>) of Rational;
   
   function "+" (A : Taylor_Series) return Taylor_Series;
   function "-" (A : Taylor_Series) return Taylor_Series;

   function "+" (A, B : Taylor_Series) return Taylor_Series;
   function "-" (A, B : Taylor_Series) return Taylor_Series;
   function "*" (A, B : Taylor_Series) return Taylor_Series;

   function Integral (A : Taylor_Series) return Taylor_Series;
   function Differential (A : Taylor_Series) return Taylor_Series;

   function Value (A : Taylor_Series; X : Rational) return Rational;

   Zero : constant Taylor_Series := (0 => Rational_Numbers.Zero);
   One  : constant Taylor_Series := (0 => Rational_Numbers.One);
end Generic_Taylor_Series;
Task: Deconvolution_1D







Python: def ToReducedRowEchelonForm( M ):
    if not M: return
    lead = 0
    rowCount = len(M)
    columnCount = len(M[0])
    for r in range(rowCount):
        if lead >= columnCount:
            return
        i = r
        while M[i][lead] == 0:
            i += 1
            if i == rowCount:
                i = r
                lead += 1
                if columnCount == lead:
                    return
        M[i],M[r] = M[r],M[i]
        lv = M[r][lead]
        M[r] = [ mrx / lv for mrx in M[r]]
        for i in range(rowCount):
            if i != r:
                lv = M[i][lead]
                M[i] = [ iv - lv*rv for rv,iv in zip(M[r],M[i])]
        lead += 1
    return M
 
def pmtx(mtx):
    print ('\n'.join(''.join(' %4s' % col for col in row) for row in mtx))
 
def convolve(f, h):
    g = [0] * (len(f) + len(h) - 1)
    for hindex, hval in enumerate(h):
        for findex, fval in enumerate(f):
            g[hindex + findex] += fval * hval
    return g

def deconvolve(g, f):
    lenh = len(g) - len(f) + 1
    mtx = [[0 for x in range(lenh+1)] for y in g]
    for hindex in range(lenh):
        for findex, fval in enumerate(f):
            gindex = hindex + findex
            mtx[gindex][hindex] = fval
    for gindex, gval in enumerate(g):        
        mtx[gindex][lenh] = gval
    ToReducedRowEchelonForm( mtx )
    return [mtx[i][lenh] for i in range(lenh)]  

if __name__ == '__main__':
    h = [-8,-9,-3,-1,-6,7]
    f = [-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1]
    g = [24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7]
    assert convolve(f,h) == g
    assert deconvolve(g, f) == h





Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
   package real_io is new Float_IO (Long_Float);
   use real_io;

   type Vector is array (Natural range <>) of Long_Float;

   function deconv (g, f : Vector) return Vector is
      len : Positive :=
        Integer'Max ((g'Length - f'length), (f'length - g'length));
      h     : Vector (0 .. len);
      Lower : Natural := 0;
   begin
      for n in h'range loop
         h (n) := g (n);
         if n >= f'length then
            Lower := n - f'length + 1;
         end if;
         for i in Lower .. n - 1 loop
            h (n) := h (n) - (h (i) * f (n - i));
         end loop;
         h (n) := h (n) / f (0);
      end loop;
      return h;
   end deconv;

   procedure print (v : Vector) is
   begin
      Put ("(");
      for I in v'range loop
         Put (Item => v (I), Fore => 1, Aft => 1, Exp => 0);
         if I < v'Last then
            Put (" ");
         else
            Put_Line (")");
         end if;
      end loop;
   end print;

   h : Vector := (-8.0, -9.0, -3.0, -1.0, -6.0, 7.0);
   f : Vector :=
     (-3.0, -6.0, -1.0, 8.0, -6.0, 3.0, -1.0, -9.0, -9.0, 3.0, -2.0, 5.0, 2.0,
      -2.0, -7.0, -1.0);
   g : Vector :=
     (24.0, 75.0, 71.0, -34.0, 3.0, 22.0, -45.0, 23.0, 245.0, 25.0, 52.0, 25.0,
      -67.0, -96.0, 96.0, 31.0, 55.0, 36.0, 29.0, -43.0, -7.0);
begin
   print (h);
   print (deconv (g, f));
   print (f);
   print (deconv (g, h));
end Main;
Task: Read a specific line from a file







Python: with open('xxx.txt') as f:
    for i, line in enumerate(f):
        if i == 6:
            break
    else:
        print('Not 7 lines in file')
        line = None





Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Rosetta_Read is
   File : File_Type;
begin
   Open (File => File,
         Mode => In_File,
         Name => "rosetta_read.adb");
   Set_Line (File, To => 7);

   declare
      Line_7 : constant String := Get_Line (File);
   begin
      if Line_7'Length = 0 then
         Put_Line ("Line 7 is empty.");
      else
         Put_Line (Line_7);
      end if;
   end;

   Close (File);
exception
   when End_Error =>
      Put_Line ("The file contains fewer than 7 lines.");
      Close (File);
   when Storage_Error =>
      Put_Line ("Line 7 is too long to load.");
      Close (File);
end Rosetta_Read;
Task: Digit fifth powers







Python: from time import time


st = time()
print(sum([n for n in range(2, 6*9**5) if sum(int(i)**5 for i in str(n)) == n]), "  ", (time() - st) * 1000, "ms")


st = time()
nums = list(range(10))
nu = list(range(((6 * 9**5) // 100000) + 1))
numbers = []
p5 = []
for i in nums: p5.append(i**5)
for i in nu:
    im = i * 100000
    ip = p5[i]
    for j in nums:
        jm = im + 10000 * j
        jp = ip + p5[j]
        for k in nums:
            km = jm + 1000 * k
            kp = jp + p5[k]
            for l in nums:
                lm = km + 100 * l
                lp = kp + p5[l]
                for m in nums:
                    mm = lm + 10 * m
                    mp = lp + p5[m]
                    for n in nums:
                        nm = mm + n
                        np = mp + p5[n]
                        if np == nm:
                            if nm > 1: numbers.append(nm)
print(sum(numbers), "  ", (time() - st) * 1000, "ms", end = "")





Ada: with Ada.Text_Io;

procedure Digit_Fifth_Powers is

   subtype Number is Natural range 000_002 .. 999_999;

   function Sum_5 (N : Natural) return Natural
   is
      Pow_5 : constant array (0 .. 9) of Natural :=
        (0 => 0**5, 1 => 1**5, 2 => 2**5, 3 => 3**5, 4 => 4**5,
         5 => 5**5, 6 => 6**5, 7 => 7**5, 8 => 8**5, 9 => 9**5);
   begin
      return (if N = 0
              then 0
              else Pow_5 (N mod 10) + Sum_5 (N / 10));
   End Sum_5;

   use Ada.Text_Io;
   Sum : Natural := 0;
begin
   for N in Number loop
      if N = Sum_5 (N) then
         Sum := Sum + N;
         Put_Line (Number'Image (N));
      end if;
   end loop;
   Put ("Sum: ");
   Put_Line (Natural'Image (Sum));
end Digit_Fifth_Powers;
Task: Find prime n such that reversed n is also prime







Python: 

def isPrime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False        
    return True

def isBackPrime(n):
    if not isPrime(n):
        return False
    m = 0
    while n:
        m *= 10
        m += n % 10
        n //= 10
    return isPrime(m)

if __name__ == '__main__':
    for n in range(2, 499):
        if isBackPrime(n):
            print(n, end=' ');





Ada: with Ada.Text_Io;

procedure Reverse_Prime is

   type Number is new Long_Integer range 0 .. Long_Integer'Last;
   package Number_Io is new Ada.Text_Io.Integer_Io (Number);

   function Is_Prime (A : Number) return Boolean is
      D : Number;
   begin
      if A < 2       then return False; end if;
      if A in 2 .. 3 then return True;  end if;
      if A mod 2 = 0 then return False; end if;
      if A mod 3 = 0 then return False; end if;
      D := 5;
      while D * D <= A loop
         if A mod D = 0 then
            return False;
         end if;
         D := D + 2;
         if A mod D = 0 then
            return False;
         end if;
         D := D + 4;
      end loop;
      return True;
   end Is_Prime;

   function Reverse_Num (N : Number) return Number is
      N2  : Number := N;
      Res : Number := 0;
   begin
      while N2 /= 0 loop
         Res := 10 * Res;
         Res := Res  + (N2 mod 10);
         N2  := N2 / 10;
      end loop;
      return Res;
   end Reverse_Num;

   use Ada.Text_Io;
   Count : Natural := 0;
begin
   for N in Number range 1 .. 499 loop
      if Is_Prime (N) and then Is_Prime (Reverse_Num (N)) then
         Count := Count + 1;
         Number_Io.Put (N, Width => 3); Put ("  ");
         if Count mod 8 = 0 then
            New_Line;
         end if;
      end if;
   end loop;
   New_Line;
   Put_Line (Count'Image & " primes.");
end Reverse_Prime;
Task: URL encoding







Python: import urllib
s = 'http://foo/bar/'
s = urllib.quote(s)





Ada: with AWS.URL;
with Ada.Text_IO; use Ada.Text_IO;
procedure Encode is
   Normal : constant String := "http://foo bar/";
begin
   Put_Line (AWS.URL.Encode (Normal));
end Encode;
Task: LU decomposition







Python: from pprint import pprint

def matrixMul(A, B):
    TB = zip(*B)
    return [[sum(ea*eb for ea,eb in zip(a,b)) for b in TB] for a in A]

def pivotize(m):
    
    n = len(m)
    ID = [[float(i == j) for i in xrange(n)] for j in xrange(n)]
    for j in xrange(n):
        row = max(xrange(j, n), key=lambda i: abs(m[i][j]))
        if j != row:
            ID[j], ID[row] = ID[row], ID[j]
    return ID

def lu(A):
    
    n = len(A)
    L = [[0.0] * n for i in xrange(n)]
    U = [[0.0] * n for i in xrange(n)]
    P = pivotize(A)
    A2 = matrixMul(P, A)
    for j in xrange(n):
        L[j][j] = 1.0
        for i in xrange(j+1):
            s1 = sum(U[k][j] * L[i][k] for k in xrange(i))
            U[i][j] = A2[i][j] - s1
        for i in xrange(j, n):
            s2 = sum(U[k][j] * L[i][k] for k in xrange(j))
            L[i][j] = (A2[i][j] - s2) / U[j][j]
    return (L, U, P)

a = [[1, 3, 5], [2, 4, 7], [1, 1, 0]]
for part in lu(a):
    pprint(part, width=19)
    print
print
b = [[11,9,24,2],[1,5,2,6],[3,17,18,1],[2,5,7,1]]
for part in lu(b):
    pprint(part)
    print





Ada: with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is

   
   procedure Decompose (A : Matrix.Real_Matrix; P, L, U : out Matrix.Real_Matrix);

end Decomposition;