Reduce a number down to a static set of numbers

烂漫一生 提交于 2021-01-05 06:52:02

问题


Okay, so I have a Google Sheet that I need to reduce a number down to a specific set of 4 numbers. Then count how many times those numbers occur.

For example:

The numbers it breaks down to: 1, 2, 3, 4

Disregard their individual values other than for the purpose of being broken down.

Now take the number 17.

Count+Add 1, 2, 3, 4, 1, 2, 3 = 7 r1

Take number 12

Count+Add 1, 2, 3, 4, 1 =  r1

The remainder is rounded DOWN

So, basically, it breaks down Cell A1 into a count of how many sequences it takes to reach the total of the number in A1, rounddown.


回答1:


try:

=ARRAYFORMULA(COUNTA(IFERROR(QUERY(MMULT(TRANSPOSE((
 ROW(INDIRECT("A1:A"&A2*COUNTA(SPLIT(B2, ","))))<=TRANSPOSE(
 ROW(INDIRECT("A1:A"&A2*COUNTA(SPLIT(B2, ","))))))*TRANSPOSE(
 SPLIT(QUERY(B2&IF(ROW(INDIRECT("A1:A"&A2))<>"", ",")
 ,,9^9), ","))), SIGN(TRANSPOSE(
 SPLIT(QUERY(B2&IF(ROW(INDIRECT("A1:A"&A2))<>"", ",")
 ,,9^9), ",")))), "where Col1 <="&A2, 0))))




回答2:


Seems odd but...

Your sequence adds to 10, so your number tens place and above times 4 is your first element. Then if the ones digit is between 6 and 9 you add 3, 3 to 5 add 2, or 1 to 2 add 1. There is probably a more elegant formula that this...

=(INT(A1/10)*4)+IF(MOD(A1,10)>0,1,0)+IF(MOD(A1,10)>3,1,0)+IF(MOD(A1,10)>5,1,0)



来源:https://stackoverflow.com/questions/60234678/reduce-a-number-down-to-a-static-set-of-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!