How to split number based on frequency

we receive input as number and need to split input based on given frequency number.
For ex: Input num=10
Frq:3

Output: 3,3,1
Note: (total sum equals input number)

Ex2: 12
Frq:5

Output: 5,5,2(total sum equals input number)

Could you please help this using linq query

Hello @Manaswini_UI try this

String.Join(“,”, Enumerable.Repeat(Freq, Num \ Freq).Concat(If(Num Mod Freq > 0, {Num Mod Freq}, {})))

and If Num = 10 and Freq = 3

Then this expression will return 3,3,3,1

Cheers

1 Like

Hi,

FYI, another solution

if you need int32 array, the following works.

(New String(" "c,number)).Chunk(freq).Select(Function(x) x.length).ToArray()

Regards,

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.