Something I can figure out how to solve the following problem:

There is a range of 360 files, which is divided into 30 elements into 12 parts.

Next is the file number, i.e. a number in the range from 1 to 360. The range from 1 - 30 corresponds to the 1st part, the range from 31 - 60 corresponds to the 2nd part, the range from 61 - 90 corresponds to the 3rd part, ..., the range from 331 - 360 corresponds to the 12-part.

How can knowing the file index (1 ... 360) arithmetically determine the index of the part to which it refers (1..12)?

  • one
    You just need to divide the resulting index by 12, of course, the result will be the group number - Grundy
  • @Grundy is not entirely clear. For example, we have a file index 59. A file with such an index belongs to the second part because it belongs to the range [31; 60]. If we divide 59 by 12 completely, we get 4, and I needed to get 2, because this is the second part. - abg
  • one
    divide by 30 and round up to 2x. In a big way. - user2455111
  • one
    I wrote, round up, if more than 1 index, then take it for 2 - user2455111
  • 2
    Try searching in the language you use the function RoundUp (). If there is none, then 1 + Fix (). - Akina

1 answer 1

Actually, everything is simple. floor can be replaced by a simple integer division.

enter image description here

  • one
    I understand your option is equivalent to this ⌈N / 30⌉? - abg
  • @abg In principle, yes, but mine is implemented by one team of integer division. - Harry