0

I first thought this would be easy but I can't think of a solution. Say you have a list of numbers with values between 0 and 1. I need a way to calculate what is the index of the interval in which X is. Here is a demonstration of what i'm trying to ask: the problem

So for example, A=[1,0.5,0.9,0.1,0.8,1,1,0,0.6,1]

If X = 2.8, i = 5 and A[i] = 0.8

If X = 2.3, i = 3 and A[i] = 0.9

For any list of values of any length, is a way to calculate this in a form I could actually use in an function ?

  • Your question is unclear, and your picture is hard to read and not appropriate for this site. If you [edit] The question to show us a short explicit example of your input and the output you expect we may be able to help. My suspicion is that there is no formula or elementary function for what you want but that it's easy to calculate in a loop in a computer program. Use mathjax: – Ethan Bolker Nov 07 '22 at 15:44
  • So you seem to be summing the items on the list until the total exceeds $X$, then noting where you stopped. There's no way to do that for an arbitrary list $A$. It is possible with the floor function if the elements of $A$ are all the same. – Ethan Bolker Nov 07 '22 at 15:56
  • The maximum value of X dépends of the sum of the elements, not the other way around – Samuel Fyckes Nov 07 '22 at 17:36

0 Answers0