您的挑战是制作一个程序或函数,以一种语言输出其输入的GCD,在另一种语言中输出其输入的LCM。GCD或LCM的内置程序(我正在看您,Mathematica)是允许的,但不鼓励。将有两个输入,它总是正整数,永远不会大于1000。
每一行都是x y => GCD(x,y) LCM(x,y)格式的一个测试用例:
1 1 => 1 1
1 2 => 1 2
4 1 => 1 4
3 4 => 1 12
7 5 => 1 35
18 15 => 3 90
23 23 => 23 23
999 1000 => 1 999000
1000 999 => 1 999000
1000 1000 => 1000 1000看这个巴斯泰尔为所有可能的输入与0 < x, y < 31。请注意,相同语言的不同版本作为不同的语言计算。
发布于 2017-04-18 03:27:21
发布于 2017-04-17 19:05:35
Alice计算LCM:
//L
oi@g看起来像空格的是0x7F,DEL控制字符。
果冻计算GCD。由于Jelly使用了只与可打印的ASCII兼容的自己的代码页,因此linefeed和DEL字符分别转换为½和linefeed:
//L½oi@
g果冻是微不足道的:第一行定义了一个无意义的辅助链接,第二行是实际的程序,它只是包含GCD内建的。
Alice有点棘手,但它也使用了内置的:
/ Reflect to SE. Switch to Ordinal.
While in Ordinal mode, the IP bounces diagonally up and down through the grid.
i Read all input as a single string.
L Compute the shortest common superstring of an empty string and the input. That
is simply the input itself, so this does nothing.
After two more bounces, the IP hits the top right corner and turns
around, continuing to bounce up and down while moving west.
L Still does nothing.
i Try to read more input, but this simply pushes an empty string.
/ Reflect to W. Switch to Cardinal.
The IP wraps to the last column.
L Implicitly discard the empty string and convert the input to two integers.
Compute their LCM.
/ Reflect to NW. Switch to Ordinal.
The IP immediately reflects off the top boundary to move SW instead.
o Implicitly convert the LCM to a string and print it.
Reflect off the bottom left corner and move back NE.
/ Reflect to S. Switch to Cardinal.
i Try to read a byte, but we're at EOF, so this pushes -1 instead. Irrelevant.
The IP wraps back to the first line.
/ Reflect to NE. Switch to Ordinal.
The IP immediately reflects off the top boundary to move SE instead.
@ Terminate the program.发布于 2017-04-17 19:12:21
在这一挑战之后,增加了CGL的LCM特性。
g=(a,b)=>b?g(b,a%b):a
//-LⓍ看起来像是一个空间,实际上是一个不间断的空间,是CGL的一个注释。JS计算GCD:
g=(a,b)=>b?g(b,a%b):aCGL计算LCM:
// does nothing
- decrements the current stack number, resulting in it pointing to input
L computes the LCM of the first and second stack items and pushes it to the stack
Ⓧ prints out the last stack item试试看:
Snippetify( g=(a,b)=>b?g(b,a%b):a
//-LⓍ
);<script src="https://programmer5000.com/snippetify.min.js"></script>
<input type = "number">
<input type = "number">https://codegolf.stackexchange.com/questions/116809
复制相似问题