VBScript, 177 octets
Salut à tous, ceci est mon tout premier post CG, et ma première tentative, alors j'espère avoir suivi toutes les règles ...
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
Cela peut être exécuté à partir du bloc-notes en ajoutant une ligne à la fin
Msgbox L(InputBox(""))
Et puis l'enregistrer en tant que .vbs, puis double-cliquez.
Explication:
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 est un peu un instrument contondant pour le golf, mais bon, je n'ai pas encore appris Ruby ...