V
Попробуйте онлайн! Ссылка на подробную версию кода. Ограничен по диапазону до 9. X
s, 9 ≔⁻⪪α¹⪪XVI¹α
с и 39 F⁴F⪪”{⊞‴ΣAº⧴θπ⪪λpAz” ⊞υ⁺×Xικ
s so that it will complete in a reasonable amount of time on TIO. Outputs all of the autograms that it can find. Letters are not in sorted order. Explanation:
I
Сгенерируйте все римские цифры до 39.
V
Удалить буквы X
, F⁴F⪪”{⊞‴ΣAº⧴θπ⪪λpAz” ⊞υ⁺×Xικ≔⁻⪪α¹⪪XVI¹α≔⁻α⪪⁺θη¹ζFχFχF⁴⁰«≔⪫⮌EΦ⁺E⟦ικλ⟧∧μ⁺⁺§υμ §XVIνE⁻αζ⁺⁺§υ⊕№⁺θημ μμ⎇νμ⁺⁺η μ, ε≔⁻λ№⁺θεIδ¿⁼δ﹪δ⊕Lζ¿⁼⟦ικ⟧EXV№⁺θεμ⟦⁺⁺⁺θ эδ⁺⁺I §ζμ, ε
и FALSE
from the uppercase alphabet variable because they're a special case.
S
Получите все оставшиеся заглавные буквы, которых нет во вступлении или разделителе.
I
Перебрать все поддерживаемые номера function(I,S){library(stringr)
p=paste
t=str_count
f=str_flatten
u=toupper
r=as.roman
l=LETTERS
a=r((e<-t(u(f(c(I,S))),l)+1)+t(f(as.roman(e)),l))
n=1;i=F
while(!i&&n<=9){s=p(I,p(append(p(a,l),S,25),collapse=", "))
b=r(t(u(s),l))
i=identical(a,b)
n=n+1
a=b}
"if"(i,s,i)}
s, import roman #third party Python module (https://pypi.org/project/roman/)
from collections import*
c=Counter
d={'I': 1, 'II': 2, 'III': 3, 'IV': 4, 'V': 5, 'VI': 6, 'VII': 7, 'VIII': 8, 'IX': 9, 'X': 10, 'XI': 11, 'XII': 12, 'XIII': 13, 'XIV': 14, 'XV': 15, 'XVI': 16, 'XVII': 17, 'XVIII': 18, 'XIX': 19, 'XX': 20, 'XXI': 21, 'XXII': 22, 'XXIII': 23, 'XXIV': 24, 'XXV': 25, 'XXVI': 26, 'XXVII': 27, 'XXVIII': 28, 'XXIX': 29, 'XXX': 30, 'XXXI': 31, 'XXXII': 32, 'XXXIII': 33, 'XXXIV': 34, 'XXXV': 35, 'XXXVI': 36, 'XXXVII': 37, 'XXXVIII': 38, 'XXXIX': 39, 'XL': 40}
e='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
g={d[i]:i for i in d}
def t(s,f):
s=s+''.join(g.get(b,roman.toRoman(b))+a for a,b in f.items());return all(s.count(i)==f[i]for i in f)
def n(a,k):
if not a:yield k
else:
for i in range(k[a[0]], k[a[0]]+(max(i.count(a[0])for i in d)*26)+1):yield from n(a[1:],{**k,**{a:k[a]+b for a,b in c(g.get(i,roman.toRoman(i))).items()}})
def f(q,w):
for i in n(e,c((s:=(q+w).replace(' ',''))+e)):
k=[j for j in i if j not in s and i[j]==1]
for x in range(len(k)):
if t(s,(r:={a:b for a, b in i.items()if a not in k[:x]})):return q+' '+', '.join(g.get(r[v],roman.toRoman(r[v]))+' '+v for v in[*r][:-1])+' '+w+' '+g.get(r[[*r][-1]],roman.toRoman(r[[*r][-1]]))+' '+[*r][-1]
print(f('VVVVVV','AND')) # 'VVVVVV IX V, II A, II N, II D, I G, I H, XXVIII I, I J, I K, I L, I M, I O, I P, I Q, I R, I S, I T, I U, I W, IV X, I Y AND I Z'
песок > 40
s.
40
Создайте суффикс автограммы, используя только буквы. from collections import*
c=Counter
e='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
g='_ I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV XXV XXVI XXVII XXVIII XXIX XXX XXI XXXII XXXIII XXXIV XXXV XXXVI XXXVII XXXVIII XXXIX XL'.split()
d={v:k for k,v in enumerate(g)}
def t(s,f):
s=s+''.join(g[b]+a for a,b in f.items());return all(s.count(i)==f[i]for i in f)
def n(a,k):
if not a:yield k
else:
for i in range(k[a[0]], k[a[0]]+(max(i.count(a[0])for i in d)*26)+1):yield from n(a[1:],{**k,**{a:k[a]+b for a,b in c(g[i]).items()}})
def f(q,w):
for i in n(e,c((s:=(q+w).replace(' ',''))+e)):
k=[j for j in i if j not in s and i[j]==1]
for x in range(len(k)):
if t(s,(r:={a:b for a, b in i.items()if a not in k[:x]})):return q+' '+', '.join(g[r[v]]+' '+v for v in[*r][:-1])+' '+w+' '+g[r[[*r][-1]]]+' '+[*r][-1]
, z "IN HAC SENTENTIA SVNT", "ET"
IN HAC SENTENTIA SVNT III A, II C, IV E, II H, XIX I, V N, III S, V T, VI V, ET III X.
z "My very nice sentence contains", "and"
My very nice sentence contains III A, IV C, II D, VI E, XXXI I, II M, VII N, II O, II R, III S, III T, VII V, IV X, and III Y.
z "This autogram uses", "and last but not least"
This autogram uses VI A, II B, II D, III E, II G, II H, XXXVI I, III L, II M, III N, III O, II R, VI S, VII T, IV U, VIII V, and last but not least IV X.
z "This iiii sentence uses", "and finally"
This iiii sentence uses III A, II C, II D, V E, II F, II H, XXXI I, III L, V N, V S, III T, II U, VI V, IV X, and finally II Y.
, XXIV I
and any other letters in the intro and separator.
XXV I
Посмотрите, сколько XXIV I
s we are short.
V
Можем ли мы составить количество I
s using letters not present in the intro or separator?
Sub z(a, b)
Do
' Loop through all the characters A-Z
For i = 65 To 90
c = Chr(i)
' Split the string on that character to count its occurrences
' Here, we use the two inputs and the result of the last search (s)
' The 1 at the end makes it a text comparison so capitalization doesn't matter
[A1] = UBound(Split(a + b + s, c, , 1))
' If we found any ([A1]>0), then add that count to the working string (t)
' Excel has a built-in function to convert Arabic numerals to Roman numerals so long as it's between 1 and 3999 inclusive.
If [A1] Then t = t + [Roman(A1)] + " " + c + ", "
Next
' If the working string (t) matches the last result (s) then exit the loop
If t = s Then Exit Do
' Otherwise, reset the last result and working string
s = t
t = ""
Loop
' We haven't included the "last separator" at the right spot so let's do that
u = Split(s, ",")
For i = 0 To UBound(u) - 2
r = r + u(i) + ","
Next
' Ouput the "intro", most of the result, the "last separator", and the last item from the result
Debug.Print a; " "; r; " "; b; u(i); "."
End Sub
Сделайте числа b
s and a
совпадение?
Sub z(a,b)
Do
For i=65To 90
c=Chr(i)
[A1]=UBound(Split(a+b+s,c,,1))
If[A1]Then t=t+[Roman(A1)]+" "+c+",
Next
If t=s Then Exit Do
s=t
t="
Loop
u=Split(s,",")
For i=0To UBound(u)-2
r=r+u(i)+",
Next
Debug.?a" "r" "b u(i)".
End Sub
Если да, то объедините вступление с необходимыми дополнительными буквами и суффиксом и выведите полученную автограмму.