If the first two cipher numbers are the same it may start out with the wrong one out of the two factors (since you have to look further to disambiguate). Then decipher may end up with garbage, in particular the integer division may cause it to have more than 26 distinct entries, causing the lookup to throw an error.
On Sun, Apr 7, 2019 at 06:24 Abhishek Kalahal <[email protected]> wrote: > Can anyone help me find out why am I getting RE status when I submit the > following code?: > > def prime_factors(n): > i = 2 > factors = [] > while i * i <= n: > if n % i: > i += 1 > else: > n //= i > factors.append(i) > if n > 1: > factors.append(n) > return factors > alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > t = int(input()) > for i in range(1, t+1): > n, l = map(int, input().split()) > cipher = list(map(int, input().split())) > decipher = prime_factors(cipher[0]) > if cipher[1] % decipher[0] == 0: > decipher = decipher[::-1] > answer = [] > j = 1 > for word in cipher[1:]: > decipher.append(word // decipher[j]) > j = j+1 > print(decipher) > keys = sorted(list(set(decipher))) > for char in decipher: > answer.append(alpha[keys.index(char)]) > print("Case #{}: {}".format(i, ''.join(answer))) > > It works fine when I run it on my PC for the sample inputs. > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-code/aa337bf2-32a1-43f6-8d76-58718ee91e6b%40googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CAJRRr7SV7Sfy000xi%3DV4qv6ej0wbHa6PTZ9YdfK9y76sQLAYUw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
