login
Sequence of digit-values after concatenating the natural numbers < 4000 in Roman numeral representation.
2

%I #31 Mar 05 2024 07:10:15

%S 1,1,1,1,1,1,1,5,5,5,1,5,1,1,5,1,1,1,1,10,10,10,1,10,1,1,10,1,1,1,10,

%T 1,5,10,5,10,5,1,10,5,1,1,10,5,1,1,1,10,1,10,10,10,10,10,1,10,10,1,1,

%U 10,10,1,1,1,10,10,1,5,10,10,5,10,10,5,1,10,10,5,1

%N Sequence of digit-values after concatenating the natural numbers < 4000 in Roman numeral representation.

%C In other words, read the sequence of Roman numerals of natural numbers without spaces: I II III IV V VI VII VIII IX, ..., replacing I by 1, V by 5, X by 10, etc.

%D GCHQ, The GCHQ Puzzle Book, Penguin, 2016. See Question 300(b), page 199.

%H Nathaniel Johnston, <a href="/A093796/b093796.txt">Table of n, a(n) for n = 1..30000</a> (complete up to 3999)

%H Stephanus Gibbs, <a href="http://www.softhawkway.com/rcalc.htm">Roman Numeral and Date Conversion</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/RomanNumerals.html">Roman Numerals</a>

%e I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII, ...

%e I,(I,I),(I,I,I),(I,V),V,(V,I),(V,I,I),(V,I,I,I),(I,X), ...

%e 1,(1,1),(1,1,1),(1,5),5,(5,1),(5,1,1),(5,1,1,1),(1,10), ...

%e 1,1,1,1,1,1,1,5,5,5,1,5,1,1,5,1,1,1,1,10,10,10,1,10,1,1, ...

%p for n from 1 to 50 do r:=convert(n, roman): for j from 1 to length(r) do printf("%d, ", convert(r[j],arabic)): od: od: # _Nathaniel Johnston_, May 18 2011

%t A093796full = Flatten[FromRomanNumeral[Characters[RomanNumeral[Range[3999]]]]];

%t A093796full[[;;100]] (* _Paolo Xausa_, Mar 03 2024 *)

%o (Haskell)

%o import Data.List (unfoldr)

%o a093796 n = a093796_list !! n

%o a093796_list = concatMap (reverse . unfoldr r) $ map a061493 [1..3999]

%o where r 0 = Nothing

%o r x = Just ([0,1,5,10,50,100,500,1000] !! fromInteger d, x')

%o where (x', d) = divMod x 10

%o -- _Reinhard Zumkeller_, Apr 14 2013

%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 r(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 afull():

%o v = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}

%o ans = []

%o for i in range(1, 4000): ans.extend([v[d] for d in r(i)])

%o return ans

%o print(afull()[:80]) # _Michael S. Branicky_, Mar 04 2024

%Y Cf. A007376.

%Y Cf. A061493; A222581 (run lengths).

%K nonn,base,easy,fini,full

%O 1,8

%A _Reinhard Zumkeller_, May 18 2004