WeixiangYan/CodeTransOcean huggingface dataset:
Task: Find the intersection of a line with a plane







Python: 
from __future__ import print_function
import numpy as np

def LinePlaneCollision(planeNormal, planePoint, rayDirection, rayPoint, epsilon=1e-6):

	ndotu = planeNormal.dot(rayDirection)
	if abs(ndotu) < epsilon:
		raise RuntimeError("no intersection or line is within plane")

	w = rayPoint - planePoint
	si = -planeNormal.dot(w) / ndotu
	Psi = w + si * rayDirection + planePoint
	return Psi


if __name__=="__main__":
	
	planeNormal = np.array([0, 0, 1])
	planePoint = np.array([0, 0, 5]) 

	
	rayDirection = np.array([0, -1, -1])
	rayPoint = np.array([0, 0, 10]) 

	Psi = LinePlaneCollision(planeNormal, planePoint, rayDirection, rayPoint)
	print ("intersection at", Psi)





Ada: with Ada.Numerics.Generic_Real_Arrays;
with Ada.Text_IO;

procedure Intersection is

   type Real is new Long_Float;

   package Real_Arrays is
      new Ada.Numerics.Generic_Real_Arrays (Real => Real);
   use Real_Arrays;

   package Real_IO is
      new Ada.Text_IO.Float_IO (Num => Real);

   subtype Vector_3D is Real_Vector (1 .. 3);

   function Line_Plane_Intersection (Line_Vector  : in Vector_3D;
                                     Line_Point   : in Vector_3D;
                                     Plane_Normal : in Vector_3D;
                                     Plane_Point  : in Vector_3D)
                                    return Vector_3D
   is
      Diff  : constant Vector_3D := Line_Point - Plane_Point;
      Denom : constant Real      := Line_Vector * Plane_Normal;
   begin
      if Denom = 0.0 then
         raise Constraint_Error with "Line does not intersect plane";
      end if;
      declare
         Scale : constant Real :=
           -Real'(Diff * Plane_Normal) / Denom;
         Point : constant Vector_3D :=
           Diff + Plane_Point + Scale * Line_Vector;
      begin
         return Point;
      end;
   end Line_Plane_Intersection;

   procedure Put (V : in Vector_3D) is
      use Ada.Text_IO, Real_IO;
   begin
      Put ("(");
      Put (V (1));  Put (",");
      Put (V (2));  Put (",");
      Put (V (3));  Put (")");
   end Put;

begin
   Real_IO.Default_Exp := 0;
   Real_IO.Default_Aft := 3;

   Put (Line_Plane_Intersection (Line_Vector  => (0.0, -1.0, -1.0),
                                 Line_Point   => (0.0,  0.0, 10.0),
                                 Plane_Normal => (0.0,  0.0,  1.0),
                                 Plane_Point  => (0.0,  0.0,  5.0)));
end Intersection;
Task: Find the intersection of a line with a plane

C: #include<stdio.h>

typedef struct{
	double x,y,z;
}vector;

vector addVectors(vector a,vector b){
	return (vector){a.x+b.x,a.y+b.y,a.z+b.z};
}

vector subVectors(vector a,vector b){
	return (vector){a.x-b.x,a.y-b.y,a.z-b.z};
}

double dotProduct(vector a,vector b){
	return a.x*b.x + a.y*b.y + a.z*b.z;
}

vector scaleVector(double l,vector a){
	return (vector){l*a.x,l*a.y,l*a.z};
}

vector intersectionPoint(vector lineVector, vector linePoint, vector planeNormal, vector planePoint){
	vector diff = subVectors(linePoint,planePoint);
	
	return addVectors(addVectors(diff,planePoint),scaleVector(-dotProduct(diff,planeNormal)/dotProduct(lineVector,planeNormal),lineVector));
}

int main(int argC,char* argV[])
{
	vector lV,lP,pN,pP,iP;
	
	if(argC!=5)
		printf("Usage : %s <line direction, point on line, normal to plane and point on plane given as (x,y,z) tuples separated by space>");
	else{
		sscanf(argV[1],"(%lf,%lf,%lf)",&lV.x,&lV.y,&lV.z);
		sscanf(argV[3],"(%lf,%lf,%lf)",&pN.x,&pN.y,&pN.z);
		
		if(dotProduct(lV,pN)==0)
			printf("Line and Plane do not intersect, either parallel or line is on the plane");
		else{
			sscanf(argV[2],"(%lf,%lf,%lf)",&lP.x,&lP.y,&lP.z);
			sscanf(argV[4],"(%lf,%lf,%lf)",&pP.x,&pP.y,&pP.z);
			
			iP = intersectionPoint(lV,lP,pN,pP);
			
			printf("Intersection point is (%lf,%lf,%lf)",iP.x,iP.y,iP.z);
		}
	}
		
	return 0;
}
Task: Find the intersection of a line with a plane



C#: using System;

namespace FindIntersection {
    class Vector3D {
        private double x, y, z;

        public Vector3D(double x, double y, double z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public static Vector3D operator +(Vector3D lhs, Vector3D rhs) {
            return new Vector3D(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
        }

        public static Vector3D operator -(Vector3D lhs, Vector3D rhs) {
            return new Vector3D(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
        }

        public static Vector3D operator *(Vector3D lhs, double rhs) {
            return new Vector3D(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs);
        }

        public double Dot(Vector3D rhs) {
            return x * rhs.x + y * rhs.y + z * rhs.z;
        }

        public override string ToString() {
            return string.Format("({0:F}, {1:F}, {2:F})", x, y, z);
        }
    }

    class Program {
        static Vector3D IntersectPoint(Vector3D rayVector, Vector3D rayPoint, Vector3D planeNormal, Vector3D planePoint) {
            var diff = rayPoint - planePoint;
            var prod1 = diff.Dot(planeNormal);
            var prod2 = rayVector.Dot(planeNormal);
            var prod3 = prod1 / prod2;
            return rayPoint - rayVector * prod3;
        }

        static void Main(string[] args) {
            var rv = new Vector3D(0.0, -1.0, -1.0);
            var rp = new Vector3D(0.0, 0.0, 10.0);
            var pn = new Vector3D(0.0, 0.0, 1.0);
            var pp = new Vector3D(0.0, 0.0, 5.0);
            var ip = IntersectPoint(rv, rp, pn, pp);
            Console.WriteLine("The ray intersects the plane at {0}", ip);
        }
    }
}
Task: Find the intersection of a line with a plane


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

class Vector3D {
public:
	Vector3D(double x, double y, double z) {
		this->x = x;
		this->y = y;
		this->z = z;
	}

	double dot(const Vector3D& rhs) const {
		return x * rhs.x + y * rhs.y + z * rhs.z;
	}

	Vector3D operator-(const Vector3D& rhs) const {
		return Vector3D(x - rhs.x, y - rhs.y, z - rhs.z);
	}

	Vector3D operator*(double rhs) const {
		return Vector3D(rhs*x, rhs*y, rhs*z);
	}

	friend std::ostream& operator<<(std::ostream&, const Vector3D&);

private:
	double x, y, z;
};

std::ostream & operator<<(std::ostream & os, const Vector3D &f) {
	std::stringstream ss;
	ss << "(" << f.x << ", " << f.y << ", " << f.z << ")";
	return os << ss.str();
}

Vector3D intersectPoint(Vector3D rayVector, Vector3D rayPoint, Vector3D planeNormal, Vector3D planePoint) {
	Vector3D diff = rayPoint - planePoint;
	double prod1 = diff.dot(planeNormal);
	double prod2 = rayVector.dot(planeNormal);
	double prod3 = prod1 / prod2;
	return rayPoint - rayVector * prod3;
}

int main() {
	Vector3D rv = Vector3D(0.0, -1.0, -1.0);
	Vector3D rp = Vector3D(0.0, 0.0, 10.0);
	Vector3D pn = Vector3D(0.0, 0.0, 1.0);
	Vector3D pp = Vector3D(0.0, 0.0, 5.0);
	Vector3D ip = intersectPoint(rv, rp, pn, pp);

	std::cout << "The ray intersects the plane at " << ip << std::endl;

	return 0;
}
Task: Find the intersection of a line with a plane





Java: public class LinePlaneIntersection {
    private static class Vector3D {
        private double x, y, z;

        Vector3D(double x, double y, double z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        Vector3D plus(Vector3D v) {
            return new Vector3D(x + v.x, y + v.y, z + v.z);
        }

        Vector3D minus(Vector3D v) {
            return new Vector3D(x - v.x, y - v.y, z - v.z);
        }

        Vector3D times(double s) {
            return new Vector3D(s * x, s * y, s * z);
        }

        double dot(Vector3D v) {
            return x * v.x + y * v.y + z * v.z;
        }

        @Override
        public String toString() {
            return String.format("(%f, %f, %f)", x, y, z);
        }
    }

    private static Vector3D intersectPoint(Vector3D rayVector, Vector3D rayPoint, Vector3D planeNormal, Vector3D planePoint) {
        Vector3D diff = rayPoint.minus(planePoint);
        double prod1 = diff.dot(planeNormal);
        double prod2 = rayVector.dot(planeNormal);
        double prod3 = prod1 / prod2;
        return rayPoint.minus(rayVector.times(prod3));
    }

    public static void main(String[] args) {
        Vector3D rv = new Vector3D(0.0, -1.0, -1.0);
        Vector3D rp = new Vector3D(0.0, 0.0, 10.0);
        Vector3D pn = new Vector3D(0.0, 0.0, 1.0);
        Vector3D pp = new Vector3D(0.0, 0.0, 5.0);
        Vector3D ip = intersectPoint(rv, rp, pn, pp);
        System.out.println("The ray intersects the plane at " + ip);
    }
}
Task: Find the intersection of a line with a plane







Python: 
from __future__ import print_function
import numpy as np

def LinePlaneCollision(planeNormal, planePoint, rayDirection, rayPoint, epsilon=1e-6):

	ndotu = planeNormal.dot(rayDirection)
	if abs(ndotu) < epsilon:
		raise RuntimeError("no intersection or line is within plane")

	w = rayPoint - planePoint
	si = -planeNormal.dot(w) / ndotu
	Psi = w + si * rayDirection + planePoint
	return Psi


if __name__=="__main__":
	
	planeNormal = np.array([0, 0, 1])
	planePoint = np.array([0, 0, 5]) 

	
	rayDirection = np.array([0, -1, -1])
	rayPoint = np.array([0, 0, 10]) 

	Psi = LinePlaneCollision(planeNormal, planePoint, rayDirection, rayPoint)
	print ("intersection at", Psi)
Task: Find the intersection of a line with a plane








VB: Module Module1

    Class Vector3D
        Private ReadOnly x As Double
        Private ReadOnly y As Double
        Private ReadOnly z As Double

        Sub New(nx As Double, ny As Double, nz As Double)
            x = nx
            y = ny
            z = nz
        End Sub

        Public Function Dot(rhs As Vector3D) As Double
            Return x * rhs.x + y * rhs.y + z * rhs.z
        End Function

        Public Shared Operator +(ByVal a As Vector3D, ByVal b As Vector3D) As Vector3D
            Return New Vector3D(a.x + b.x, a.y + b.y, a.z + b.z)
        End Operator

        Public Shared Operator -(ByVal a As Vector3D, ByVal b As Vector3D) As Vector3D
            Return New Vector3D(a.x - b.x, a.y - b.y, a.z - b.z)
        End Operator

        Public Shared Operator *(ByVal a As Vector3D, ByVal b As Double) As Vector3D
            Return New Vector3D(a.x * b, a.y * b, a.z * b)
        End Operator

        Public Overrides Function ToString() As String
            Return String.Format("({0:F}, {1:F}, {2:F})", x, y, z)
        End Function
    End Class

    Function IntersectPoint(rayVector As Vector3D, rayPoint As Vector3D, planeNormal As Vector3D, planePoint As Vector3D) As Vector3D
        Dim diff = rayPoint - planePoint
        Dim prod1 = diff.Dot(planeNormal)
        Dim prod2 = rayVector.Dot(planeNormal)
        Dim prod3 = prod1 / prod2
        Return rayPoint - rayVector * prod3
    End Function

    Sub Main()
        Dim rv = New Vector3D(0.0, -1.0, -1.0)
        Dim rp = New Vector3D(0.0, 0.0, 10.0)
        Dim pn = New Vector3D(0.0, 0.0, 1.0)
        Dim pp = New Vector3D(0.0, 0.0, 5.0)
        Dim ip = IntersectPoint(rv, rp, pn, pp)
        Console.WriteLine("The ray intersects the plane at {0}", ip)
    End Sub

End Module
Task: Find the intersection of a line with a plane




Go: package main

import "fmt"

type Vector3D struct{ x, y, z float64 }

func (v *Vector3D) Add(w *Vector3D) *Vector3D {
    return &Vector3D{v.x + w.x, v.y + w.y, v.z + w.z}
}

func (v *Vector3D) Sub(w *Vector3D) *Vector3D {
    return &Vector3D{v.x - w.x, v.y - w.y, v.z - w.z}
}

func (v *Vector3D) Mul(s float64) *Vector3D {
    return &Vector3D{s * v.x, s * v.y, s * v.z}
}

func (v *Vector3D) Dot(w *Vector3D) float64 {
    return v.x*w.x + v.y*w.y + v.z*w.z
}

func (v *Vector3D) String() string {
    return fmt.Sprintf("(%v, %v, %v)", v.x, v.y, v.z)
}

func intersectPoint(rayVector, rayPoint, planeNormal, planePoint *Vector3D) *Vector3D {
    diff := rayPoint.Sub(planePoint)
    prod1 := diff.Dot(planeNormal)
    prod2 := rayVector.Dot(planeNormal)
    prod3 := prod1 / prod2
    return rayPoint.Sub(rayVector.Mul(prod3))
}

func main() {
    rv := &Vector3D{0.0, -1.0, -1.0}
    rp := &Vector3D{0.0, 0.0, 10.0}
    pn := &Vector3D{0.0, 0.0, 1.0}
    pp := &Vector3D{0.0, 0.0, 5.0}
    ip := intersectPoint(rv, rp, pn, pp)
    fmt.Println("The ray intersects the plane at", ip)
}
Task: Order two numerical lists



C#: namespace RosettaCode.OrderTwoNumericalLists
{
    using System;
    using System.Collections.Generic;

    internal static class Program
    {
        private static bool IsLessThan(this IEnumerable<int> enumerable,
            IEnumerable<int> otherEnumerable)
        {
            using (
                IEnumerator<int> enumerator = enumerable.GetEnumerator(),
                    otherEnumerator = otherEnumerable.GetEnumerator())
            {
                while (true)
                {
                    if (!otherEnumerator.MoveNext())
                    {
                        return false;
                    }

                    if (!enumerator.MoveNext())
                    {
                        return true;
                    }

                    if (enumerator.Current == otherEnumerator.Current)
                    {
                        continue;
                    }

                    return enumerator.Current < otherEnumerator.Current;
                }
            }
        }

        private static void Main()
        {
            Console.WriteLine(
                new[] {1, 2, 1, 3, 2}.IsLessThan(new[] {1, 2, 0, 4, 4, 0, 0, 0}));
        }
    }
}









Ada: with Ada.Text_IO;  use Ada.Text_IO;
procedure Order is

   type IntArray is array (Positive range <>) of Integer;
   List1 : IntArray := (1, 2, 3, 4, 5);
   List2 : IntArray := (1, 2, 1, 5, 2, 2);
   List3 : IntArray := (1, 2, 1, 5, 2);
   List4 : IntArray := (1, 2, 1, 5, 2);

   type Animal is (Rat, Cat, Elephant);
   type AnimalArray is array (Positive range <>) of Animal;
   List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
   List6 : AnimalArray := (Cat, Elephant, Rat);
   List7 : AnimalArray := (Cat, Cat, Elephant);

begin
   Put_Line (Boolean'Image (List1 > List2)); 
   Put_Line (Boolean'Image (List2 > List3)); 
   Put_Line (Boolean'Image (List3 > List4)); 
   Put_Line (Boolean'Image (List5 > List6)); 
   Put_Line (Boolean'Image (List6 > List7)); 
end Order;
Task: Order two numerical lists

C: int list_cmp(int *a, int la, int *b, int lb)
{
	int i, l = la;
	if (l > lb) l = lb;
	for (i = 0; i < l; i++) {
		if (a[i] == b[i]) continue;
		return (a[i] > b[i]) ? 1 : -1;
	}
	if (la == lb) return 0;
	return la > lb ? 1 : -1;
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;
procedure Order is

   type IntArray is array (Positive range <>) of Integer;
   List1 : IntArray := (1, 2, 3, 4, 5);
   List2 : IntArray := (1, 2, 1, 5, 2, 2);
   List3 : IntArray := (1, 2, 1, 5, 2);
   List4 : IntArray := (1, 2, 1, 5, 2);

   type Animal is (Rat, Cat, Elephant);
   type AnimalArray is array (Positive range <>) of Animal;
   List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
   List6 : AnimalArray := (Cat, Elephant, Rat);
   List7 : AnimalArray := (Cat, Cat, Elephant);

begin
   Put_Line (Boolean'Image (List1 > List2)); 
   Put_Line (Boolean'Image (List2 > List3)); 
   Put_Line (Boolean'Image (List3 > List4)); 
   Put_Line (Boolean'Image (List5 > List6)); 
   Put_Line (Boolean'Image (List6 > List7)); 
end Order;
Task: Order two numerical lists


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

int main() {
  std::vector<int> a;
  a.push_back(1);
  a.push_back(2);
  a.push_back(1);
  a.push_back(3);
  a.push_back(2);
  std::vector<int> b;
  b.push_back(1);
  b.push_back(2);
  b.push_back(0);
  b.push_back(4);
  b.push_back(4);
  b.push_back(0);
  b.push_back(0);
  b.push_back(0);

  std::cout << std::boolalpha << (a < b) << std::endl; 
  return 0;
}










Ada: with Ada.Text_IO;  use Ada.Text_IO;
procedure Order is

   type IntArray is array (Positive range <>) of Integer;
   List1 : IntArray := (1, 2, 3, 4, 5);
   List2 : IntArray := (1, 2, 1, 5, 2, 2);
   List3 : IntArray := (1, 2, 1, 5, 2);
   List4 : IntArray := (1, 2, 1, 5, 2);

   type Animal is (Rat, Cat, Elephant);
   type AnimalArray is array (Positive range <>) of Animal;
   List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
   List6 : AnimalArray := (Cat, Elephant, Rat);
   List7 : AnimalArray := (Cat, Cat, Elephant);

begin
   Put_Line (Boolean'Image (List1 > List2)); 
   Put_Line (Boolean'Image (List2 > List3)); 
   Put_Line (Boolean'Image (List3 > List4)); 
   Put_Line (Boolean'Image (List5 > List6)); 
   Put_Line (Boolean'Image (List6 > List7)); 
end Order;
Task: Order two numerical lists




Go: package main

import "fmt"



func lessRune(a, b []rune) bool {
    return string(a) < string(b) 
}



type numericType int

func lessNT(a, b []numericType) bool {
    l := len(a)
    if len(b) < l {
        l = len(b)
    }
    for i := 0; i < l; i++ {
        if a[i] != b[i] {
            return a[i] < b[i]
        }
    }
    return l < len(b)
}

var testCases = [][][]numericType{
    {{0}, {}},
    {{}, {}},
    {{}, {0}},

    {{-1}, {0}},
    {{0}, {0}},
    {{0}, {-1}},

    {{0}, {0, -1}},
    {{0}, {0, 0}},
    {{0}, {0, 1}},
    {{0, -1}, {0}},
    {{0, 0}, {0}},
    {{0, 0}, {1}},
}

func main() {
    
    for _, tc := range testCases {
        fmt.Printf("order %6s before %6s : %t\n",
            fmt.Sprintf("%v", tc[0]),
            fmt.Sprintf("%v", tc[1]),
            lessNT(tc[0], tc[1]))
    }
    fmt.Println()

    
    
    for _, tc := range testCases {
        a := toByte(tc[0])
        b := toByte(tc[1])
        fmt.Printf("order %6q before %6q : %t\n",
            string(a),
            string(b),
            lessByte(a, b))
    }
}

func toByte(a []numericType) []byte {
    b := make([]byte, len(a))
    for i, n := range a {
        b[i] = 'b' + byte(n)
    }
    return b
}








Ada: with Ada.Text_IO;  use Ada.Text_IO;
procedure Order is

   type IntArray is array (Positive range <>) of Integer;
   List1 : IntArray := (1, 2, 3, 4, 5);
   List2 : IntArray := (1, 2, 1, 5, 2, 2);
   List3 : IntArray := (1, 2, 1, 5, 2);
   List4 : IntArray := (1, 2, 1, 5, 2);

   type Animal is (Rat, Cat, Elephant);
   type AnimalArray is array (Positive range <>) of Animal;
   List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
   List6 : AnimalArray := (Cat, Elephant, Rat);
   List7 : AnimalArray := (Cat, Cat, Elephant);

begin
   Put_Line (Boolean'Image (List1 > List2)); 
   Put_Line (Boolean'Image (List2 > List3)); 
   Put_Line (Boolean'Image (List3 > List4)); 
   Put_Line (Boolean'Image (List5 > List6)); 
   Put_Line (Boolean'Image (List6 > List7)); 
end Order;
Task: Order two numerical lists





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

public class ListOrder{
	public static boolean ordered(double[] first, double[] second){
		if(first.length == 0) return true;
		if(second.length == 0) return false;
		if(first[0] == second[0])
			return ordered(Arrays.copyOfRange(first, 1, first.length),
					Arrays.copyOfRange(second, 1, second.length));
		return first[0] < second[0];
	}
	
	public static <T extends Comparable<? super T>> boolean ordered(List<T> first, List<T> second){
		int i = 0;
		for(; i < first.size() && i < second.size();i++){
			int cmp = first.get(i).compareTo(second.get(i));
			if(cmp == 0) continue;
			if(cmp < 0) return true;
			return false;
		}
		return i == first.size();
	}
	
	public static boolean ordered2(double[] first, double[] second){
		int i = 0;
		for(; i < first.length && i < second.length;i++){
			if(first[i] == second[i]) continue;
			if(first[i] < second[i]) return true;
			return false;
		}
		return i == first.length;
	}
}







Ada: with Ada.Text_IO;  use Ada.Text_IO;
procedure Order is

   type IntArray is array (Positive range <>) of Integer;
   List1 : IntArray := (1, 2, 3, 4, 5);
   List2 : IntArray := (1, 2, 1, 5, 2, 2);
   List3 : IntArray := (1, 2, 1, 5, 2);
   List4 : IntArray := (1, 2, 1, 5, 2);

   type Animal is (Rat, Cat, Elephant);
   type AnimalArray is array (Positive range <>) of Animal;
   List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
   List6 : AnimalArray := (Cat, Elephant, Rat);
   List7 : AnimalArray := (Cat, Cat, Elephant);

begin
   Put_Line (Boolean'Image (List1 > List2)); 
   Put_Line (Boolean'Image (List2 > List3)); 
   Put_Line (Boolean'Image (List3 > List4)); 
   Put_Line (Boolean'Image (List5 > List6)); 
   Put_Line (Boolean'Image (List6 > List7)); 
end Order;
Task: Order two numerical lists







Python: >>> [1,2,1,3,2] < [1,2,0,4,4,0,0,0]
False





Ada: with Ada.Text_IO;  use Ada.Text_IO;
procedure Order is

   type IntArray is array (Positive range <>) of Integer;
   List1 : IntArray := (1, 2, 3, 4, 5);
   List2 : IntArray := (1, 2, 1, 5, 2, 2);
   List3 : IntArray := (1, 2, 1, 5, 2);
   List4 : IntArray := (1, 2, 1, 5, 2);

   type Animal is (Rat, Cat, Elephant);
   type AnimalArray is array (Positive range <>) of Animal;
   List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
   List6 : AnimalArray := (Cat, Elephant, Rat);
   List7 : AnimalArray := (Cat, Cat, Elephant);

begin
   Put_Line (Boolean'Image (List1 > List2)); 
   Put_Line (Boolean'Image (List2 > List3)); 
   Put_Line (Boolean'Image (List3 > List4)); 
   Put_Line (Boolean'Image (List5 > List6)); 
   Put_Line (Boolean'Image (List6 > List7)); 
end Order;
Task: Order two numerical lists








VB: Private Function order(list1 As Variant, list2 As Variant) As Boolean
    i = 1
    Do While list1(i) <= list2(i)
        i = i + 1
        If i > UBound(list1) Then
            order = True
            Exit Function
        End If
        If i > UBound(list2) Then
            order = False
            Exit Function
        End If
    Loop
    order = False
End Function
Public Sub main()
    Debug.Print order([{1, 2, 3, 4}], [{1,2,0,1,2}])
    Debug.Print order([{1, 2, 3, 4}], [{1,2,3}])
    Debug.Print order([{1, 2, 3}], [{1,2,3,4}])
End Sub




Ada: with Ada.Text_IO;  use Ada.Text_IO;
procedure Order is

   type IntArray is array (Positive range <>) of Integer;
   List1 : IntArray := (1, 2, 3, 4, 5);
   List2 : IntArray := (1, 2, 1, 5, 2, 2);
   List3 : IntArray := (1, 2, 1, 5, 2);
   List4 : IntArray := (1, 2, 1, 5, 2);

   type Animal is (Rat, Cat, Elephant);
   type AnimalArray is array (Positive range <>) of Animal;
   List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
   List6 : AnimalArray := (Cat, Elephant, Rat);
   List7 : AnimalArray := (Cat, Cat, Elephant);

begin
   Put_Line (Boolean'Image (List1 > List2)); 
   Put_Line (Boolean'Image (List2 > List3)); 
   Put_Line (Boolean'Image (List3 > List4)); 
   Put_Line (Boolean'Image (List5 > List6)); 
   Put_Line (Boolean'Image (List6 > List7)); 
end Order;
Task: Order two numerical lists

C: int list_cmp(int *a, int la, int *b, int lb)
{
	int i, l = la;
	if (l > lb) l = lb;
	for (i = 0; i < l; i++) {
		if (a[i] == b[i]) continue;
		return (a[i] > b[i]) ? 1 : -1;
	}
	if (la == lb) return 0;
	return la > lb ? 1 : -1;
}
Task: Order two numerical lists



C#: namespace RosettaCode.OrderTwoNumericalLists
{
    using System;
    using System.Collections.Generic;

    internal static class Program
    {
        private static bool IsLessThan(this IEnumerable<int> enumerable,
            IEnumerable<int> otherEnumerable)
        {
            using (
                IEnumerator<int> enumerator = enumerable.GetEnumerator(),
                    otherEnumerator = otherEnumerable.GetEnumerator())
            {
                while (true)
                {
                    if (!otherEnumerator.MoveNext())
                    {
                        return false;
                    }

                    if (!enumerator.MoveNext())
                    {
                        return true;
                    }

                    if (enumerator.Current == otherEnumerator.Current)
                    {
                        continue;
                    }

                    return enumerator.Current < otherEnumerator.Current;
                }
            }
        }

        private static void Main()
        {
            Console.WriteLine(
                new[] {1, 2, 1, 3, 2}.IsLessThan(new[] {1, 2, 0, 4, 4, 0, 0, 0}));
        }
    }
}