in reply to Solution to A simple but difficult arithmetic puzzle

Couldn't sleep, so I put some stuff I had together:

#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1169564 use strict; $_ = 6652; 1 while do { /\d.*?\d(?{ 17 == eval "$`($&)$'" and print "$`($&)$'" })(*FAIL)/ for map tr#a-d#-+*/#r, glob join '{a,b,c,d}', split // }, s/.*\K # find the last (.) # digit such that (.*) # there is a later (latest) (.)(??{$1 <= $3 and '(*FAIL)'}) # digit less than it (.*) # and get rest # swap those two digits ( $1 & $3 ) # then reverse everything after the first swapped digit / $3 . reverse $2.$1.$4 /xe;