Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
1
Task/Sort-an-integer-array/8th/sort-an-integer-array.8th
Normal file
1
Task/Sort-an-integer-array/8th/sort-an-integer-array.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
[ 10,2,100 ] ' n:cmp a:sort . cr
|
||||
7
Task/Sort-an-integer-array/Axe/sort-an-integer-array.axe
Normal file
7
Task/Sort-an-integer-array/Axe/sort-an-integer-array.axe
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2→{L₁}
|
||||
4→{L₁+1}
|
||||
3→{L₁+2}
|
||||
1→{L₁+3}
|
||||
2→{L₁+4}
|
||||
|
||||
SortD(L₁,5)
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
' version 11-03-2016
|
||||
' compile with: fbc -s console
|
||||
|
||||
#Include Once "crt/stdlib.bi" ' needed for qsort subroutine
|
||||
|
||||
' Declare Sub qsort (ByVal As Any Ptr, <== point to start of array
|
||||
' ByVal As size_t, <== size of array
|
||||
' ByVal As size_t, <== size of array element
|
||||
' ByVal As Function(ByVal As Any Ptr, ByVal As Any Ptr) As Long) <== callback function
|
||||
' declare callback function with Cdecl to ensures that the parameters are passed in the correct order
|
||||
'
|
||||
' size of long: 4 bytes on 32bit OS, 8 bytes on 64bit OS
|
||||
|
||||
' ascending
|
||||
Function callback Cdecl (ByVal element1 As Any Ptr, ByVal element2 As Any Ptr) As Long
|
||||
Function = *Cast(Long Ptr, element1) - *Cast(Long Ptr, element2)
|
||||
End Function
|
||||
|
||||
' Function callback Cdecl (ByVal element1 As Any Ptr, ByVal element2 As Any Ptr) As Long
|
||||
' Dim As Long e1 = *Cast(Long Ptr, element1)
|
||||
' Dim As Long e2 = *Cast(Long Ptr, element2)
|
||||
' Dim As Long result = Sgn(e1 - e2)
|
||||
' If Sgn(e1) = -1 And Sgn(e2) = -1 Then result = -result
|
||||
' Function = result
|
||||
' End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As Long i, array(20)
|
||||
|
||||
Dim As Long lb = LBound(array)
|
||||
Dim As Long ub = UBound(array)
|
||||
|
||||
For i = lb To ub ' fill array
|
||||
array(i) = 10 - i
|
||||
Next
|
||||
|
||||
Print
|
||||
Print "unsorted array"
|
||||
For i = lb To ub ' display array
|
||||
Print Using "###";array(i);
|
||||
Next
|
||||
Print : Print
|
||||
|
||||
' sort array
|
||||
qsort(@array(lb), ub - lb +1, SizeOf(array), @callback)
|
||||
|
||||
Print "sorted array"
|
||||
For i = lb To ub ' show sorted array
|
||||
Print Using "###";array(i);
|
||||
Next
|
||||
Print
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
nums = [5, 2, 78, 2, 578, -42]
|
||||
println( sort(nums) ) // sort in ascending order
|
||||
println( nums.sortWith((>)) ) // sort in descending order
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
local(array) = array(5,20,3,2,6,1,4)
|
||||
#array->sort
|
||||
#array // 1, 2, 3, 4, 5, 6, 20
|
||||
|
||||
// Reverse the sort order
|
||||
#array->sort(false)
|
||||
#array // 20, 6, 5, 4, 3, 2, 1
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
l = [7, 4, 23]
|
||||
l.sort()
|
||||
put l
|
||||
-- [4, 7, 23]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
put "3,2,5,4,1" into X
|
||||
sort items of X numeric
|
||||
put X
|
||||
-- outputs "1,2,3,4,5"
|
||||
6
Task/Sort-an-integer-array/Nim/sort-an-integer-array.nim
Normal file
6
Task/Sort-an-integer-array/Nim/sort-an-integer-array.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import algorithm
|
||||
|
||||
var a: array[0..8,int] = [2,3,5,8,4,1,6,9,7]
|
||||
a.sort(system.cmp[int], Ascending)
|
||||
for x in a:
|
||||
echo(x)
|
||||
|
|
@ -0,0 +1 @@
|
|||
[ 8, 2, 5, 9, 1, 3, 6, 7, 4 ] sort
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Construct a list of numbers
|
||||
<@ LETCNSLSTLIT>L|65^84^1^25^77^4^47^2^42^44^41^25^69^3^51^45^4^39^</@>
|
||||
Numbers sort as strings
|
||||
<@ ACTSRTENTLST>L</@>
|
||||
<@ SAYDMPLST>L</@>
|
||||
<@ ACTSRTENTLSTLIT>L|__StringDescending</@>
|
||||
<@ SAYDMPLST>L</@>
|
||||
|
||||
Construct another list of numbers
|
||||
<@ LETCNSLSTLIT>list|65^84^1^25^77^4^47^2^42^44^41^25^69^3^51^45^4^39^</@>
|
||||
Numbers sorted as numbers
|
||||
<@ ACTSRTENTLSTLIT>list|__Numeric</@>
|
||||
<@ SAYDMPLST>list</@>
|
||||
<@ ACTSRTENTLSTLIT>list|__NumericDescending</@>
|
||||
<@ SAYDMPLST>list</@>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Construct a list of numbers
|
||||
|
||||
Numbers sort as strings
|
||||
|
||||
1^2^25^25^3^39^4^4^41^42^44^45^47^51^65^69^77^84^
|
||||
|
||||
84^77^69^65^51^47^45^44^42^41^4^4^39^3^25^25^2^1^
|
||||
|
||||
Construct another list of numbers
|
||||
|
||||
Numbers sorted as numbers
|
||||
|
||||
1^2^3^4^4^25^25^39^41^42^44^45^47^51^65^69^77^84^
|
||||
|
||||
84^77^69^65^51^47^45^44^42^41^39^25^25^4^4^3^2^1^
|
||||
|
|
@ -0,0 +1 @@
|
|||
?sort({9, 10, 3, 1, 4, 5, 8, 7, 6, 2})
|
||||
|
|
@ -0,0 +1 @@
|
|||
(7, 5, 1, 2, 3, 8, 9) sort join(", ") print
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
aArray = [2,4,3,1,2]
|
||||
see sort(aArray)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var nums = [2,4,3,1,2];
|
||||
var sorted = nums.sort; # returns a new sorted array.
|
||||
nums.sort!; # sort 'nums' "in-place"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
var arr = { 2, 8, 1, 4, 6, 5, 3, 7, 0, 9 };
|
||||
sort(arr);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var nums = [2, 4, 3, 1, 2]
|
||||
nums.sortInPlace()
|
||||
print(nums)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var nums = [2, 4, 3, 1, 2]
|
||||
nums.sortInPlace(<)
|
||||
print(nums)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var nums = [2, 4, 3, 1, 2]
|
||||
nums.sort(<)
|
||||
println(nums)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var nums = [2, 4, 3, 1, 2]
|
||||
sort(&nums)
|
||||
println(nums)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var nums = [2, 4, 3, 1, 2]
|
||||
sort(&nums, <)
|
||||
println(nums)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
let nums = [2,4,3,1,2].sort()
|
||||
print(nums)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
let nums = [2,4,3,1,2].sort(<)
|
||||
print(nums)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
let nums = sorted([2,4,3,1,2])
|
||||
println(nums)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
let nums = [2,4,3,1,2].sorted(<)
|
||||
println(nums)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
decl int<> nums
|
||||
append 2 4 3 1 2 nums
|
||||
sort nums
|
||||
|
|
@ -0,0 +1 @@
|
|||
@sort [39 47 40 53 14 23 88 52 78 62 41 92 88 66 5 40]
|
||||
1
Task/Sort-an-integer-array/jq/sort-an-integer-array.jq
Normal file
1
Task/Sort-an-integer-array/jq/sort-an-integer-array.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
[2,1,3] | sort # => [1,2,3]
|
||||
Loading…
Add table
Add a link
Reference in a new issue