Why settle for just one programming language when you can solve a problem in six different ones?
New post: https://jcarroll.com.au/2024/10/26/polyglot-maxxie-and-minnie/
in which I tackle a puzzle with a similar approach in #rstats , #APL 🍎, #julialang , #haskell , #python , and #rustlang , with a bonus solution in J
If you can spot improvements, have a different approach, or would like to add a solution in another language, let me know!
@jonocarroll
Just came across your blog post, here's my Julia solution:
```
maxmin(n::Integer) = maxxie(n), minnie(n)
function firstdigitswap(n::Integer, f::Function)
n == 0 && return 0
digs = digits(n)
val, i = f(digs)
digs[i] = digs[end]
digs[end] = val
digits2num(digs)
end
digits2num(digs) = mapreduce((i, d)::Tuple -> d*10^(i-1), +, enumerate(digs))
maxxie(n::Integer) = firstdigitswap(n, findmax)
minnie(n::Integer) = firstdigitswap(n, digs -> findmin((d > 0 ? d : 10 for d in digs)))
```
@jonocarroll
Ah, this is what happens when I read and code with 4am brain 😄 This just swaps the first digit with the max/min (non-zero) digit, which gives the same result in many cases, but fails for numbers like 92484957 (maxxie should return 99484257, returns with no swaps instead).