05-05-2023, 04:50 PM

Looks like I made good score at nerd-sniping

@Programmer_ceds: can't make you code to work. I have trouble relating your definition of the offset to mine (if they are the same, then there is a problem since we find different answers). For instance: 5px tiles, 2px lines, offset 6 in a 20px window should give 14 ([4,5,5]):

@ottiatuota: Nice one, not disappointed. Very interesting point of view. Can' t make you code to work exactly like mine, possibly due to a different meaning:

This isn't an idle problem, I want to compute the width and height of this image after I have removed the red checkers lines:

From your PDF; the equivalent code is:

But the result are different from mine (seem shifted by 1):

Otherwise, my code:

@Programmer_ceds: can't make you code to work. I have trouble relating your definition of the offset to mine (if they are the same, then there is a problem since we find different answers). For instance: 5px tiles, 2px lines, offset 6 in a 20px window should give 14 ([4,5,5]):

Code:

` 123456 offset`

TTTTTGGTTTTTGGTTTTTGGTTTTTGG

[------------------]

12345678901234567890

@ottiatuota: Nice one, not disappointed. Very interesting point of view. Can' t make you code to work exactly like mine, possibly due to a different meaning:

This isn't an idle problem, I want to compute the width and height of this image after I have removed the red checkers lines:

From your PDF; the equivalent code is:

Code:

`def otsize(span,tile,grid,offset):`

a=tile

s=grid

p=grid+tile

w=span

def k(x):

return x-math.floor(float(x)/p)*p

def h(x):

return max(0,a-k(x))

def g(x):

return a*(1+math.floor(float(x)/p))

def f(x):

return g(x)-h(x)

return f(offset+span)-f(offset)

But the result are different from mine (seem shifted by 1):

Code:

`offset 0, total 15 ( [5, 5, 5]), ofn size 15, ot size 15`

offset 1, total 15 ( [5, 5, 5]), ofn size 15, ot size 14

offset 2, total 14 ( [5, 5, 4]), ofn size 14, ot size 14

offset 3, total 14 ([1, 5, 5, 3]), ofn size 14, ot size 14

offset 4, total 14 ([2, 5, 5, 2]), ofn size 14, ot size 14

offset 5, total 14 ([3, 5, 5, 1]), ofn size 14, ot size 14

offset 6, total 14 ( [4, 5, 5]), ofn size 14, ot size 15

Otherwise, my code:

Code:

`def ofnsize(span,tile,grid,offset):`

period=tile+grid

whole,rest=divmod(span-offset,period)

left=max(0,offset-grid)

right=min(tile,span-offset-whole*period)

return whole*tile+left+right