w.i.p.
This commit is contained in:
		@@ -35,25 +35,69 @@ def ResetData():
 | 
				
			|||||||
    for letter in all_possibilities:
 | 
					    for letter in all_possibilities:
 | 
				
			||||||
        possibilities[letter] = list(all_possibilities)
 | 
					        possibilities[letter] = list(all_possibilities)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def RemoveImpossibleLetters(good_letters, good_positions):
 | 
				
			||||||
 | 
					    # generate inverse list of good_positions
 | 
				
			||||||
 | 
					    bad_positions = list(all_possibilities)
 | 
				
			||||||
 | 
					    for position in good_positions:
 | 
				
			||||||
 | 
					        bad_positions.remove(position)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    # first, get rid of the other letters from the positions used
 | 
				
			||||||
 | 
					    for position in good_positions: # positions used
 | 
				
			||||||
 | 
					        to_remove_list = []
 | 
				
			||||||
 | 
					        for l in possibilities[position]:
 | 
				
			||||||
 | 
					            if(not (l in good_letters)):
 | 
				
			||||||
 | 
					                to_remove_list.append(l)
 | 
				
			||||||
 | 
					        for to_remove in to_remove_list:
 | 
				
			||||||
 | 
					            if(to_remove in possibilities[position]):
 | 
				
			||||||
 | 
					                possibilities[position].remove(to_remove)
 | 
				
			||||||
 | 
					    # second, get rid of the good letters from all the other positions
 | 
				
			||||||
 | 
					    for position in bad_positions: # positions not used
 | 
				
			||||||
 | 
					        for to_remove in good_letters:
 | 
				
			||||||
 | 
					            if(to_remove in possibilities[position]):
 | 
				
			||||||
 | 
					                possibilities[position].remove(to_remove)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def ParsePossibilities(text):
 | 
					def ParsePossibilities(text):
 | 
				
			||||||
    text_len = len(text)
 | 
					    text_len = len(text)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # The easy ones first:
 | 
				
			||||||
    if(text_len == 2):
 | 
					    if(text_len == 2):
 | 
				
			||||||
        good_letters = [ text[0], text[1] ]
 | 
					        good_letters = list(text)
 | 
				
			||||||
        print(good_letters)
 | 
					        good_positions = ['c', 'f']
 | 
				
			||||||
 | 
					        RemoveImpossibleLetters(good_letters, good_positions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # first, get rid of the good letters from all the other positions
 | 
					    if(text_len == 3):
 | 
				
			||||||
        for letter in ['a', 'b', 'd', 'e', 'g']: # all the positions not used by #1
 | 
					        good_letters = list(text)
 | 
				
			||||||
            for to_remove in good_letters:
 | 
					        good_positions = ['a', 'c', 'f']
 | 
				
			||||||
                possibilities[letter].remove(to_remove)
 | 
					        RemoveImpossibleLetters(good_letters, good_positions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(text_len == 4):
 | 
				
			||||||
 | 
					        good_letters = list(text)
 | 
				
			||||||
 | 
					        good_positions = ['b', 'c', 'd', 'f']
 | 
				
			||||||
 | 
					        RemoveImpossibleLetters(good_letters, good_positions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # This one straight up doesn't help:
 | 
				
			||||||
 | 
					    # if(text_len == 7):
 | 
				
			||||||
 | 
					    #     good_letters = list(text)
 | 
				
			||||||
 | 
					    #     good_positions = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
 | 
				
			||||||
 | 
					    #     RemoveImpossibleLetters(good_letters, good_positions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # The harder ones second:
 | 
				
			||||||
 | 
					    if(text_len == 5):
 | 
				
			||||||
 | 
					        # Could be 2, 3, or 5
 | 
				
			||||||
 | 
					        # MUST  contain positions 'a', 'd', and 'g' in any 5-position number
 | 
				
			||||||
 | 
					        # MIGHT contain positions 'b' and 'f' for FIVE
 | 
				
			||||||
 | 
					        #                         'c' and 'e' for TWO
 | 
				
			||||||
 | 
					        #                         'c' and 'f' for THREE
 | 
				
			||||||
 | 
					        # if one of them is found with two others, it's either c or f
 | 
				
			||||||
 | 
					        # if one of them is not found with two others, it could be b or e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(text_len == 6):
 | 
				
			||||||
 | 
					        # Could be 0, 6, or 9
 | 
				
			||||||
 | 
					        # MUST  contain positions 'a', 'b', 'f', and 'g' in any 6-position number
 | 
				
			||||||
 | 
					        # MIGHT contain positions 'c' and 'd' for NINE
 | 
				
			||||||
 | 
					        #                         'c' and 'e' for ZERO
 | 
				
			||||||
 | 
					        #                         'd' and 'e' for SIX
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # second, get rid of the other letters from the positions used by #1
 | 
					 | 
				
			||||||
        for letter in ['c', 'f']:
 | 
					 | 
				
			||||||
            to_remove_list = []
 | 
					 | 
				
			||||||
            for l in possibilities[letter]:
 | 
					 | 
				
			||||||
                if(not (l in good_letters)):
 | 
					 | 
				
			||||||
                    to_remove_list.append(l)
 | 
					 | 
				
			||||||
            for to_remove in to_remove_list:
 | 
					 | 
				
			||||||
                possibilities[letter].remove(to_remove)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
total = 0
 | 
					total = 0
 | 
				
			||||||
with open('example_data', 'r') as fp:
 | 
					with open('example_data', 'r') as fp:
 | 
				
			||||||
@@ -62,7 +106,7 @@ with open('example_data', 'r') as fp:
 | 
				
			|||||||
        ResetData()
 | 
					        ResetData()
 | 
				
			||||||
        split_line = line.split(' | ')
 | 
					        split_line = line.split(' | ')
 | 
				
			||||||
        data = split_line[0].split()
 | 
					        data = split_line[0].split()
 | 
				
			||||||
        print(data)
 | 
					        # print(data)
 | 
				
			||||||
        codes = split_line[1]
 | 
					        codes = split_line[1]
 | 
				
			||||||
        for val in codes.split():
 | 
					        for val in codes.split():
 | 
				
			||||||
            if(len(val) in [2, 3, 4, 7]):
 | 
					            if(len(val) in [2, 3, 4, 7]):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user