[HELP] Idk what to do with this programming question. /u/Evening_Oven_8431 Python Education

The question is British Informatics Olympiad 2012 Question 2a : https://www.olympiad.org.uk/papers/2012/bio/round_one.html

This is my code:

# constructing network network = { 'A' : ['D', 'E', 'F', True], 'B' : ['C', 'G', 'H', True], 'C' : ['B', 'I', 'J', True], 'D' : ['A', 'K', 'L', True], 'E' : ['A', 'M', 'N', True], 'F' : ['A', 'N', 'O', True], 'G' : ['B', 'O', 'P', True], 'H' : ['B', 'P', 'Q', True], 'I' : ['C', 'Q', 'R', True], 'J' : ['C', 'R', 'S', True], 'K' : ['D', 'S', 'T', True], 'L' : ['D', 'T', 'M', True], 'M' : ['U', 'L', 'E', True], 'N' : ['U', 'E', 'F', True], 'O' : ['V', 'F', 'G', True], 'P' : ['V', 'G', 'H', True], 'Q' : ['W', 'H', 'I', True], 'R' : ['W', 'I', 'J', True], 'S' : ['X', 'J', 'K', True], 'T' : ['X', 'K', 'L', True], 'U' : ['V', 'M', 'N', True], 'V' : ['U', 'O', 'P', True], 'W' : ['X', 'Q', 'R', True], 'X' : ['W', 'S', 'T', True] } # taking inputs flip_flops = list(input('Enter the names of flip-flop junctions: ')) start = list(input('Enter the start track: ')) points_count = int(input('Enter the number of points to pass through: ')) # modifying based on input for junction in network: if junction in flip_flops: network[junction][3] = False # simulation last_junction = start[0] current_junction = start[1] new_junction = 'NULL' side = False if current_junction == network[start[1]][1] else True side = side if network[current_junction][3] else not side track = [last_junction, current_junction] for _ in range(points_count): if last_junction == network[current_junction][1] or last_junction == network[current_junction][2]: new_junction = network[current_junction][0] else: side = side if network[current_junction][3] else not side if side: new_junction = network[current_junction][1] else: new_junction = network[current_junction][2] track.append(new_junction) last_junction, current_junction = current_junction, new_junction # output print(f'Track: {track}') print(f'Last track: {track[-2]}{track[-1]}') 

Well, this is wrong.

My code outputs when inputs are [‘GHIJKL’, ‘AE’, 100]:

Track: ['A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O']

Last track: VO

But in the correct answer, the train goes to S after the first K, even though K is a flip flop point. Why is that? Am I understanding the questions wrong?

Any help is greatly appreciated. Thank you

submitted by /u/Evening_Oven_8431
[link] [comments]

​r/learnpython The question is British Informatics Olympiad 2012 Question 2a : https://www.olympiad.org.uk/papers/2012/bio/round_one.html This is my code: # constructing network network = { ‘A’ : [‘D’, ‘E’, ‘F’, True], ‘B’ : [‘C’, ‘G’, ‘H’, True], ‘C’ : [‘B’, ‘I’, ‘J’, True], ‘D’ : [‘A’, ‘K’, ‘L’, True], ‘E’ : [‘A’, ‘M’, ‘N’, True], ‘F’ : [‘A’, ‘N’, ‘O’, True], ‘G’ : [‘B’, ‘O’, ‘P’, True], ‘H’ : [‘B’, ‘P’, ‘Q’, True], ‘I’ : [‘C’, ‘Q’, ‘R’, True], ‘J’ : [‘C’, ‘R’, ‘S’, True], ‘K’ : [‘D’, ‘S’, ‘T’, True], ‘L’ : [‘D’, ‘T’, ‘M’, True], ‘M’ : [‘U’, ‘L’, ‘E’, True], ‘N’ : [‘U’, ‘E’, ‘F’, True], ‘O’ : [‘V’, ‘F’, ‘G’, True], ‘P’ : [‘V’, ‘G’, ‘H’, True], ‘Q’ : [‘W’, ‘H’, ‘I’, True], ‘R’ : [‘W’, ‘I’, ‘J’, True], ‘S’ : [‘X’, ‘J’, ‘K’, True], ‘T’ : [‘X’, ‘K’, ‘L’, True], ‘U’ : [‘V’, ‘M’, ‘N’, True], ‘V’ : [‘U’, ‘O’, ‘P’, True], ‘W’ : [‘X’, ‘Q’, ‘R’, True], ‘X’ : [‘W’, ‘S’, ‘T’, True] } # taking inputs flip_flops = list(input(‘Enter the names of flip-flop junctions: ‘)) start = list(input(‘Enter the start track: ‘)) points_count = int(input(‘Enter the number of points to pass through: ‘)) # modifying based on input for junction in network: if junction in flip_flops: network[junction][3] = False # simulation last_junction = start[0] current_junction = start[1] new_junction = ‘NULL’ side = False if current_junction == network[start[1]][1] else True side = side if network[current_junction][3] else not side track = [last_junction, current_junction] for _ in range(points_count): if last_junction == network[current_junction][1] or last_junction == network[current_junction][2]: new_junction = network[current_junction][0] else: side = side if network[current_junction][3] else not side if side: new_junction = network[current_junction][1] else: new_junction = network[current_junction][2] track.append(new_junction) last_junction, current_junction = current_junction, new_junction # output print(f’Track: {track}’) print(f’Last track: {track[-2]}{track[-1]}’) Well, this is wrong. My code outputs when inputs are [‘GHIJKL’, ‘AE’, 100]: Track: [‘A’, ‘E’, ‘M’, ‘U’, ‘V’, ‘O’, ‘F’, ‘A’, ‘D’, ‘K’, ‘T’, ‘X’, ‘W’, ‘R’, ‘J’, ‘C’, ‘B’, ‘H’, ‘P’, ‘V’, ‘U’, ‘M’, ‘L’, ‘D’, ‘A’, ‘E’, ‘M’, ‘U’, ‘V’, ‘O’, ‘F’, ‘A’, ‘D’, ‘K’, ‘T’, ‘X’, ‘W’, ‘R’, ‘J’, ‘C’, ‘B’, ‘H’, ‘P’, ‘V’, ‘U’, ‘M’, ‘L’, ‘D’, ‘A’, ‘E’, ‘M’, ‘U’, ‘V’, ‘O’, ‘F’, ‘A’, ‘D’, ‘K’, ‘T’, ‘X’, ‘W’, ‘R’, ‘J’, ‘C’, ‘B’, ‘H’, ‘P’, ‘V’, ‘U’, ‘M’, ‘L’, ‘D’, ‘A’, ‘E’, ‘M’, ‘U’, ‘V’, ‘O’, ‘F’, ‘A’, ‘D’, ‘K’, ‘T’, ‘X’, ‘W’, ‘R’, ‘J’, ‘C’, ‘B’, ‘H’, ‘P’, ‘V’, ‘U’, ‘M’, ‘L’, ‘D’, ‘A’, ‘E’, ‘M’, ‘U’, ‘V’, ‘O’] Last track: VO But in the correct answer, the train goes to S after the first K, even though K is a flip flop point. Why is that? Am I understanding the questions wrong? Any help is greatly appreciated. Thank you submitted by /u/Evening_Oven_8431 [link] [comments] 

The question is British Informatics Olympiad 2012 Question 2a : https://www.olympiad.org.uk/papers/2012/bio/round_one.html

This is my code:

# constructing network network = { 'A' : ['D', 'E', 'F', True], 'B' : ['C', 'G', 'H', True], 'C' : ['B', 'I', 'J', True], 'D' : ['A', 'K', 'L', True], 'E' : ['A', 'M', 'N', True], 'F' : ['A', 'N', 'O', True], 'G' : ['B', 'O', 'P', True], 'H' : ['B', 'P', 'Q', True], 'I' : ['C', 'Q', 'R', True], 'J' : ['C', 'R', 'S', True], 'K' : ['D', 'S', 'T', True], 'L' : ['D', 'T', 'M', True], 'M' : ['U', 'L', 'E', True], 'N' : ['U', 'E', 'F', True], 'O' : ['V', 'F', 'G', True], 'P' : ['V', 'G', 'H', True], 'Q' : ['W', 'H', 'I', True], 'R' : ['W', 'I', 'J', True], 'S' : ['X', 'J', 'K', True], 'T' : ['X', 'K', 'L', True], 'U' : ['V', 'M', 'N', True], 'V' : ['U', 'O', 'P', True], 'W' : ['X', 'Q', 'R', True], 'X' : ['W', 'S', 'T', True] } # taking inputs flip_flops = list(input('Enter the names of flip-flop junctions: ')) start = list(input('Enter the start track: ')) points_count = int(input('Enter the number of points to pass through: ')) # modifying based on input for junction in network: if junction in flip_flops: network[junction][3] = False # simulation last_junction = start[0] current_junction = start[1] new_junction = 'NULL' side = False if current_junction == network[start[1]][1] else True side = side if network[current_junction][3] else not side track = [last_junction, current_junction] for _ in range(points_count): if last_junction == network[current_junction][1] or last_junction == network[current_junction][2]: new_junction = network[current_junction][0] else: side = side if network[current_junction][3] else not side if side: new_junction = network[current_junction][1] else: new_junction = network[current_junction][2] track.append(new_junction) last_junction, current_junction = current_junction, new_junction # output print(f'Track: {track}') print(f'Last track: {track[-2]}{track[-1]}') 

Well, this is wrong.

My code outputs when inputs are [‘GHIJKL’, ‘AE’, 100]:

Track: ['A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O', 'F', 'A', 'D', 'K', 'T', 'X', 'W', 'R', 'J', 'C', 'B', 'H', 'P', 'V', 'U', 'M', 'L', 'D', 'A', 'E', 'M', 'U', 'V', 'O']

Last track: VO

But in the correct answer, the train goes to S after the first K, even though K is a flip flop point. Why is that? Am I understanding the questions wrong?

Any help is greatly appreciated. Thank you

submitted by /u/Evening_Oven_8431
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *