WeixiangYan/CodeTransOcean huggingface dataset:
Task: Averages_Simple moving average



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

namespace SMA {
    class Program {
        static void Main(string[] args) {
            var nums = Enumerable.Range(1, 5).Select(n => (double)n);
            nums = nums.Concat(nums.Reverse());

            var sma3 = SMA(3);
            var sma5 = SMA(5);

            foreach (var n in nums) {
                Console.WriteLine("{0}    (sma3) {1,-16} (sma5) {2,-16}", n, sma3(n), sma5(n));
            }
        }

        static Func<double, double> SMA(int p) {
            Queue<double> s = new Queue<double>(p);
            return (x) => {
                if (s.Count >= p) {
                    s.Dequeue();
                }
                s.Enqueue(x);
                return s.Average();
            };
        }
    }
}








Fortran: program Movavg
  implicit none

  integer :: i
	
  write (*, "(a)") "SIMPLE MOVING AVERAGE: PERIOD = 3"

  do i = 1, 5
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do
  do i = 5, 1, -1
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do 
 
contains

function sma(n)
  real :: sma
  real, intent(in) :: n
  real, save :: a(3) = 0
  integer, save :: count = 0

  if (count < 3) then
    count = count + 1
    a(count) = n
  else
    a = eoshift(a, 1, n)
  end if

  sma = sum(a(1:count)) / real(count)
end function

end program Movavg
Task: Averages_Simple moving average


C++: #include <iostream>
#include <stddef.h>
#include <assert.h>

using std::cout;
using std::endl;

class SMA {
public:
	SMA(unsigned int period) :
		period(period), window(new double[period]), head(NULL), tail(NULL),
				total(0) {
		assert(period >= 1);
	}
	~SMA() {
		delete[] window;
	}

	
	void add(double val) {
		
		if (head == NULL) {
			head = window;
			*head = val;
			tail = head;
			inc(tail);
			total = val;
			return;
		}

		
		if (head == tail) {
			
			total -= *head;
			
			inc(head);
		}

		
		*tail = val;
		inc(tail);

		
		total += val;
	}

	
	
	double avg() const {
		ptrdiff_t size = this->size();
		if (size == 0) {
			return 0; 
		}
		return total / (double) size; 
	}

private:
	unsigned int period;
	double * window; 

	
	double * head; 
	double * tail; 

	double total; 

	
	
	void inc(double * & p) {
		if (++p >= window + period) {
			p = window;
		}
	}

	
	ptrdiff_t size() const {
		if (head == NULL)
			return 0;
		if (head == tail)
			return period;
		return (period + tail - head) % period;
	}
};

int main(int argc, char * * argv) {
	SMA foo(3);
	SMA bar(5);

	int data[] = { 1, 2, 3, 4, 5, 5, 4, 3, 2, 1 };
	for (int * itr = data; itr < data + 10; itr++) {
		foo.add(*itr);
		cout << "Added " << *itr << " avg: " << foo.avg() << endl;
	}
	cout << endl;
	for (int * itr = data; itr < data + 10; itr++) {
		bar.add(*itr);
		cout << "Added " << *itr << " avg: " << bar.avg() << endl;
	}

	return 0;
}









Fortran: program Movavg
  implicit none

  integer :: i
	
  write (*, "(a)") "SIMPLE MOVING AVERAGE: PERIOD = 3"

  do i = 1, 5
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do
  do i = 5, 1, -1
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do 
 
contains

function sma(n)
  real :: sma
  real, intent(in) :: n
  real, save :: a(3) = 0
  integer, save :: count = 0

  if (count < 3) then
    count = count + 1
    a(count) = n
  else
    a = eoshift(a, 1, n)
  end if

  sma = sum(a(1:count)) / real(count)
end function

end program Movavg
Task: Averages_Simple moving average

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

typedef struct sma_obj {
  double sma;
  double sum;
  int period;
  double *values;
  int lv;
} sma_obj_t;

typedef union sma_result {
  sma_obj_t *handle;
  double sma;
  double *values;
} sma_result_t;

enum Action { SMA_NEW, SMA_FREE, SMA_VALUES, SMA_ADD, SMA_MEAN };
sma_result_t sma(enum Action action, ...)
{
  va_list vl;
  sma_result_t r;
  sma_obj_t *o;
  double v;

  va_start(vl, action);
  switch(action) {
  case SMA_NEW: 
    r.handle = malloc(sizeof(sma_obj_t));
    r.handle->sma = 0.0;
    r.handle->period = va_arg(vl, int);
    r.handle->values = malloc(r.handle->period * sizeof(double));
    r.handle->lv = 0;
    r.handle->sum = 0.0;
    break;
  case SMA_FREE: 
    r.handle = va_arg(vl, sma_obj_t *);
    free(r.handle->values);
    free(r.handle);
    r.handle = NULL;
    break;
  case SMA_VALUES: 
    o = va_arg(vl, sma_obj_t *);
    r.values = o->values;
    break;
  case SMA_MEAN: 
    o = va_arg(vl, sma_obj_t *);
    r.sma = o->sma;
    break;
  case SMA_ADD: 
    o = va_arg(vl, sma_obj_t *);
    v = va_arg(vl, double);
    if ( o->lv < o->period ) {
      o->values[o->lv++] = v;
      o->sum += v;
      o->sma = o->sum / o->lv;
    } else {
      o->sum -= o->values[ o->lv % o->period];
      o->sum += v;
      o->sma = o->sum / o->period;
      o->values[ o->lv % o->period ] = v; o->lv++;
    }
    r.sma = o->sma;
    break;
  }
  va_end(vl);
  return r;
}










Fortran: program Movavg
  implicit none

  integer :: i
	
  write (*, "(a)") "SIMPLE MOVING AVERAGE: PERIOD = 3"

  do i = 1, 5
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do
  do i = 5, 1, -1
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do 
 
contains

function sma(n)
  real :: sma
  real, intent(in) :: n
  real, save :: a(3) = 0
  integer, save :: count = 0

  if (count < 3) then
    count = count + 1
    a(count) = n
  else
    a = eoshift(a, 1, n)
  end if

  sma = sum(a(1:count)) / real(count)
end function

end program Movavg
Task: Averages_Simple moving average





Java: import java.util.LinkedList;
import java.util.Queue;

public class MovingAverage {
    private final Queue<Double> window = new LinkedList<Double>();
    private final int period;
    private double sum;

    public MovingAverage(int period) {
        assert period > 0 : "Period must be a positive integer";
        this.period = period;
    }

    public void newNum(double num) {
        sum += num;
        window.add(num);
        if (window.size() > period) {
            sum -= window.remove();
        }
    }

    public double getAvg() {
        if (window.isEmpty()) return 0.0; 
        return sum / window.size();
    }

    public static void main(String[] args) {
        double[] testData = {1, 2, 3, 4, 5, 5, 4, 3, 2, 1};
        int[] windowSizes = {3, 5};
        for (int windSize : windowSizes) {
            MovingAverage ma = new MovingAverage(windSize);
            for (double x : testData) {
                ma.newNum(x);
                System.out.println("Next number = " + x + ", SMA = " + ma.getAvg());
            }
            System.out.println();
        }
    }
}






Fortran: program Movavg
  implicit none

  integer :: i
	
  write (*, "(a)") "SIMPLE MOVING AVERAGE: PERIOD = 3"

  do i = 1, 5
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do
  do i = 5, 1, -1
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do 
 
contains

function sma(n)
  real :: sma
  real, intent(in) :: n
  real, save :: a(3) = 0
  integer, save :: count = 0

  if (count < 3) then
    count = count + 1
    a(count) = n
  else
    a = eoshift(a, 1, n)
  end if

  sma = sum(a(1:count)) / real(count)
end function

end program Movavg
Task: Averages_Simple moving average







Python: from collections import deque

def simplemovingaverage(period):
    assert period == int(period) and period > 0, "Period must be an integer >0"
    
    summ = n = 0.0
    values = deque([0.0] * period)     

    def sma(x):
        nonlocal summ, n
        
        values.append(x)
        summ += x - values.popleft()
        n = min(n+1, period)
        return summ / n

    return sma




Fortran: program Movavg
  implicit none

  integer :: i
	
  write (*, "(a)") "SIMPLE MOVING AVERAGE: PERIOD = 3"

  do i = 1, 5
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do
  do i = 5, 1, -1
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do 
 
contains

function sma(n)
  real :: sma
  real, intent(in) :: n
  real, save :: a(3) = 0
  integer, save :: count = 0

  if (count < 3) then
    count = count + 1
    a(count) = n
  else
    a = eoshift(a, 1, n)
  end if

  sma = sum(a(1:count)) / real(count)
end function

end program Movavg
Task: Averages_Simple moving average








VB: Class sma

Private n As Integer 
Private arr() As Double 
Private index As Integer 
Private oldsma As Double

Public Sub init(size As Integer)
    n = size
    ReDim arr(n - 1)
    index = 0
End Sub

Public Function sma(number As Double) As Double
    sma = oldsma + (-arr(index) + number) / n
    oldsma = sma
    arr(index) = number
    index = (index + 1) Mod n
End Function

Normal module
Public Sub main()
    s = [{1,2,3,4,5,5,4,3,2,1}]
    Dim sma3 As New sma
    Dim sma5 As New sma
    sma3.init 3
    sma5.init 5
    For i = 1 To UBound(s)
        Debug.Print i, Format(sma3.sma(CDbl(s(i))), "0.00000"),
        Debug.Print Format(sma5.sma(CDbl(s(i))), "0.00000")
    Next i
End Sub



Fortran: program Movavg
  implicit none

  integer :: i
	
  write (*, "(a)") "SIMPLE MOVING AVERAGE: PERIOD = 3"

  do i = 1, 5
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do
  do i = 5, 1, -1
    write (*, "(a, i2, a, f8.6)") "Next number:", i, "   sma = ", sma(real(i))
  end do 
 
contains

function sma(n)
  real :: sma
  real, intent(in) :: n
  real, save :: a(3) = 0
  integer, save :: count = 0

  if (count < 3) then
    count = count + 1
    a(count) = n
  else
    a = eoshift(a, 1, n)
  end if

  sma = sum(a(1:count)) / real(count)
end function

end program Movavg
Task: Literals_Integer



C#: int a = 42;
int b = 0x2a;









Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer

C: #include <stdio.h>

int main(void)
{
  printf("%s\n",
         ( (727 == 0x2d7) && 
           (727 == 01327)    ) ? "true" : "false");

  return 0;
}











Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer


C++: #include <iostream>

int main()
{
  std::cout << ( (727 == 0x2d7) && 
                 (727 == 01327)     ? "true" : "false")
            << std::endl;
 
  return 0;
}










Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer




Go: package main

import "fmt"

func main() {
	fmt.Println(727 == 0x2d7)         
	fmt.Println(727 == 01327)         
	fmt.Println(727 == 0b10110_10111) 
	fmt.Println(727 == '˗')           
}








Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer





Java: public class IntegerLiterals {
    public static void main(String[] args) {
        System.out.println( 727 == 0x2d7 && 
                            727 == 01327   );
    }
}







Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer







Python: >>> 
>>> 0b1011010111 == 0o1327 == 727 == 0x2d7
True
>>>





Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer








VB: Sub Main()


Dim l1 As Long, l2 As Long, l3 As Long

Dim i1 As Integer, i2 As Integer, i3 As Integer

Dim b1 As Byte, b2 As Byte, b3 As Byte
  
  l1 = 1024&
  l2 = &H400&
  l3 = &O2000&
  Debug.Assert l1 = l2
  Debug.Assert l2 = l3
  
  i1 = 1024
  i2 = &H400
  i3 = &O2000
  Debug.Assert i1 = i2
  Debug.Assert i2 = i3
  
  b1 = 255
  b2 = &O377
  b3 = &HFF
  Debug.Assert b1 = b2
  Debug.Assert b2 = b3
  
End Sub




Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer

C: #include <stdio.h>

int main(void)
{
  printf("%s\n",
         ( (727 == 0x2d7) && 
           (727 == 01327)    ) ? "true" : "false");

  return 0;
}
Task: Literals_Integer


C++: #include <iostream>

int main()
{
  std::cout << ( (727 == 0x2d7) && 
                 (727 == 01327)     ? "true" : "false")
            << std::endl;
 
  return 0;
}
Task: Literals_Integer





Java: public class IntegerLiterals {
    public static void main(String[] args) {
        System.out.println( 727 == 0x2d7 && 
                            727 == 01327   );
    }
}
Task: Literals_Integer







Python: >>> 
>>> 0b1011010111 == 0o1327 == 727 == 0x2d7
True
>>>
Task: Literals_Integer








VB: Sub Main()


Dim l1 As Long, l2 As Long, l3 As Long

Dim i1 As Integer, i2 As Integer, i3 As Integer

Dim b1 As Byte, b2 As Byte, b3 As Byte
  
  l1 = 1024&
  l2 = &H400&
  l3 = &O2000&
  Debug.Assert l1 = l2
  Debug.Assert l2 = l3
  
  i1 = 1024
  i2 = &H400
  i3 = &O2000
  Debug.Assert i1 = i2
  Debug.Assert i2 = i3
  
  b1 = 255
  b2 = &O377
  b3 = &HFF
  Debug.Assert b1 = b2
  Debug.Assert b2 = b3
  
End Sub
Task: Literals_Integer




Go: package main

import "fmt"

func main() {
	fmt.Println(727 == 0x2d7)         
	fmt.Println(727 == 01327)         
	fmt.Println(727 == 0b10110_10111) 
	fmt.Println(727 == '˗')           
}
Task: Literals_Integer



C#: int a = 42;
int b = 0x2a;
Task: Literals_Integer



C#: int a = 42;
int b = 0x2a;








Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer


C++: #include <iostream>

int main()
{
  std::cout << ( (727 == 0x2d7) && 
                 (727 == 01327)     ? "true" : "false")
            << std::endl;
 
  return 0;
}









Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer

C: #include <stdio.h>

int main(void)
{
  printf("%s\n",
         ( (727 == 0x2d7) && 
           (727 == 01327)    ) ? "true" : "false");

  return 0;
}










Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer




Go: package main

import "fmt"

func main() {
	fmt.Println(727 == 0x2d7)         
	fmt.Println(727 == 01327)         
	fmt.Println(727 == 0b10110_10111) 
	fmt.Println(727 == '˗')           
}







Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer





Java: public class IntegerLiterals {
    public static void main(String[] args) {
        System.out.println( 727 == 0x2d7 && 
                            727 == 01327   );
    }
}






Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer







Python: >>> 
>>> 0b1011010111 == 0o1327 == 727 == 0x2d7
True
>>>




Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer








VB: Sub Main()


Dim l1 As Long, l2 As Long, l3 As Long

Dim i1 As Integer, i2 As Integer, i3 As Integer

Dim b1 As Byte, b2 As Byte, b3 As Byte
  
  l1 = 1024&
  l2 = &H400&
  l3 = &O2000&
  Debug.Assert l1 = l2
  Debug.Assert l2 = l3
  
  i1 = 1024
  i2 = &H400
  i3 = &O2000
  Debug.Assert i1 = i2
  Debug.Assert i2 = i3
  
  b1 = 255
  b2 = &O377
  b3 = &HFF
  Debug.Assert b1 = b2
  Debug.Assert b2 = b3
  
End Sub



Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer






PHP: <?php
if (727 == 0x2d7 && 
    727 == 01327) {
  echo "true\n";
}

$a = 1234; // decimal number
$a = 0123; // octal number (equivalent to 83 decimal)
$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)
$a = 0b11111111; // binary number (equivalent to 255 decimal)
$a = 1_234_567; // decimal number (as of PHP 7.4.0)





Fortran: program IntegerLiteral

  implicit none
  integer, parameter   :: dec = 727
  integer, parameter   :: hex = Z'2d7'
  integer, parameter   :: oct = O'1327'
  integer, parameter   :: bin = B'1011010111' 

  print *, dec, hex, oct, bin

end program IntegerLiteral
Task: Literals_Integer

C: #include <stdio.h>

int main(void)
{
  printf("%s\n",
         ( (727 == 0x2d7) && 
           (727 == 01327)    ) ? "true" : "false");

  return 0;
}









COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: Literals_Integer



C#: int a = 42;
int b = 0x2a;







COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: Literals_Integer


C++: #include <iostream>

int main()
{
  std::cout << ( (727 == 0x2d7) && 
                 (727 == 01327)     ? "true" : "false")
            << std::endl;
 
  return 0;
}








COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: Literals_Integer





Java: public class IntegerLiterals {
    public static void main(String[] args) {
        System.out.println( 727 == 0x2d7 && 
                            727 == 01327   );
    }
}





COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: Literals_Integer







Python: >>> 
>>> 0b1011010111 == 0o1327 == 727 == 0x2d7
True
>>>



COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: Literals_Integer








VB: Sub Main()


Dim l1 As Long, l2 As Long, l3 As Long

Dim i1 As Integer, i2 As Integer, i3 As Integer

Dim b1 As Byte, b2 As Byte, b3 As Byte
  
  l1 = 1024&
  l2 = &H400&
  l3 = &O2000&
  Debug.Assert l1 = l2
  Debug.Assert l2 = l3
  
  i1 = 1024
  i2 = &H400
  i3 = &O2000
  Debug.Assert i1 = i2
  Debug.Assert i2 = i3
  
  b1 = 255
  b2 = &O377
  b3 = &HFF
  Debug.Assert b1 = b2
  Debug.Assert b2 = b3
  
End Sub


COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: Literals_Integer




Go: package main

import "fmt"

func main() {
	fmt.Println(727 == 0x2d7)         
	fmt.Println(727 == 01327)         
	fmt.Println(727 == 0b10110_10111) 
	fmt.Println(727 == '˗')           
}






COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: Literals_Integer






PHP: <?php
if (727 == 0x2d7 && 
    727 == 01327) {
  echo "true\n";
}

$a = 1234; // decimal number
$a = 0123; // octal number (equivalent to 83 decimal)
$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)
$a = 0b11111111; // binary number (equivalent to 255 decimal)
$a = 1_234_567; // decimal number (as of PHP 7.4.0)
Task: Literals_Integer






PHP: <?php
if (727 == 0x2d7 && 
    727 == 01327) {
  echo "true\n";
}

$a = 1234; // decimal number
$a = 0123; // octal number (equivalent to 83 decimal)
$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)
$a = 0b11111111; // binary number (equivalent to 255 decimal)
$a = 1_234_567; // decimal number (as of PHP 7.4.0)






Ada: with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Literals is
begin
   Put (16#2D7#);
   Put (10#727#);
   Put (8#1_327#);
   Put (2#10_1101_0111#);
end Test_Literals;
Task: Literals_Integer






PHP: <?php
if (727 == 0x2d7 && 
    727 == 01327) {
  echo "true\n";
}

$a = 1234; // decimal number
$a = 0123; // octal number (equivalent to 83 decimal)
$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)
$a = 0b11111111; // binary number (equivalent to 255 decimal)
$a = 1_234_567; // decimal number (as of PHP 7.4.0)




COBOL: display B#10 ", " O#01234567 ", " -0123456789 ", "
        H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4
Task: JortSort



C#: using System;

class Program
{
  public static bool JortSort<T>(T[] array) where T : IComparable, IEquatable<T>
  {
    
    T[] originalArray = (T[]) array.Clone();
    Array.Sort(array);

    
    for (var i = 0; i < originalArray.Length; i++)
    {
      if (!Equals(originalArray[i], array[i]))
      {
        return false;
      }
    }

    return true;
  }
}









Ada: with Ada.Text_IO, Ada.Containers.Generic_Array_Sort;

procedure Jortsort is
   
   function Jort_Sort(List: String) return Boolean is
      procedure Sort is new Ada.Containers.Generic_Array_Sort
	(Positive, Character, Array_Type => String);
      Second_List: String := List;
   begin
      Sort(Second_List);
      return Second_List = List;
   end Jort_Sort;
   
   use Ada.Text_IO;
begin
   Put_Line("""abbigail"" sorted: " & Boolean'Image(Jort_Sort("abbigail")));
   Put_Line("""abbey"" sorted: " & Boolean'Image(Jort_Sort("abbey")));
end Jortsort;