login
Numbers written using exactly two distinct Roman numerals.
0

%I #14 Oct 05 2022 05:10:20

%S 4,6,7,8,9,11,12,13,15,19,21,22,23,25,29,31,32,33,35,39,40,51,52,53,

%T 55,60,70,80,90,101,102,103,105,110,120,130,150,190,201,202,203,205,

%U 210,220,230,250,290,301,302,303,305,310,320,330,350,390,400,501,502

%N Numbers written using exactly two distinct Roman numerals.

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Roman_numerals">Roman numerals</a>

%e 4, written IV, and 8, written VIII, are terms.

%e 14, written XIV, is not a term.

%t kmax=502; a={}; For[k=1, k<=kmax, k++, If[Length[DeleteDuplicates[Characters[RomanNumeral[k]]]] == 2, AppendTo[a,k]]]; a (* _Stefano Spezia_, Aug 26 2022 *)

%o (Python)

%o def f(s, k):

%o return s[:2] if k==4 else (s[1]*(k>=5)+s[0]*(k%5) if k<9 else s[0]+s[2])

%o def roman(n):

%o m, c, x, i = n//1000, (n%1000)//100, (n%100)//10, n%10

%o return "M"*m + f("CDM", c) + f("XLC", x) + f("IVX", i)

%o def ok(n): return len(set(roman(n))) == 2

%o print([k for k in range(503) if ok(k)]) # _Michael S. Branicky_, Aug 24 2022

%K nonn,base,fini,easy

%O 1,1

%A _Alain Cousquer_ and _Pierre-Hugues Villaume_, Aug 24 2022