Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -5,3 +5,5 @@ The order is determined by [[wp:Lexicographical order#Ordering of sequences of v
If the first elements are equal, then the second elements should be compared, and so on, until one of the list has no more elements.
If the first list runs out of elements the result is <code>true</code>.
If the second list or both run out of elements the result is <code>false</code>.
<small>Note: further clarification of lexicographical ordering is expounded on the talk page [[Talk:Order_two_numerical_lists#Lexicographic_order|here]] and [[Talk:Order_two_numerical_lists#Is_the_task_statement_consistent.3F|here]].</small>

View file

@ -0,0 +1,14 @@
function isallreal{T<:AbstractArray}(a::T)
all(map(x->isa(x, Real), a))
end
function islexfirst{T<:AbstractArray,U<:AbstractArray}(a::T, b::U)
isallreal(a) && isallreal(b) || throw(DomainError())
for i in 1:min(length(a), length(b))
x = a[i]
y = b[i]
x != y || continue
return x < y
end
return length(a) < length(b)
end

View file

@ -0,0 +1,15 @@
tests = {[1, 2, 3],
primes(10),
0:2:6,
[-Inf, 0.0, Inf],
[π, e, φ, catalan],
[2015, 5],
[-sqrt(50.0), 50.0^2],
}
println("Testing islexfirst:")
for (a, b) in combinations(tests, 2)
tres = islexfirst(a, b) ? " is " : " is not "
tres *= "lexically prior to\n "
println("\n ", a, tres, b)
end

View file

@ -1,8 +1,2 @@
let rec ordered_lists = function
| x1::tl1, x2::tl2 ->
(match compare x1 x2 with
| 0 -> ordered_lists (tl1, tl2)
| 1 -> false
| _ -> true)
| [], _ -> true
| _ -> false
# [|1;2;1;3;2|] < [|1;2;0;4;4;0;0;0|];;
- : bool = true

View file

@ -1,20 +1,8 @@
(* copy-paste the code of ordered_lists here *)
let make_num_list p n =
let rec aux acc =
if Random.int p = 0 then acc
else aux (Random.int n :: acc)
in
aux []
let print_num_list lst =
List.iter (Printf.printf " %d") lst;
print_newline()
let () =
Random.self_init();
let lst1 = make_num_list 8 5 in
let lst2 = make_num_list 8 5 in
print_num_list lst1;
print_num_list lst2;
Printf.printf "ordered: %B\n" (ordered_lists (lst1, lst2))
let rec ordered_lists = function
| x1::tl1, x2::tl2 ->
(match compare x1 x2 with
| 0 -> ordered_lists (tl1, tl2)
| 1 -> false
| _ -> true)
| [], _ -> true
| _ -> false

View file

@ -1 +1,20 @@
val ordered_lists : 'a list * 'a list -> bool
(* copy-paste the code of ordered_lists here *)
let make_num_list p n =
let rec aux acc =
if Random.int p = 0 then acc
else aux (Random.int n :: acc)
in
aux []
let print_num_list lst =
List.iter (Printf.printf " %d") lst;
print_newline()
let () =
Random.self_init();
let lst1 = make_num_list 8 5 in
let lst2 = make_num_list 8 5 in
print_num_list lst1;
print_num_list lst2;
Printf.printf "ordered: %B\n" (ordered_lists (lst1, lst2))

View file

@ -0,0 +1 @@
val ordered_lists : 'a list * 'a list -> bool

View file

@ -0,0 +1,33 @@
Function order_list(arr1,arr2)
order_list = "FAIL"
n1 = UBound(arr1): n2 = UBound(arr2)
n = 0 : p = 0
If n1 > n2 Then
max = n2
Else
max = n1
End If
For i = 0 To max
If arr1(i) > arr2(i) Then
n = n + 1
ElseIf arr1(i) = arr2(i) Then
p = p + 1
End If
Next
If (n1 < n2 And n = 0) Or _
(n1 = n2 And n = 0 And p - 1 <> n1) Or _
(n1 > n2 And n = 0 And p = n2) Then
order_list = "PASS"
End If
End Function
WScript.StdOut.WriteLine order_list(Array(-1),Array(0))
WScript.StdOut.WriteLine order_list(Array(0),Array(0))
WScript.StdOut.WriteLine order_list(Array(0),Array(-1))
WScript.StdOut.WriteLine order_list(Array(0),Array(0,-1))
WScript.StdOut.WriteLine order_list(Array(0),Array(0,0))
WScript.StdOut.WriteLine order_list(Array(0),Array(0,1))
WScript.StdOut.WriteLine order_list(Array(0,-1),Array(0))
WScript.StdOut.WriteLine order_list(Array(0,0),Array(0))
WScript.StdOut.WriteLine order_list(Array(0,0),Array(1))
WScript.StdOut.WriteLine order_list(Array(1,2,1,3,2),Array(1,2,0,4,4,0,0,0))