%I M0417 #63 Mar 04 2024 01:23:49
%S 1,2,3,2,1,2,3,4,2,1,2,3,4,3,2,3,4,5,3,2,3,4,5,4,3,4,5,6,4,3,4,5,6,5,
%T 4,5,6,7,5,2,3,4,5,4,3,4,5,6,4,1,2,3,4,3,2,3,4,5,3,2,3,4,5,4,3,4,5,6,
%U 4,3,4,5,6,5,4,5,6,7,5,4,5,6,7,6,5,6,7,8,6,2,3,4,5,4,3,4,5,6,4,1,2,3,4,3,2
%N Number of letters in Roman numeral representation of n.
%C How is this sequence defined for large values? - _Charles R Greathouse IV_, Feb 01 2011
%C See A078715 for a discussion on the Roman 4M-problem. - _Reinhard Zumkeller_, Apr 14 2013
%C The sequence can be considered to be defined via the formula (as A055642 o A061493), so the question is to be posed in A061493, not here. - _M. F. Hasler_, Jan 12 2015
%D GCHQ, The GCHQ Puzzle Book, Penguin, 2016. See page 60.
%D Netnews group rec.puzzles, Frequently Asked Questions (FAQ) file. (Science Section).
%D N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
%H Nathaniel Johnston, <a href="/A006968/b006968.txt">Table of n, a(n) for n = 1..3999</a>
%H Rec.puzzles, <a href="http://www.rec-puzzles.org">Archive</a>
%H Gerard Schildberger, <a href="/A006968/a006968.txt">The first 3999 numbers in Roman numerals</a>
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/RomanNumerals.html">Roman Numerals</a>
%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Roman_numerals">Roman numerals</a>
%H <a href="/index/Lc#letters">Index entries for sequences related to number of letters in n</a>
%F A006968 = A055642 o A061493, i.e., a(n) = A055642(A061493(n)). - _M. F. Hasler_, Jan 11 2015
%p A006968 := proc(n) return length(convert(n,roman)): end: seq(A006968(n),n=1..105); # _Nathaniel Johnston_, May 18 2011
%t a[n_] := StringLength[ IntegerString[ n, "Roman"]]; Table[a[n], {n, 1, 105}] (* _Jean-François Alcover_, Dec 27 2011 *)
%o (R) as.roman(1 :1024) # _N. J. A. Sloane_, Aug 23 2009
%o (Haskell)
%o a006968 = lenRom 3 where
%o lenRom 0 z = z
%o lenRom p z = [0, 1, 2, 3, 2, 1, 2, 3, 4, 2] !! m + lenRom (p - 1) z'
%o where (z',m) = divMod z 10
%o -- _Reinhard Zumkeller_, Apr 14 2013
%o (PARI) A006968(n)=#Str(A061493(n)) \\ _M. F. Hasler_, Jan 11 2015
%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 a(n):
%o m, c, x, i = n//1000, (n%1000)//100, (n%100)//10, n%10
%o return len("M"*m + f("CDM", c) + f("XLC", x) + f("IVX", i))
%o print([a(n) for n in range(1, 101)]) # _Michael S. Branicky_, Mar 03 2024
%Y Cf. A002963, A036746, A036786, A036787, A036788, A061493, A092196, A160676, A160677, A199921.
%K nonn,base,nice,easy
%O 1,2
%A _N. J. A. Sloane_
%E More terms from _Eric W. Weisstein_