CarViz's blog

By CarViz, history, 45 minutes ago, In English

hello all

will delete next period

can you guys figure out why im runtime erroring

391906583

thanks,

edit: i didnt generate enough primes whoops.

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
33 minutes ago, hide # |
← Rev. 2  
Vote: I like it +1 Vote: I do not like it

first time seeing normal blog by CarViz

»
29 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by CarViz (previous revision, new revision, compare).

»
24 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think the runtime error is most likely caused by this line:

while (i+1)*primel[lp]-1 < len(l):

You access primel[lp] before checking whether lp is still within the bounds of primel. If lp becomes equal to len(primel), this causes an IndexError: list index out of range.

Also, this line can cause an IndexError if any value in l is greater than len(l):

sum([dp[i-1] for i in l])

For example, if len(l) = 3 but l contains 100, then dp[99] is out of bounds.

You should check the constraints and make sure the prime list is large enough, and also verify that every value in l is a valid index for dp.

»
12 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

will delete next period

I guess he learned how to pocket solve