login
Sum of digits of n in Roman numeral representation.
4

%I #24 Aug 10 2020 13:07:04

%S 1,2,3,6,5,6,7,8,11,10,11,12,13,16,15,16,17,18,21,20,21,22,23,26,25,

%T 26,27,28,31,30,31,32,33,36,35,36,37,38,41,60,61,62,63,66,65,66,67,68,

%U 71,50,51,52,53,56,55,56,57,58,61,60,61,62,63,66,65,66,67,68

%N Sum of digits of n in Roman numeral representation.

%H Nathaniel Johnston, <a href="/A093783/b093783.txt">Table of n, a(n) for n = 1..3999</a>

%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>

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

%e n=42 == XLII: a(42) = 'X' + 'L' + 'I' + 'I' = 10+50+1+1 = 62.

%p A093783 := proc(n) local r: r:=convert(n, roman): return add(convert(r[j], arabic), j=1..length(r)): end: seq(A093783(n), n=1..68); # _Nathaniel Johnston_, May 18 2011

%t Total[#2 FromRomanNumeral[#1] & @@@ Tally[Characters@ RomanNumeral@ #]] & /@ Range@ 68 (* _Michael De Vlieger_, Sep 08 2015, Version 10.2 *)

%o (Haskell)

%o a093783 n = q 0 $ a061493 n where

%o q s 0 = s

%o q s x = q (s + [0,1,5,10,50,100,500,1000] !! d') x'

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

%o -- _Reinhard Zumkeller_, Apr 14 2013

%o (HP 49G calculator)

%o ::

%o CK1&Dispatch

%o # FF

%o ::

%o FPTR2 ^DupQIsZero?

%o caseSIZEERR

%o FPTR2 ^Z>S

%o Z0_

%o SWAP

%o DUPLEN$

%o ZERO_DO

%o DUP

%o ISTOP-INDEX

%o SUB$1#

%o BINT48

%o #-

%o BINT4

%o OVER#=

%o OVER

%o BINT9

%o #=

%o OR

%o IT

%o #2+

%o FPTR2 ^#>Z

%o Z10_

%o INDEX@

%o FPTR2 ^RP#

%o FPTR2 ^RMULText

%o ROT

%o FPTR2 ^RADDext

%o SWAPLOOP

%o DROP

%o ;

%o ;

%o _Gerald Hillier_, Sep 08 2015

%Y Cf. A007953, A057226, A006968.

%Y Cf. A061493, A002963.

%K nonn,easy,base

%O 1,2

%A _Reinhard Zumkeller_, May 17 2004