Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def binaryCounter(x):
- if type(x) is not int:
- raise TypeError("Input an integer only")
- numbers = [] # list for initial numbers
- binary = ['0'] # list for binary, with 0 automatically placed due to python treating 0 as empty
- binaryNegative = []
- y = 0
- if x > 0:
- while y != x: # first counts the number from 0 up to the inputted number
- y = y + 1
- numbers.append(y) # appends the numbers into the number list
- for digit in numbers: # computes for the binary for each number in the number list
- convertedBinary = bin(digit)[2:]
- binary.append(str(convertedBinary)) # appends the converted binary numbers into the binary list
- return binary
- else:
- return binaryNegative
- def toPalindrome(x): # for palindromes
- if not (type(x) is str or type(x) is int):
- raise TypeError("Input a string or integer only")
- # this uses the slice notation of lists, from the last character up to the first, counting down by 1
- d = ', '
- return str(x) + (str(x)[::-1]) + d + (str(x)[::-1]) +str(x)
- def numtomaxn(x): # to compute the number in descending order
- y = [] # list to contain the converted numbers
- y[:] = str(x) # this part is to convert the inputted integer into a list per digit
- # descending sort from previous experiment
- for numbers in range(0, len(y) - 1):
- for innerNumber in range(0, len(y) - 1 - numbers):
- if y[innerNumber] < y[innerNumber + 1]:
- y[innerNumber], y[innerNumber + 1] = y[innerNumber + 1], y[innerNumber]
- for i in y:
- print(int(i), end='') # prints out the sorted integer
- return ''
- def bitwise_NAND(x, y): # to compute a bitwise NAND operation on a binary list
- # declaration of initial lists
- first = []
- second = []
- final = []
- first[:] = x
- second[:] = y
- for l1, l2 in zip(first, second):
- if l1 == "1":
- if l2 == '0':
- final.append("1")
- elif l2 == '1':
- final.append("0")
- elif l1 == "0":
- if l2 == '1':
- final.append("1")
- elif l2 == '0':
- final.append("1")
- for i in final: # converts the list into a single string
- print(int(i), end='')
- return ''
- print("Binary")
- print("-------------------------")
- print(binaryCounter(1))
- print(binaryCounter(2))
- print(binaryCounter(3))
- print(binaryCounter(-3))
- print(binaryCounter(6))
- print(binaryCounter(4))
- print(binaryCounter(5))
- print(binaryCounter(11))
- print(binaryCounter(13))
- print(binaryCounter(10))
- print(binaryCounter(15))
- print(binaryCounter(20))
- print(" ")
- print("Palindrome")
- print("-------------------------")
- print(toPalindrome(567))
- print(toPalindrome("Hello"))
- print(toPalindrome("192.168"))
- print(toPalindrome(101))
- print(toPalindrome("Pneumonoultramicroscopicsilicovolcanoconiosis"))
- print(toPalindrome('Bruh'))
- print(toPalindrome('All work and no play makes Jack a dull boy'))
- print(toPalindrome('The fog was as thick as pea soup. This was a problem.'))
- print(toPalindrome(123456789))
- print(toPalindrome("my mama don't like you but she likes everyone"))
- print(toPalindrome('Ruby Kurosawa'))
- print(toPalindrome('Chika Takami'))
- print(" ")
- print("NumToMaxN")
- print("-------------------------")
- print(numtomaxn(576233))
- print(numtomaxn(31415926535))
- print(numtomaxn(2718281828))
- print(numtomaxn(987654321))
- print(numtomaxn(6390123456))
- print(numtomaxn(123987654))
- print(numtomaxn(348597983475937589356))
- print(numtomaxn(12390470812370570934))
- print(numtomaxn(32498790178238914718947892))
- print(numtomaxn(32426))
- print(numtomaxn(9879837976))
- print(numtomaxn(2146878921232))
- print(numtomaxn(59789712213213))
- print(numtomaxn(32166897889788465))
- print(numtomaxn(3215465489786462))
- print(numtomaxn(987654312165498))
- print(numtomaxn(12454648798874))
- print(numtomaxn(51546897879545121))
- print(numtomaxn(97423546))
- print(numtomaxn(879545121))
- print(" ")
- print("bitwise_NAND operation")
- print("-------------------------")
- print(bitwise_NAND("0010011011", "1010000011"))
- print(bitwise_NAND("11100000", "00011111"))
- print(bitwise_NAND("1010101", "1111000"))
- print(bitwise_NAND("1", "0"))
- print(bitwise_NAND("0110110010010010", "1111110000110111"))
- print(bitwise_NAND("010100101010", "100101110101"))
- print(bitwise_NAND("1001001001", "0110011100"))
- print(bitwise_NAND("1111011011", "1010011100"))
- print(bitwise_NAND("1010011010111010000110010", "0001111000001001111000110"))
- print(bitwise_NAND("0101001100011100110010101", "1011100010100000110010001"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement