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をまだ学んでいません...