-1
\$\begingroup\$

This question already has an answer here:

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.

\$\endgroup\$

marked as duplicate by Mr. Xcoder, Arnauld, Quintec, Nit, a spaghetto Sep 22 '18 at 13:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Arnauld Sep 22 '18 at 12:49
  • 1
    \$\begingroup\$ I should also note that there is no explicit win condition present here. \$\endgroup\$ – Don Thousand Sep 22 '18 at 17:41
  • \$\begingroup\$ Note that duplicate should not be interpreted as exactly the same but rather as trivially portable. \$\endgroup\$ – Jonathan Frech Sep 24 '18 at 2:47
  • \$\begingroup\$ Golf this or have the fastest running time. I think is not a valid winning criterion. \$\endgroup\$ – Jonathan Frech Sep 24 '18 at 2:49
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – dylnan Sep 24 '18 at 4:14
0
\$\begingroup\$

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
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.