Every positive integer can be written as the sum of 3 palindrome integers. Wha'ts the largest possible palindrome integer for each integer n?

-1

Let n be a positive integer then n = a + b + c for some a, b, and c that are palindrome integers. What is the largest possible integer a for k = 1 to 1_000_000?

Golf this or have the fastest running time.

NOTE: it's NOT the same as this question as I am asking for the largest palindrome component. The question just asks for ANY combination.

xiaodai

Posted 2018-09-22T12:42:43.203

Reputation: 119

Question was closed 2018-09-22T13:03:28.793

2

Welcome to PPCG! This is currently off-topic. We're hosting programming challenges that require an objective winning criterion. Also, this is potentially a duplicate of this question.

– Arnauld – 2018-09-22T12:49:24.307

1I should also note that there is no explicit win condition present here. – Don Thousand – 2018-09-22T17:41:00.617

Note that duplicate should not be interpreted as exactly the same but rather as trivially portable. – Jonathan Frech – 2018-09-24T02:47:44.320

Golf this or have the fastest running time. I think is not a valid winning criterion. – Jonathan Frech – 2018-09-24T02:49:32.390

@JonathanFrech it's not trivially portable. Finding the maximum component is different to finding ANY combination. – xiaodai – 2018-09-24T03:49:00.417

@JonathanFrech if Golf or fastest is not then what is? I can easily make similiar comments, e.g. your example is not helpful. – xiaodai – 2018-09-24T03:50:11.900

Hi @xiaodai and welcome to PPCG. In terms of winning criteria, the only issue in this case is that challenges typically either have code golf or fastest code as the scoring metric, but not both. You could conceivably create a challenge that uses both metrics but the scoring system would need to be very explicit in that case. That being said, even if a single winning criterion was chosen this challenge is pretty similar to the other challenge referenced which typically counts as a duplicate on this site – dylnan – 2018-09-24T04:12:44.000

1

Also, there is a sandbox on the meta site where people can post their potential questions to see what others think of them. A lot of people use it, even really experienced users who have been on PPCG for a long time

– dylnan – 2018-09-24T04:14:15.020

@xiaodai You can of course state that my example -- I do not know which example you are referring to -- is not helpful. However, this differs from a winning criterion not being valid as the latter -- I think -- is more objectively decidable. – Jonathan Frech – 2018-09-24T13:16:01.730

Answers

0

My Julia solution

using Base.Iterators

is_palindrome(n) = begin
    dn = digits(n)
    all(dn .== reverse(dn))
end

lim  = Int64(1e6)
res = filter(is_palindrome,lim:-1:0)

using DataFrames
lp = DataFrame(k = 1:1_000_000, largest_palindrome = Array{Int64,1}(lim))

# found stores the integers backwardds
ok(lim, res, lp) = begin
    found = BitArray(lim)
    found .= false
    tot = Int128(0)

    cap = lim
    r = res[1]

    for r in res[1:end-1]
        bs = res[res .<= (cap - r)]
        cs = res[res .<= ceil((cap - r)/2)]

        res1 = vec([r + b + c for (b,  c) in product(bs,cs)])

        res1 = res1[res1 .<= cap]

        for rr in res1
            if !found[rr]
                lp[rr,:largest_palindrome] = r
                tot = tot + r
                found[rr] = true
            end
        end

        for i in lim:-1:1
            if !found[i]
                cap = i
                break
            end
        end
    end

    (tot, found, lp)
end

xiaodai

Posted 2018-09-22T12:42:43.203

Reputation: 119