September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -7,9 +7,10 @@
(defn bead-sort [xs]
(->> xs
(map #(repeat 1 %))
(map #(repeat % 1))
transpose
transpose
(map #(reduce + %))))
;; This algorithm does not work if collection has zero
(-> [5 2 4 1 3 3 9] bead-sort println)

View file

@ -15,8 +15,8 @@ public class BeadSort
}
int[] beadSort(int[] arr)
{
int max=0;
for(int i=0;i<arr.length;i++)
int max=a[0];
for(int i=1;i<arr.length;i++)
if(arr[i]>max)
max=arr[i];

View file

@ -1,16 +1,10 @@
try:
from itertools import zip_longest
except:
try:
from itertools import izip_longest as zip_longest
except:
zip_longest = lambda *args: map(None, *args)
#!/bin/python3
from itertools import zip_longest
def beadsort(l):
return map(len, columns(columns([[1] * e for e in l])))
return list(map(sum, zip_longest(*[[1] * e for e in l], fillvalue=0)))
def columns(l):
return [filter(None, x) for x in zip_longest(*l)]
# Demonstration code:
print(beadsort([5,3,1,7,4,1,1]))

View file

@ -0,0 +1,33 @@
Option Base 1
Private Function sq_add(arr As Variant, x As Double) As Variant
Dim res() As Variant
ReDim res(UBound(arr))
For i = 1 To UBound(arr)
res(i) = arr(i) + x
Next i
sq_add = res
End Function
Private Function beadsort(ByVal a As Variant) As Variant
Dim poles() As Variant
ReDim poles(WorksheetFunction.Max(a))
For i = 1 To UBound(a)
For j = 1 To a(i)
poles(j) = poles(j) + 1
Next j
Next i
For j = 1 To UBound(a)
a(j) = 0
Next j
For i = 1 To UBound(poles)
For j = 1 To poles(i)
a(j) = a(j) + 1
Next j
Next i
beadsort = a
End Function
Public Sub main()
Debug.Print Join(beadsort([{5, 3, 1, 7, 4, 1, 1, 20}]), ", ")
End Sub