果冻,82字节
ị“+-×÷”;”/v®ṫ-¤®ṖṖ¤;©
4Ḷ⁵*p1,5P€
“IVXLCDM”iЀị¢µIN‘Ṡæ.µ®;©
Ḳµ“+-*/”W€i⁸Ñ⁸Ǥ¹?µ€ṛ®Ḋ
在线尝试!
最初张贴在聊天中。
说明:
由于Jelly没有堆栈,因此将堆栈放入寄存器中。
当程序启动时,寄存器值®是0,这将被视为[0]对本方案的目的。
ị“+-×÷”;”/v®ṫ-¤®ṖṖ¤;© Link 1: Given an operator index (an
integer in range 1..4), apply it.
ị“+-×÷” Index to the string "+-×÷"
;”/ Concatenate with the character "/",
which is Jelly splat operator.
v ¤ Evaluate with parameter...
® the register's
ṫ tail
- from -1. (2 last items)
® ¤; Concatenate with the register value,
ṖṖ pop twice.
© Store the result to register.
4Ḷ⁵*p1,5P€ Link 2: Niladic, generate [1,5,10,50,...]
4Ḷ Lowered range of 4, gives [0,1,2,3].
⁵* Raise to power of 10. Value = 1,10,100,1000.
p1,5 Calculate Cartesian product with [1,5].
Value = [1,1],[1,5],[10,1],[10,5],...
P€ Calculate product of each item.
Alternatively, ×þ1,5F would also work instead of p1,5P€.
“IVXLCDM”iЀị¢µIN‘Ṡæ.µ®;© Link 3: Given roman number, push it
to the stack (register).
i Find index of ...
Ѐ each character ...
“IVXLCDM” in "IVXLCDM".
ị¢ Index to last link. (link 2)
µ With that value, (consider LIX ->
[50,1,10] for example)
I
Ḳµ“+-*/”W€i⁸Ñ⁸Ǥ¹?µ€ṛ®Ḋ
[TODO complete explanation]