DC, 104 byte
L'input viene prelevato dal terminale, l'output viene stampato e anche nello stack.
Perché questo usa il? operatore, è necessario utilizzare dc -e "<solution>"
odc <file with solution in it>
.
Nessuno vede mai le mie risposte, figuriamoci votare su di esse, ma mi piace davvero solo risolvere i problemi in DC. Finora è la soluzione meno efficiente in questa discussione, ma ho pensato di pubblicarla comunque.
1sb?sn[lesi]ss[lble1+dse^dln=sln>c]sc[liSflq1+sq]sm[Lfplq1-dsq0<p]dsp[lb1+sb0si0selcxli0!=mlbln!=h]dshxx
roba di avviamento
1sb Store 1 in register b
?sn Store user input in register n
[lesi]ss A macro to copy the e to the i register, stored in the s register
Macro per elevare una base a tutti i poteri fino a quando il risultato non è più grande del bersaglio o uguale al bersaglio
[lble1+dse^dln=sln>c]sc
[lb ] load our base num (register b)
[ le ] load our exponent (register e)
[ 1+dse ] add 1 to the exponent, copy and store in the e register
[ ^d ] raise the base to the exponent and copy it
[ ln=s ] load the user input, if that is equal to the power result run the macro in register s
[ ln>c] load the user input, if it's greater than the power result run the macro in register c (this one)
[ ]sc save this macro in register c
Macro per salvare un valore di esponente valido come trovato dalle macro di esponente di cui sopra in un altro stack
[liSflq1+sq]sm
[liSf ] copy the i register to the top of the stack in register f
[ lq1+sq] add 1 to the q register
[ ]sm save this macro in the m register
Macro per eseguire la macro 2x sopra (macro c) attraverso tutte le basi da 2 al nostro numero di destinazione
[lb1+sb0si0selcxli0!=mlbln!=h]dsh
[lb1+sb ] add 1 to the base number
[ 0si0se ] reset the i and e registers (previously found value and exponent
[ lcx ] load and run the c macro
[ li0!=m ] load the result of the c macro and if it's not 0, run m to save it to the f stack
[ lbln!=h] if our base number is not equal to our target number, run macro h (this macro)
[ ]dsh duplicate this macro and save one copy, so that one is left on the stack to run later
Macro per stampare i valori dalla pila f
[Lfplq1-dsq0<p]dsp
[Lfp ] load the top value from the f register and print it
[ lq1-dsq ] load the q register and subtract one from it and save it
[ 0<p] if the q register is greater than 0, run macro p (this macro) again
[ ]dsp duplicate this macro and save one copy, so that one is left on the stack to run later
xx finally run the two macros on the stack (h and then p)
[1 2 3 6]
per l'ultimo caso di prova. Potrebbe anche stampare[6 3 2 1]
,[1.0 2.0 3.0 6.0]
o[6.0 3.0 2.0 1.0]
?