diff --git a/bit_difference.py b/bit_difference.py new file mode 100644 index 0000000..f6fe3f0 --- /dev/null +++ b/bit_difference.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import sys + +def xor_count(a, b): + xor = a ^ b + i = 0 + while xor != 0: + i = i + (xor & 1) + xor = xor >> 1 + return i + + +def bitwise_difference(A): + s = 0 + for i in range(len(A)): + for j in range(i+1,len(A)): + s = s + xor_count(A[i], A[j]) + return s + + +if __name__ == "__main__": + sys.stdin.readline() + A = sys.stdin.readline().split() + for i in range(len(A)): + A[i] = int(A[i]) + + print(bitwise_difference(A)) diff --git a/bit_difference.txt b/bit_difference.txt new file mode 100644 index 0000000..4406f67 --- /dev/null +++ b/bit_difference.txt @@ -0,0 +1,2 @@ +6 +34 10 52 84 0 71 diff --git a/counting_sheep.py b/counting_sheep.py new file mode 100755 index 0000000..a71db4d --- /dev/null +++ b/counting_sheep.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import sys +import math + +def digits(A, n): + if n == 0: + A[0] = True + return + + while n != 0: + A[n % 10] = True + n = n // 10 + + +def check(A): + n = 0 + for i in range(10): + if A[i]: + n = n + 1 + return n == 10 + + +def count_sheep(start): + if start == 0: + return "INSOMNIA" + + A = [False,False,False,False,False,False,False,False,False,False] + + n = start + while True: + digits(A, n) + if check(A): + return str(n) + n += start + + return "INSOMNIA" + + +if __name__ == "__main__": + i = 0 + for line in sys.stdin: + if i == 0: + i = i + 1 + continue + print('Case #' + str(i) + ": " + count_sheep(int(line))) + i = i + 1 diff --git a/counting_sheep.txt b/counting_sheep.txt new file mode 100644 index 0000000..74eaa92 --- /dev/null +++ b/counting_sheep.txt @@ -0,0 +1,6 @@ +5 +0 +1 +2 +11 +1692