You will not be asked to devise a function to find the third-least of $ 3 \raise .6ex {\small 3} \raise 1.1ex { \scriptsize 3}\!\: \raise 1.6ex { \tiny 3} \!\; \raise 2.2ex . \! \raise 2.5ex . \! \raise 2.8ex . \!\!\!\!\!\! $ numbers today, rather to merely show that you could. $ \begingroup \def \= { \mathop{\normalsize\,\raise-.2ex\triangleq\,} } \def \yellow { \color {#aaaa00} } \def \red { \color{#990044} } \def \t #1{ \small \text{#1} } \def \blunderline #1{{ #1 \rlap{ \, \llap {\red {\raise -.33ex{\underline {\hphantom {\, #1\, }}}}} \llap{ \yellow{ \raise-.55ex{ \underline{ \hphantom{ \,#1 \,}}}}} } }} \def \strikeline #1{{ #1 \rlap{ \, \llap { \red {\raise 1.18ex{\underline {\hphantom {\, #1\, }}}}} } }} $
- What definitions of $\t{3rd.27}(a,b,c,\dots,x,y,z,zz)$ and 4 other simple functions of your choice can work together to find the third-least of any 27 different numbers regardless of input order?
Devising 5 simple functions to find the third-least of only $27$ (${\small =}\, 3\small\raise.6ex 3$) numbers would surely convince anyone that 9 simple functions could cover 7625597484987 ($ {\small =}\, 3 \raise .6ex {\small 3} \raise 1.1ex { \scriptsize 3} $) input numbers and so on. A “simple function” has a fixed number of numeric inputs, like these sample simple functions.
$$\small\begin{align} \t{Max.3}(a,b,c) & \= \t {Max.2} ( \, \t{Max.2}(a,b) , c \, ) \\[1.5ex] \t{Median.3}(a,b,c) & \= \t {Max.3} ( \, \t {Min.2}(a,b) , \, \t {Min.2}(b,c) , \, \t{Min.2}(a,c) \, ) \end{align}$$
(“$\! \= \!$” means “is defined as.”) A simple function simply calls one other function, passing inputs that may each contain an additional level of function call. This amounts to a two-deep function call with no variables, conditionals, loops, other operations, . . . And the definition of a truly simple function does not include any larger functions (those with more inputs than the function being defined).
$$\small\begin{align} \t{TwoDeepIsOkay.4}(a,b,c,d) & \= \t {Max.2} ( \, \t {Max.2}(a,b) , \, \t{Max.2}(c,d) \, ) \\[1.5ex] \strikeline { \t {ThreeDeepIsTooDeep.4}(a,b,c,d) } & \= \strikeline{ \t {Max.2} ( \, \t {Max.2} ( \, \blunderline{ \t{Max.2}(a,b) } , \, c \, ) , \, d \, ) } \\[1.5ex] \strikeline { \t {ShouldNotCallLargerFunctions.}\blunderline{2}(a,b) } & \= \strikeline{ \t {Median.}\blunderline{3} ( \, a , \, b , \, \t{Mmm.}\blunderline{3}(a,b,a) \, ) } \end{align}$$
Just two functions are available to build upon, providing the lesser and greater of their two inputs: $ \t {Min.2}(a,b) $ and $ \t{Max.2}(a,b) $. These are not counted among the 5 functions to be defined but all other utilized functions are, including any of those mentioned above.
If all goes well, for example, $ \small \t{3rd.27} \, ( 70,71,72,73,74, \! $ $ \small 75,76,77,78,79, \! $ $ \small 80,81,82,83,84, \! $ $ \small 85,86,87, \! $ $ \small 11,12,13,14,15, \! $ $ \small 16,17,18,19 ) = 13 $. To further appreciate Paul Panzer’s solution notice how nicely its components lay out on this 3-dimensional grid of inputs to $ \small \t{3rd.27} \, ( a,b,c,d,e,f,g,h,i, \! $ $ \small j,k,l,m,n,o,p,q,r, \! $ $ \small s,t,u,v,w,x,y,z,zz ) $.
(This puzzle was motivated by Misha Lavrov’s solution to I don’t want the smallest one, I want the second-smallest one. Interesting answers that stray from stated conditions are welcome.) $\endgroup$
MathJax
puzzles' solutions actually create functions (\macros) on the fly. $\endgroup$