Red, 108 bytes
func[n][i: s: 0 until[t: form i
if(t > u: sort copy t)and(t < reverse u)[s: s + i n: n - 1]i: i + 1
0 = n]s]
More readable:
f: func [ n ] [
i: s: 0
until [
t: form i
if ( t > u: sort copy t ) and ( t < reverse u ) [
s: s + i
n: n - 1
]
i: i + 1
0 = n
]
s
]
A good opportunity to use form
- form i
is 5 bytes shorter than to-string i