DC, 104 byte
Input diambil dari terminal, output dicetak dan juga di stack.
Karena ini menggunakan? operator, Anda harus menggunakan dc -e "<solution>"
atau dc <file with solution in it>
.
Tidak ada yang pernah melihat jawaban saya, apalagi memilihnya, tapi saya benar-benar menikmati menyelesaikan masalah di DC. Ini solusi paling efisien di utas ini sejauh ini, tapi saya pikir saya akan mempostingnya.
1sb?sn[lesi]ss[lble1+dse^dln=sln>c]sc[liSflq1+sq]sm[Lfplq1-dsq0<p]dsp[lb1+sb0si0selcxli0!=mlbln!=h]dshxx
barang pemula
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
Makro menaikkan basis ke semua kekuatan hingga hasilnya lebih besar dari target atau sama dengan target
[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
Makro untuk menyimpan nilai eksponen yang valid seperti yang ditemukan dari makro eksponen di atas ke tumpukan lain
[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
Makro menjalankan makro 2x di atas (makro c) melalui semua basis dari 2 hingga nomor target kami
[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
Makro untuk mencetak nilai dari f stack
[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]
untuk test case terakhir. Bisakah juga dicetak[6 3 2 1]
,[1.0 2.0 3.0 6.0]
atau[6.0 3.0 2.0 1.0]
?