Sum of digits problem

No you didn't you left most of the code undefined!

Lets start again, apologies if not clear, here this is the problem - you can code it and test it in the site and then submit it, when you do that the system will subject your code to a battery of test cases.

I've been writing computer code longer than you've been alive. I don't need to prove anything.
 
Imagine a file or string in some programming language that consists of a non-empty sequence of digits (assume ASCII) it has a finite length but unknown length, do not assume some specific or "max" length.

You are to write the code (or pseudo code if you want) that can consume the sequence from the start digit, by adding a digit and the following digit in such a way that any result of > 1 digit long is again added until you get a single digit result, and then continue adding that result to the next digit

Examples

164 ⇒ 1 + 6 + 4 7 + 4 11 2

9576 9 + 5 + 7 + 6 14 + 7 + 6 5 + 7 + 6 12 + 6 3 + 6 9

So, devise an algorithm, a set of rules that can achieve this.

Read your post.

You said "code or pseudo code".

You didn't say anything about web sites, lambda calculus or anything else.

I work with Python and TensorFlow on a daily basis. That's using a digital computer to program an analog computer. As you know interpreters are horribly inefficient (that's why WASM exists), but they help with interactive programming.

TensorFlow is like a GPU in software, except it's more flexible. It's used to explore artificial neural networks. Except the matrices are fixed So you can't add neurons very easily.

So I built a list based simulator, that maps lists to matrices. This way, I can study network development. It's slow but it works. I can run 30 minutes of hippocampus overnight, and visualize all the new neurons and synapses.

I'm going to post it on Git for open source use. Some people will find it useful.
 
I've been writing computer code longer than you've been alive. I don't need to prove anything.
Yes you do, you need to at least prove that you know how long I've been alive, that's a necessary condition, if you do not then that statement is unprovable so why assert with such confidence?

I already apologized, so the actual challenge now (if you're willing to man up) is to solve that HackerRank problem, that's where my own solution arose years ago.

I want to see how good you are, I want to see what kind of actual solution you come up with because I suspect much of your posting here is bluster.

Look at that test case (your code will be subjected to seven challenging cases)

1724423552820.png


The task is to compute the "super digit" for that long numeric string (740...153) repeated 100,000 times, that's a real problem, not for a novice, for a person who's been writing code for "longer than" I've been alive, this is run of the mill, not trivial, might even take a few days all told but certainly within your much publicized skill set.

We'll then compare/contrast solutions, who knows you might actually impress me, teach me something new.

So pick one of the available languages and man up, have you not even used a functional language before? is that the problem?

Here's what happens when your code passes all tests:

1724423877855.png
 
Last edited:
Read your post.

You said "code or pseudo code".

You didn't say anything about web sites, lambda calculus or anything else.
Yes, I apologized, it was - with hindsight - much better to post the challenge itself, that levels the playing field and avoids subjectivity.
I work with Python and TensorFlow on a daily basis. That's using a digital computer to program an analog computer. As you know interpreters are horribly inefficient (that's why WASM exists), but they help with interactive programming.

TensorFlow is like a GPU in software, except it's more flexible. It's used to explore artificial neural networks. Except the matrices are fixed So you can't add neurons very easily.

So I built a list based simulator, that maps lists to matrices. This way, I can study network development. It's slow but it works. I can run 30 minutes of hippocampus overnight, and visualize all the new neurons and synapses.

I'm going to post it on Git for open source use. Some people will find it useful.
 
Just a complete novice here ... but my first step would be to search the public use forums for the code already written ... this sounds awful familiar like there might be a command in PHP for this already ... not that I know anything about PHP commands mine you ... just a novice spitting out my opinion ...
 
Just a complete novice here ... but my first step would be to search the public use forums for the code already written ... this sounds awful familiar like there might be a command in PHP for this already ... not that I know anything about PHP commands mine you ... just a novice spitting out my opinion ...
That's a very good idea in the case of a typical work problem. HackerRank though is about seeing if one can solve it themselves. It's a good way to push the limits of our thinking, they ways we look at problems, the things we assume and so on.

If this were a problem that just came up in some kind of project then yes, searching existing codebases is a sensible step, especially as the code we find might well have been well tested.

I suspect that this particular problem has been defined in an usual way to make it unlikely to exist in any easy to find public way, that's why they define the string to be processed as a function of a number and a repetition factor I think.

There are lots of problems on HackerRank that I've started and gotten stumped, totally stumped.

Those problems are for functional languages, very very different to imperative languages like Python, C, C++ and so on, Functional languages are very very different they:

1. Have no loops
2. No variables
3. Execution order is a minor detail

Some of the strengths of such languages is that one writes less code, more terse, one writes it more quickly and bugs are much less of a problem.
 
Last edited:
Here's a random example of it running locally

1724444096780.png



It's computing the sum of the string of digits of 4521356853475648753 repeated 2,535 times, we get the answer 6.

Is this a little too hard for you, scruffy ?
 

Forum List

Back
Top