Answers:
T.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Listen tothy!Page:You cat!Scene V:.Page:You be the sum ofyou a cat!Be the product ofthe quotient betweenI you you worse I?If soLet usScene V.Open heart
(I/you)*you<I
比I%you>0
SPL中的短。
n->{int r=1;for(;n%++r>0;);return r;}
-7字节间接感谢@Tsathoggua。
-2个字节,感谢JoKing
说明:
n->{ // Method with integer as both parameter and return-type
int r=1; // Start the result-integer `r` at 1
for(;n%++r>0;); // Increase `r` by 1 before every iteration with `++r`
// and loop until `n` is divisible by `r`
return r;} // After the loop, return `r` as result
n->{for(int i=1;++i<=n;)if(n%i<1)return i;}
以获取43个字符?(我不会讲Java。)
n->{for(int i=1;++i<=n;)if(n%i<1)return i;return n;}
可以,但是不幸的是更长。Java可以在无限循环中有一个返回,但是确实可以节省字节,所以谢谢!n->{for(int i=1;;)if(n%++i<1)return i;}
。由于最终i
会变成n
(和测试用例一样2687
)和n%n==0
,因此i<=n
在这种情况下不是必需的。
if/else
,则可以(通常)保存一个字节and/or
。就像f=lambda n,x=2:n%x and f(n,x+1)or x
。
[S S T T N
_Push_-1][S S S N
_Push_0][T N
T T _Read_STDIN_as_number][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T S S T _Subtract][S N
S _Duplicate][S S S N
_Push_0][T T T _Retrieve][S N
T _Swap][T S T T _Modulo][N
T T N
_If_0_Jump_to_Label_LOOP][S S T T N
_Push_-1][T S S N
_Multiply][T N
S T _Print_as_number]
-20个字节,感谢@JoKing。
字母S
(空格),T
(制表符)和N
(换行符)仅作为突出显示而添加。
[..._some_action]
仅作为说明添加。
在线尝试(仅使用空格,制表符和换行符)。
伪代码中的解释:
Integer n = STDIN as integer
Integer i = -1
Start LOOP:
i = i - 1
if(n modulo-i is negative)
Go to next iteration of LOOP
else
i = i * -1
Print i
Exit with error: No exit defined
示例运行: input = 9
Command Explanation Stack Heap STDIN STDOUT STDERR
SSTTN Push -1 [-1]
SSSN Push 0 [-1,0]
TNTT Read STDIN as integer [-1] {0:9} 9
NSSN Create Label_LOOP [-1] {0:9}
SSSTN Push 1 [-1,1] {0:9}
TSST Subtract top two (-1-1) [-2] {0:9}
SNS Duplicate top (-2) [-2,-2] {0:9}
SSSN Push 0 [-2,-2,0] {0:9}
TTT Retrieve [-2,-2,9] {0:9}
SNT Swap top two [-2,9,-2] {0:9}
TSTT Modulo top two (9%-2) [-2,-1] {0:9}
NTSN If neg.: Jump to Label_LOOP [-2] {0:9}
SSTTN Push -1 [-2,-1] {0:9}
TSST Subtract top two (-2-1) [-3] {0:9}
SNS Duplicate top (-2) [-3,-3] {0:9}
SSSN Push 0 [-3,-3,0] {0:9}
TTT Retrieve [-3,-3,9] {0:9}
SNT Swap top two [-3,9,-3] {0:9}
TSTT Modulo top two (9%-3) [-3,0] {0:9}
NTSN If neg.: Jump to Label_LOOP [-3] {0:9}
SSTTN Push -1 [-3,-1] {0:9}
TSSN Multiply top two (-3*-1) [3] {0:9}
TNST Print as integer [] {0:9} 3
error
程序因错误而停止:未找到出口。
i == n
支票吗?n%n
无论如何都会是0
n%i
然后再调用打印?
@(x)factor(x)(1)
@(x) % Anonymous function taking x as input
factor(x) % Prime factorization
(1) % Get the first element
要么:
@(x)max(factor(x)) % the makeup of makeup artists
: f 1 begin 1+ 2dup mod 0= until ;
: f \ Define a new word
1 \ place a 1 on the stack (to use as a counter/index)
begin \ start indefinite loop
1+ 2dup \ increment counter and duplicate counter and prime power
mod \ calculate power % index
0= until \ end the loop if modulus is 0 (no remainder)
; \ end word definition
param($a)(2..$a|?{!($a%$_)})[0]
构造从2
到输入的范围$a
,取出那些元素where
(?
),取模运算%
结果为零!(...)
(即那些为的除数$a
),然后取其中的最小的[0]
一个。剩下的就在管道上,输出是隐式的。
-52字节感谢@Jo King
Function A(n)
For i=n To 2 Step-1
A=If(n Mod i=0,i,A)
Next
End Function
取消高尔夫:
Function A(input As Long) As Long
For i = input To 2 Step -1
A = If (input Mod i = 0, i, A)
Next
End Function
说明:
在i
从第一个数字环路搜索倒着,并认为平均分配所有的数字。因为我们要倒退,所以最小的存储在vairable中A
。
VB为您提供了一个与您的函数名称相匹配的免费变量(在我的情况下为A
)。函数执行结束时,将返回该变量中的值(除非有明确的Return
语句。
n
是1吗?