I have written a python script that has tallies representing digits 1-9 (0 is just ":" ) Unlike true Unary languages that are in the form 1^k. I represent values for n as per their decimal digits. The integer 121 is 1_11_1 Overall every k digit out of n "integer" is in Tally notation, and the amount of tallies is the sum of all the digits in a given n "integer" such as 121 = 4, 1_11_1 = 4.
Its called a many-one reduction. If you can transform Instance A(9,33,4) into Instance B(1111_1111 1, 111----111, 1111) in poly-time, then its NP-complete
Transformation rules is to just to enter each integer sequentially when asked in the while loop. Also, when your integer is a negative you do not give a "-" symbol for input. It will ask for input if its a negative integer.
Input
(9,33,4) "9, and then 33 and then 4. One at a time for each input."
Output
'111_1111 1' = 9
111
33>>
111
11 11 =4
Algorithm for the Reduction
# This algorithm is very simple and inconsequential.
# It converts integers into a unary like language
# in poly time. All tallies are represented vertically.
print('If your integer is a negative, the script will ask.')
print("DO NOT GIVE -X integers for input!!!")
print('Script will output multiple - symbols for a negative integer transformation')
while 0 == 0:
ask = input('Enter an integer from a subset-sum instance sequentially.')
askStr = str(ask)
res = list(map(int, str(askStr)))
x = (res)
asktwo = input('Is your integer a negative integer? y or n: ')
if asktwo == str("y"):
twinkle = str('-')
else:
twinkle = str(" ")
for n in x:
if n == 0:
tallyone = ":"
print(twinkle, tallyone)
if n == 1:
print(twinkle, "1")
if n == 2:
print(twinkle, "11")
if n == 3:
print(twinkle, "111")
if n == 4:
print(twinkle, "11 11")
if n == 5:
print(twinkle, "111 11")
if n == 6:
print(twinkle, "111 111")
if n == 7:
print(twinkle, "111_111 1")
if n == 8:
print(twinkle, "1111 1111")
if n == 9:
print(twinkle, "1111_1111 1")
Question
In what way, is this code sloppy? Am I using while loops and variable names in an ugly way? Is my tallies in the print statements hard to read? What is the ugliest parts of my code and how would I improve them?
The code works. But, I don't know enough about python so what mistakes are you seeing in my code?