Daily Challenge #100

Welcome to 100th Daily Challenge :tada::tada:

Thanks @peter for starting this and thanks to all those who participated either as making challenges or solving them :heart:. Also a big shout-out again to @peter for the above artwork

The Challenge

Sum of Digits :

The challenge is to Kode procedure for finding the sum of digits of a given number until the sum we get is a single digit.

Input

A n digit non-negative number

Output

A single digit integer

Sample Set

1. 24 => 2 + 4 => 6
2. 356 => 3 + 5 + 6 => 14 => 1 + 4 => 5
3. 123 => 1 + 2 + 3 => 6
4. 42654 => 21 => 2 + 1 => 3
5. 34.08 => 15 => 1 + 5 => 6

Winner

There will be two winners of this challenge as:

Explanation:

I will add some more info about the concept:wink:

All the Best :partying_face:

5 Likes

Here’s mine

Solution (24 blocks)
2 Likes

that was quick:+1:

1 Like

Just now one little bug in my blocks crashes my whole phone :sweat_smile:
Now it’s alright.

1 Like

Solution (11 blocks)

blocks

Explanation

Solving the Digital Root Algorithm using JavaScript - DEV

5 Likes

smart one:wink: but what about in case of decimal :grin:?

1 Like

It doesn’t work

Btw, are you able to see the solution?

1 Like

yes,i saw, input can be any non negative number


Caught! :joy:

3 Likes

technically still your solution do not reach challenge requirement:wink:. just a small change :zipper_mouth_face:

Fixed

image

Solution (14 blocks)

blocks(1)

5 Likes

Be carefull from now! every thing you think is already thought by me , now there are no secrets of Kodular:wink::rofl:

4 Likes

Here is my Try
Disclaimer: I knew the fact that the digital root of multiples of 9 is always 9 but never thought of using it for other numbers until I saw @pavi2410 post. So basically credits go to her.

12 Blocks

10 Blocks

(Improper Method): uses RHS limit of 9 which is not possible to write perfectly, so it works for the limited number of digits that can be anything 50, 100, 10000 anything but not for infinite digits. However, if we stretch 9.0000…goeson…0001 to the max limit of computation then it works the same as the above code.

4 Likes

Her :crazy_face::sweat_smile: :sweat_smile:

2 Likes

different result coming when calling procedure and if manually running the code inside procedure?
input: 99999999999999999999999999999999907979

image

1 Like

do u have any idea of this behaviour ? :thinking:

Absolutely no idea.
Interesting
@Deepanshu_Arya can you check that data passed to the procedure is same as that of data in callProcedure method. Maybe due to large number of digits it is passing only first few digits.

1 Like

For those who are wondering what is the right answer for digital sum of 99999999999999999999999999999999907979

It is 5

Maybe there is some problem in calling procedure method

1 Like

Issue solved:
image
need to pass number as a string. Dont know why but if the it is passed as number it change the number to some another number

1 Like

i am really curious about this behaviour of procedure. It will be interesting to know why this happens.

You were wrong boi