I no longer have a diamond; I only have it in chat due to caching. I've got the points for the dupehammer, but not the answer count, so I'll need to pump out a few. :P
@Code-Apprentice They aren't exactly on a sphere, but it's a projection that maps the infinite plane to a disc via a sphere. It's a form of Stereographic projection.
@Code-Apprentice like pycharm, pip, maven and etc. I understand that. The problem is I always was too direct and too sincere. But the line between sincerity and roughness is tenuous
I hope this OP understands my code. The logic is very close to his logic, but I guess recursive generators can be a bit mind-blowing if you aren't familiar with them stackoverflow.com/questions/47107663/…
@PM2Ring Nice answer. I don't think your usage of itertools.product is correct there though. Imagine if the input is "RW", then the OP's code would output ['a'], ['bd'], ['aceaeg']. Using itertools.product on that will result in incorrect paths like "abg"
product combines everything with everything, but you'd have to split 'aceaeg' into 'ace' for 'b' and 'aeg' for 'd'
I messed a mini function up a little (missed a fun edge case).. .now I'm not sure on the best practice for getting over this case.
def max_even_seq(n, k):
max = 0
counter = 0
for digit in str(n):
if int(digit)%k==0:
counter = counter + 1
else:
max = counter if counter > max else max
counter = 0
return max
max_even_seq(4613**999,1)
maximum digits in a row that divide in k
mess up.... if they all divide, max does not get updated to the value of counter
I currently have two sol options in my head -- not in love with either
1) update max again when finished (same code written twice)
2) update max on every counter increment -- wasted computations
@ofer.sheffer could you use enumerate() to figure out when you're on the last iteration and modify your if else formulation to add in that test as well?
@RobertGrant From your suggestion, I have the idea of changing the initial 'if' clause to 'if digit%k !=0 or inter == len(str(num)): update max, else counter++
its better than repeated updates on the max because it only reads 'i' and doesn't write to it repeatedly... so, an improvement and I also get rid of the duplicate code.
I found myself needing of duplicating the counter++ code though, to make sure that if its the last iteration, the counter is updated before max is assigned.... so I did not get the job any easier.
@ofer.sheffer: you could look into itertools.groupby, which helps when working with problems involving contiguity (things in a row). Something like max(len(list(g)) for _, g in groupby(str(n), key=lambda digit: int(digit) % k == 0)) would probably work.
Not sure what this "before" or "after" you're talking about means, but the docs do explicitly mention that you can add __weakref__ by adding it to the __slots__ (so in the same manner as you'd add __dict__)