# [Haskell], <s>70</s> 69 bytes <!-- language-all: lang-hs --> filter(0#)[0..] a#x=a!divMod x 10 a!(d,m)|d<1=a==m|c<-a-m+1=m<=a&&c#d [Try it online!][TIO-kx40yeq3] [Haskell]: https://www.haskell.org/ [TIO-kx40yeq3]: https://tio.run/##BcFBCoMwEADAu69YCYjSRpJ79gm@oC2yZLUNydqgUjz49saZD21xSqlEfJY5pH1aW6O6h@n7V0XqQKo5/IYvwwHWVFS3fJfuZGeREOX0TpOWm0VxSE3jFRehsACCUB5GyGtYdojl7@dE761on/MF "Haskell – Try It Online" - Thanks to @Unrelated String for saving 1 by using filter instead of list comprehension. - _k_ is an infinite sequence We start from the end checking if the last digit(m) doesn't consume more groups than available `a` _a-m>=0_ Then we remove `m` groups and add 1 _a=a-m+1_ and move backwards. At the end we must have exactly one group _a-m+1==1_ <pre> 3010200 m a a=a-m+1 0 0 1 0 1 2 2 2 1 0 1 2 1 2 2 0 2 3 3 3 1 </pre>