Realistic math solver

There are a few more like that in the Euler problems, including finding sequences of primes etc. I worked my way through a lot of them, until they started to need obscure math tricks to solve.

The way it works is you register, then you solve each problem and type the answer in. If you’re correct, you get a tick (and can see the forum discussion where other people have solved the same problem with 200 different languages!).

@Ignatz I don’t have time to start this yet, but is this a trick question. Why the fists 10 digits and not all of them. Most people would probable add up all 50 digits of the 100 numbers and then write down the first 10. But I’m wondering if there’s some formula that depends on how many numbers there are to add up so that to get the first 10 digits, you only have to add up maybe the first 15 digits of each number ignoring the rest. But using a program to do it, it’s probably just as easy adding up all 50 digits.

Why the first 10 digits? Because you have to type the answer into a small textbox, that’s why. You still have to do all the arithmetic, so it’s sufficient to ask for just a few leading digits.

@Ignatz Is this the sum of all the numbers with the 1st 10 being 5537376230. Hope I didn’t mess up the numbers reading them in.
5537376230390876637302048746832985971773659831892672

Yep,
5537376230390876637302048746832985971773659831892672

@Ignatz Here’s the code I used. I copied all the numbers from the link you gave and pasted them into a tab called nbrs. I put comments --[[ --]] around them and just read them in as a string. The next thing I’m going to try later is to see how many digits I have to read to get the 1st 10 digits correct. Will it be more or less than the left most 15 digits. I think I enjoy writing the code more than getting the correct answer.


function setup()
    ans={}
    for z=1,50 do
        ans[z]=0
    end 
    l=listProjectTabs()
    str=readProjectTab("nbrs")
    for nbr in string.gmatch(str,"%d+") do 
        add(nbr)
    end
    print(table.concat(ans))
end

function add(nbr)
    c=0
    cc=#nbr
    for z=#ans,1,-1 do
        ans[z]=ans[z]+c
        if cc>0 then
            ans[z]=ans[z]+string.sub(nbr,cc,cc)
        end
        c=math.floor(ans[z]/10)
        ans[z]=ans[z]%10
        cc=cc-1
    end
    if c>0 then
        table.insert(ans,1,c)
    end
end
        

@Ignats I got the correct left most 10 digits of the answer by adding up the left most 11 digits of the 50 digit starting numbers. So the trick was you didn’t have to add up all 50 digits, just the left most 11. The answer was even close just adding up the left most 10 digits.


5537376230     left 10 digits of the answer
553737623039   left 12 digits of the answer
553737623034   left 12 digits adding up the left most 11 digits (correct to 11 digits)
553737622992   left 12 digits adding up the left most 10 digits

Add up 100 numbers all beginning with 9 and the 9s will give a term of 900. So each column can affect only the two columns to its left. Thus adding up the left 12 digits will definitely give the right answer for the left-most 10 digits. But not every number has a 9 in 12th column, so actually the effect of the 12th column will be less than that which is why you get the right answer with only 11 columns. 10 columns will only differ by a little amount because you’re losing only the information at one end.

Incidentally, for this sort of thing you shouldn’t think in terms of numerical difference. Something like the Levenshtein metric would be more appropriate.

That’s why I gave up doing the Euler problems in the end, because to solve the harder ones, you needed things like the Levenshtein metric (whatever that is). #-o

But a lot of the early ones are fun, you should try them, @dave1707

@Ignatz I was looking at some of them and the one that looks interesting is the largest product in a grid, number 11. Do you have answers for these or is there a way to get the answers or do I have to register. The thing I don’t like is that Codea has limited precision math, so I might have to try some of the problems using techBasic.

I got up to problem 85 or so, using just Excel VBA, so I have answers for all the early ones.

Every language has limited precision math, which is why you need big number functions, also good prime number identification functions, because they use primes a lot.

I would register, it takes about 30 seconds, and then it gives you a textbox for each question, where you put your answer in and wait for the verdict!

If you get stuck, I can give you answers, but I’m sure you won’t give up easily!

@Ignatz actually, I think you’d quite like the Levenshtein metric. It’s for measuring the difference between two strings by looking at the length of their overlap. What I meant was that if you get two answers to this question and one differs from the right answer by one digit and the other by two then you’d say that you’d gotten closer with the first answer, even if that one digit was the initial digit and the other was wrong at the lower end.

I assume there’s more to it than that, or else Levenshtein put his name on something very obvious! :smiley:
(Just being facetious)