VBScript,177字节
嘿,这是我的第一篇CG文章,也是第一次尝试,所以希望我遵循所有规则...
Function L(s)
dim i,j,k,m,n
j = Len(s)
redim a(j)
n = 0
for i = 0 to j-1
A(i) = Mid(s,i+1,1)
m = m + s Mod A(i)
if j = 1 then
else
for k = 0 to i - 1
if A(i) = A(k) then n = n + 1
next
end if
next
if m + n = 0 then L = "y" else L = "n"
End Function
可以在记事本中运行,方法是在末尾添加一行
Msgbox L(InputBox(""))
然后将其另存为.vbs,然后双击。
说明:
Function L(s) 'creates the function "L" taking test number as input
dim i,j,k,t,m,n 'variables
j = Len(s) '"j" gets length of test number
redim a(j) 'creates array "a", size is length of test number
n = 0 'sets repeat character counter "n" to zero
for i = 0 to j-1 'for length of string
A(i) = Mid(s,i+1,1) 'each array slot gets one test number character
m = m + s Mod A(i) '"m" accumulates moduli as we test divisibility of each digit
if j = 1 then 'if test number is of length 1, it passes (do nothing)
else 'otherwise, gotta test for repeats
for k = 0 to i - 1 'for each digit already in array, test against current digit
if A(i) = A(k) then n = n + 1
'repeat char counter "n" stores no of repeats
next 'proceed through array looking for repeat
end if
next 'test next digit for divisibility and repeats
if m + n = 0 then L = "y" else L = "n"
'check for any repeats and moduli,
'then return yes or no for LynchBelledness
End Function
VBScript是打高尔夫球的钝器,但是,我还没学过Ruby ...