python - What function has these integer results? -


for example, have reference number a = 15 , b= 3.

  • if x=2, f(a,b,x) = 1 because if 1 divide 15 3 parts, number 2 in first part.
  • if x=7, f(a,b,x) = 2 because if 1 divide 15 3 parts, number 7 in second part.
  • if x=15, f(a,b,x) = 3 because if 1 divide 15 3 parts, number 15 in third part.
  • if x<0 or >15 results irrelevant me.

is there built-in function this?

i can't think of single built-in function that. not difficult write one:

def f(a, b, x):   return (x - 1) * b // + 1  in range(1, 16):   print i, f(15, 3, i) 

this prints out

1 1 2 1 3 1 4 1 5 1 6 2 7 2 8 2 9 2 10 2 11 3 12 3 13 3 14 3 15 3 

(it not entirely clear question how, , if, x=0 needs handled; answer considers outside valid range.)


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -