Added column1 programs
This commit is contained in:
commit
fcfda903d2
15
column1/problem3.py
Normal file
15
column1/problem3.py
Normal file
@ -0,0 +1,15 @@
|
||||
from bitarray import bitarray
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
n = int(sys.argv[1])
|
||||
arr = (n + 1) * bitarray('0')
|
||||
|
||||
for line in sys.stdin:
|
||||
num = int(line)
|
||||
arr[num] = 1
|
||||
|
||||
for (i, bit) in enumerate(arr):
|
||||
if bit:
|
||||
print i
|
||||
|
19
column1/problem4.py
Normal file
19
column1/problem4.py
Normal file
@ -0,0 +1,19 @@
|
||||
import random
|
||||
|
||||
def k_uniq_rand_nums_of_n(n, k):
|
||||
nums = [0]
|
||||
for i in xrange(1, n):
|
||||
nums.append(i)
|
||||
j = random.randint(0, i)
|
||||
nums[i] = nums[j]
|
||||
nums[j] = i
|
||||
|
||||
return nums[:k]
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
n = int(sys.argv[1])
|
||||
k = int(sys.argv[2])
|
||||
for i in k_uniq_rand_nums_of_n(n, k):
|
||||
print i
|
||||
|
9
column1/test.sh
Normal file
9
column1/test.sh
Normal file
@ -0,0 +1,9 @@
|
||||
echo "Generating input"
|
||||
python problem4.py $1 $2 > input
|
||||
echo "Generating output"
|
||||
cat input | python problem3.py $1 > output
|
||||
echo "Sorting input"
|
||||
sort -g input > input_sorted
|
||||
echo "Diffing sorted input and output"
|
||||
diff -s input_sorted output
|
||||
rm input input_sorted output
|
Loading…
Reference in New Issue
Block a user