-1
\$\begingroup\$

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

1 Answer 1

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.