On Monday, April 8, 2019 at 12:28:38 PM UTC+5:30, /dev/joe wrote:
> If the message contains a pattern like ABA, then two consecutive values will
> be the same. Your code generates the wrong values in this case (because gcd =
> value and dividing out the gcd gives 1 instead of one of the primes), and
> probably puts more than 26 values into prime_list, which leads to alpha_id
> exceeding the length of alphabets later.
>
>
> On Sun, Apr 7, 2019 at 5:20 PM Nicholas Sadjoli <[email protected]> wrote:
> Hello everyone,
>
>
>
> I have tried to solve the Cryptopangram problem for the recent CodeJam, but I
> have no idea why my code is giving me a Runtime Error. The code already
> passed the sample test case, though do note that I have not tried with any
> other test cases just yet.
>
>
>
> I have analyzed for any possible mis-indent or any possible zero-division or
> mathematically invalid operations in the code. However, it is still producing
> the Runtime Error on the CodeJam interface.
>
>
>
> Any discussions for helping me understand the problem is greatly appreciated,
> and looking forward to your feedback on my code.
>
>
>
> cryptopangrams.py:
>
>
>
> import string
>
>
>
> #find GCD between 2 integers
>
> def gcd_euclid(n1, n2):
>
>
>
> #n2 being 0 means remainder == 0
>
> if n2 == 0:
>
> return n1
>
> return gcd_euclid(n2, n1 % n2)
>
>
>
> test_cases = int(input())
>
>
>
> for T in range(0, test_cases):
>
> N, L = map(int, input().rstrip().split(' '))
>
> cipher_values = list(map(int, input().rstrip().split(' ')))
>
>
>
> #get the prime numbers that make up cipher_values
>
> prime_list = []
>
> for i in range(0, L - 1):
>
>
>
> #find prime value commonly shared by current and next cipher value
>
> common_prime = gcd_euclid(cipher_values[i], cipher_values[i+1])
>
>
>
> #edge case for i at start of cipher_value list
>
> if i == 0:
>
> prime_list.append(int(cipher_values[i] / common_prime))
>
>
>
> prime_list.append(common_prime)
>
>
>
> #edge case for when i at end of cipher_value list
>
> if i == (L - 2):
>
> prime_list.append(int(cipher_values[i + 1] / common_prime))
>
>
>
> #get all alphabets into a string
>
> alphabets = string.ascii_uppercase
>
> alpha_id = 0
>
>
>
> #prepare dictionary for mapping between prime and alphabets
>
> prime_dict = {}
>
>
>
> #get a sorted prime_list first
>
> prime_list_sorted = sorted(prime_list.copy())
>
>
>
> #map the sorted prime numbers to the appropriate alphabets
>
> for p in prime_list_sorted:
>
> if p not in prime_dict:
>
> prime_dict[p] = alphabets[alpha_id]
>
> alpha_id += 1
>
>
>
> #Use mapping to get alphabetical values of all primes in the prime_list
>
>
> plaintext = ''
>
> for t in range(0, L + 1):
>
> plaintext += prime_dict[prime_list[t]]
>
>
>
> print("Case #{}: {}".format(T + 1, plaintext))
>
>
>
> --
>
> 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/0d1a6381-969e-4e16-be4e-7e334446a7dc%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
But in my case this scenario is also working fine..
And some other edge cases is also working fine still giving RE don't know what
to do..still no clrification provided!
def factors(n):
ls=[]
for i in range(2,n//2):
if n%i==0:
ls.append(i)
break
ls.append(n//i)
return ls
t=int(input())
#start_time = time.time()
for ix in range(1,t+1):
n,l=map(int,input().split(" "))
s=str(input())
ls=list(s.split(" "))
j=0
dict={}
al=[]
nm=[]
for i in range(65,92):
al.append(chr(i))
fls=[]
for i in ls:
fls.append(factors(int(i)))
l=factors(int(ls[0]))
if int(ls[1])%l[0]==0:
pv=l[0]
ov=l[1]
else:
pv=l[1]
ov=l[0]
lll=[]
lll.append(ov)
lll.append(pv)
for i in range(1,len(ls)):
pv=int(ls[i])//pv
lll.append(pv)
llp=sorted(list(set(lll)))
llt=[]
for i in lll:
llt.append(al[llp.index(i)])
strg="".join(llt)
print("Case #{}: {}".format(ix,strg))
#print("--- %s seconds ---" % (time.time() - start_time))
--
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/7c7b7712-61ef-46ae-bc33-3192d31b9afa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.