| Bytes | Lang | Time | Link |
|---|---|---|---|
| 116 | Julia | 251009T172306Z | M-- |
| 095 | Ruby | 251014T214247Z | Value In |
| 024 | 05AB1E | 251008T135226Z | Kevin Cr |
| 042 | Charcoal | 251008T090210Z | Neil |
| 019 | Vyxal | 251007T231255Z | lyxal |
| 128 | JavaScript ES6 | 251008T102147Z | Arnauld |
| 123 | R | 251008T193140Z | pajonk |
| 269 | Lua | 251008T004734Z | Someone |
Julia, 157 116 bytes
(b=max(s...)+1;n=foldl((a,x)->a*b+x,s);k=0;while(g=digits(n+k,base=b);g!=reverse(g)||max(g...)<b-1)k=-k+(k<1) end;k)
This is much longer than pajonk's, but I thought it's different enough to warrant posting, albeit as a "footnote".
R, 173 169 154 bytes
\(s){b=max(s)+1
n=sum(s*b^(sum(s|1):1-1))
for(d in 0:n)for(e in d*-1:1){x=n+e;v=c()
while(x){v=c(x%%b,v);x=x%/%b}
if(!any(v-rev(v),max(v)-b+1))return(e)}}
Ruby, 95 bytes
Putting in my own answer now that it's been a week. While not initially intended as such, optimizations have led to it becoming an adaptation of Jordan's solution to the original problem. Taking input as a character array because recombining into a string with (n*'') is one byte shorter than taking as a string and splitting with n.chars to find the max digit.
F=->n,d=0{a=n.max;s=((n*'').to_i(b=a.to_i(36)+1)+d).to_s b;s==s.reverse&&s[a]?d:F[n,d<0?-d:~d]}
05AB1E, 24 bytes
∞<D(.ι.ΔžLRIkZ>©β+®вDÂQ*à®<Q
Input as a list of integers, with \$[10,35]\$ for a-z.
Try it online or verify all test cases (times out for the last test case).
Explanation:
∞ # Push an infinite positive list: [1,2,3,...]
< # Decrease each by 1 to make it non-negative: [0,1,2,...]
D # Duplicate it
( # Negate each value in the copy: [0,-1,-2,...]
.ι # Interleave the two lists: [0,0,1,-1,2,-2,...]
.Δ # Pop and find the first value that's truthy for:
I # Push the input-list
Z # Push the maximum (without popping the list)
> # Increase it by 1
© # Store this max+1 in variable `®` (without popping)
β # Convert the base-® list to a base-10 integer
+ # Add it to the current value
®в # Convert it from a base-10 integer to a base-® list
D # Duplicate it
ÂQ # Check if it's a palindrome:
 # Bifurcate it; short for Duplicate & Reverse copy
Q # Pop both and check if they're the same
* # Multiply it to each value in the list
à # Pop and push the maximum
®<Q # Check that it equals the max, aka ®-1
# (after which the found value is output implicitly)
Charcoal, 43 42 bytes
≔⊕⍘⌈θφηW¬ⅉ«≔⍘⁺⍘θηⅈηζF∧⁼⌈θ⌈ζ⁼⮌ζζ⟦Iⅈ⟧J⁻‹ⅈ¹ⅈⅉ
Try it online! Link is to verbose version of code. Explanation: Uses the canvas x and y coordinates as they are initialised to zero saving three bytes per variable.
≔⊕⍘⌈θφη
Calculate b.
W¬ⅉ«
Repeat while y is zero.
≔⍘⁺⍘θηⅈηζ
Convert the input from base b, add on x, then convert back to base b.
F∧⁼⌈θ⌈ζ⁼⮌ζζ
If the result has the same interpreted base b and is palindromic, then...
⟦Iⅈ⟧
... print x while incrementing y.
J⁻‹ⅈ¹ⅈⅉ
Assign the next element of the sequence 0, 1, -1, 2, -2... to x without changing y.
39 bytes using the new import format of a numeric list:
W¬ⅉ«≔↨⁺↨θ⊕⌈θⅈ⊕⌈θηF∧⁼⌈θ⌈η⁼⮌ηη⟦Iⅈ⟧J⁻‹ⅈ¹ⅈⅉ
Try it online! Link is to verbose version of code. Explanation: Uses Base instead of BaseString and inlines Incremented(Maximum(q)) instead of precomputing b.
Vyxal, 31 27 25 24 22 19 bytes
?:G›~β„+Ȯτ:Ḃ⁼*G›=)N
Uses a list of digits.
-1 byte after seeing DÂQ* in Kevin's 05AB1E answer
-2 bytes after seeing Kevin put the base conversion logic inside the "find integer" structure + after doing some stack manipulation stuff
-3 bytes after the rule change
Explained
This was the 25 byte explanation, but the approach is fundamentally the same.
Gkrḟ›:£β→λ←+¥τ₌‡Ḃ⁼G¥‹=*;N
G ḟ # Find the location of the biggest digit in the input in
kr # "0-9a-zA-Z"
› # and add 1 to get the interpreted base
:£ # Store this interpreted base in the register
β→ # and convert the input from this interpreted base to base 10, storing the result in the ghost variable. Call this X
λ ;N # Find the first whole number n (from [0, 1, -1, 2, -2, ...]) where:
←+ # Adding n to X
¥τ # and converting back to the interpreted base
₌ * # Holds true under:
‡Ḃ⁼ # Is palindrome?
* # AND
G¥‹= # max digit == (interpreted base - 1)
💎
Created with the help of Luminespire.
JavaScript (ES6), 128 bytes
-2 thanks to @l4m2
s=>(P=parseInt,g=k=>[...S=(P(s,b=P(c=[...s].sort().pop(),36)+1)+k).toString(b)].reverse().join``!=S|!S.match(c)?g((k<1)-k):k)(0)
Commented
s => ( // s = input string
P = parseInt, // P = alias for parseInt
g = k => // g is a recursive function taking an integer k:
[... //
S = ( // define S as:
P( //
s, // s parsed in base b
b = P( // where b is:
c = [...s] // the highest digit c in s ...
.sort() //
.pop(), //
36 // ... parsed in base 36
) + 1 // plus 1
) + k // plus k
).toString(b) // converted back to base b
].reverse() // if S reversed ...
.join`` != S | // ... is not equal to itself
!S.match(c) ? // or S doesn't contain c:
g( // do a recursive call with:
(k < 1) - k // either -k if k > 0 or 1 - k otherwise
// (0 → 1 → -1 → 2 → -2 → …)
) // end of recursive call
: // else:
k // return k
)(0) // initial call to g with k = 0
R, 126 125 123 bytes
\(x){b=which.min(m<-mapply(strtoi,x,2:36))+1
while(any(rev(q<-(n=m[b-1]+F)%/%b^(0:log(n,b))%%b)-q)|all(q-b+1))F=(F<1)-F
+F}
Partly uses @Giuseppe's solution to the linked challenge.
Lua, 304 269 bytes
Pain. Suffering. Being forced to implement index-to-radixed-string conversion manually. Uh…something something hardcoding the alphabet.
This only accepts uppercase letters for its input.
Addendum: OP managed to slash 35 characters by avoiding using a table at all.
a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"n=io.read()i=0t={}n:gsub(".",function(c)table.insert(t,c)end)table.sort(t)b=a:find(t[#t])n=tonumber(n,b)while 1 do s=""v=n+i repeat s=a:sub(v%b+1,v%b+1)..s v=v//b until v==0if s==s:reverse()and s:find(a:sub(b,b))then print(i)break end j=.5-i i=j+j/2/math.abs(j)end