DC、104バイト
入力は端末から取得され、出力はスタック上にも出力されます。
これは?演算子を使用するには、dc -e "<solution>"
またはを使用する必要がありますdc <file with solution in it>
。
誰も私の答えを見たり、投票することはできませんが、DCでの問題解決は本当に楽しいです。これまでのところ、このスレッドで最も効率の悪いソリューションですが、とにかく投稿したいと思いました。
1sb?sn[lesi]ss[lble1+dse^dln=sln>c]sc[liSflq1+sq]sm[Lfplq1-dsq0<p]dsp[lb1+sb0si0selcxli0!=mlbln!=h]dshxx
スタータースタッフ
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
結果がターゲットよりも大きくなるかターゲットと等しくなるまで、すべての累乗に基数を上げるマクロ
[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
上記の指数マクロから見つかった有効な指数値を別のスタックに保存するマクロ
[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
2からターゲット番号までのすべてのベースを介してマクロの2倍(マクロc)を実行するマクロ
[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
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]
最後のテストケースの回答が印刷されます。それはまた、印刷できませんでした[6 3 2 1]
、[1.0 2.0 3.0 6.0]
または[6.0 3.0 2.0 1.0]
?