diff --git a/branchless.py b/branchless.py index 2d3490a..c7a44eb 100644 --- a/branchless.py +++ b/branchless.py @@ -26,6 +26,26 @@ def stringcompare(a,b): return tmp == 0 +def lowerbound(x, t): + #base = t + #l = len(t) + #while(l > 1): + # half = l >> 1 + # base += (base[half -1] < x) * half + # l -= half + #return base + k = 1 + l = len(t) + while k <= l: + #print(t[k]) + k = (k << 1) + (t[k] < x) + #return k.bit_count(),k + #k >>= k.bit_count() + #print(bin(k)) + #return t[k] + #return k.bit_count() + return k + def test(): assert(IsOdd(3) == True) assert(IsOdd(2) == False) @@ -55,3 +75,10 @@ def test(): test() + +for i in range(0, 10): + k = lowerbound(i,[0,1,2,3,4,5,6,7,8,9]) + print(i, k, k.bit_count()) + +print(lowerbound(5,[6, 3, 7, 1, 5, 8, 9, 0, 2, 4])) + diff --git a/heaps.py b/heaps.py index 038b1db..179e1f1 100644 --- a/heaps.py +++ b/heaps.py @@ -9,7 +9,7 @@ def heaps(k, A): yield A else: for i in range(0, k): - yield from heap(k-1, A) + yield from heaps(k-1, A) if k & 1 == 0: A[i],A[k-1] = A[k-1],A[i] else: @@ -31,5 +31,24 @@ def heaps_count_swaps(k, A): return c -A038156 = lambda n: heaps_count_swaps(n, list(range(0,n))) +#A038156 = lambda n: heaps_count_swaps(n, list(range(0,n))) + +def a(n): + m=0 + L = list(range(0,n)) + for p in heaps(len(L),L): + m = max(m,Permutation(p).rank()) + return m + + +def a(n): + m=0 + L = list(range(0,n)) + for p in heaps(len(L),L): + m = Permutation(p).rank() + return m + + + +print([a(n) for n in range(0,10)]) diff --git a/mass_resolv.sh b/mass_resolv.sh new file mode 100644 index 0000000..0053a07 --- /dev/null +++ b/mass_resolv.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Author DarĂ­o Clavijo 2024 +cat $1 | nslookup | grep -e "[Name|Address]" | grep -e "#" -v | grep -e "Non" -v | grep -e "Server" -v | sed -e 's/\s//g;s/Name://g;s/Address://g;' | awk '{split($0,col1); getline; for (i=1; i<=NF; i++) print col1[i], $i}'