When in Rome, Count as Romans do?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
19
down vote

favorite
2












Background



This challenge is inspired by this website, which published the following diagram:



enter image description here



This diagram shows us that the longest Roman Numeral expression under 250 is that of 188, which requires 9 numerals to express.



Challenge



The standard symbols used to express most Roman Numerals are the following: I, V, X, L, C, D, M, where the characters' numeric values are M=1000, D=500, C=100, L=50, X=10, V=5, I=1.



In this challenge, your goal is to, given an positive integer n, compute the number of valid Roman Numeral representations that can be composed through concatenating n of the standard symbols.



Then, your program must output the result of this computation!



Input: A positive integer n.



Output: The number of valid roman numeral expressions of length n.



Rules for Roman Numeral Expressions



Roman Numerals originally only had "additive" pairing, meaning that numerals were always written in descending order, and the sum of the values of all the numerals was the value of the number.



Later on, subtractive pairing, the use of placing a smaller numeral in front of a larger in order to subtract the smaller from the larger, became commonplace to shorten Roman Numeral expressions. Subtractive pairs cannot be chained, like in the following invalid expression: IXL.



The following are the modern day rules for additive and subtractive pairing.



  1. Only one I, X, and C can be used as the leading numeral in part of a subtractive pair.

  2. I can only be placed before V or X in a subtractive pair.

  3. X can only be placed before L or C in a subtractive pair.

  4. C can only be placed before D or M in a subtractive pair.

  5. Other than subtractive pairs, numerals must be in descending order (meaning that if you drop the leading numeral of each subtractive pair, then the numerals will be in descending order).

  6. M, C, and X cannot be equalled or exceeded by smaller denominations.

  7. D, L, and V can each only appear once.

  8. Only M can be repeated 4 or more times.

Further Notes



  • We will not be using the bar notation; rather, we will simply add more Ms to express any number.


  • These are the only rules that we will follow for our roman numerals. That means that odd expressions, such as IVI, will also be considered valid in our system.


  • Also remember that we are not counting the number of numbers that have expressions of length n, since some numbers have multiple expressions. Instead, we are solely counting the number of valid expressions.


Test Cases



1 → 7



2 → 31



3 → 105



I checked the above by hand, so please make sure to double check the test cases, and add more if you can!



Winning Criteria



This is a code-golf challenge, so have fun! I will only accept solutions that can handle at least inputs from 1 through 9. Any more is bonus!



Edit



As requested by commenters, find below, or at this pastebin link, the 105 combos I counted for n=3




III
IVI
IXI
IXV
IXX
VII
XII
XIV
XIX
XVI
XXI
XXV
XXX
XLI
XLV
XLX
XCI
XCV
XCX
XCL
XCC
LII
LIV
LIX
LVI
LXI
LXV
LXX
CII
CIV
CIX
CVI
CXI
CXV
CXX
CXL
CXC
CLI
CLV
CLX
CCI
CCV
CCX
CCL
CCC
CDI
CDV
CDX
CDL
CDC
CMI
CMV
CMX
CML
CMC
CMD
CMM
DII
DIV
DIX
DVI
DXI
DXV
DXX
DXL
DXC
DLI
DLV
DLX
DCI
DCV
DCX
DCL
DCC
MII
MIV
MIX
MVI
MXI
MXV
MXX
MXL
MXC
MLI
MLV
MLX
MCI
MCV
MCX
MCL
MCC
MCD
MCM
MDI
MDV
MDX
MDL
MDC
MMI
MMV
MMX
MML
MMC
MMD
MMM




Edit 2:



Use the following non-golfed code, as courtesy of Jonathan Allan to check your results.



Edit 3:



I apologize for all of the errors in this challenge. I'll make sure to do a better job next time!










share|improve this question























  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 11 at 0:20














up vote
19
down vote

favorite
2












Background



This challenge is inspired by this website, which published the following diagram:



enter image description here



This diagram shows us that the longest Roman Numeral expression under 250 is that of 188, which requires 9 numerals to express.



Challenge



The standard symbols used to express most Roman Numerals are the following: I, V, X, L, C, D, M, where the characters' numeric values are M=1000, D=500, C=100, L=50, X=10, V=5, I=1.



In this challenge, your goal is to, given an positive integer n, compute the number of valid Roman Numeral representations that can be composed through concatenating n of the standard symbols.



Then, your program must output the result of this computation!



Input: A positive integer n.



Output: The number of valid roman numeral expressions of length n.



Rules for Roman Numeral Expressions



Roman Numerals originally only had "additive" pairing, meaning that numerals were always written in descending order, and the sum of the values of all the numerals was the value of the number.



Later on, subtractive pairing, the use of placing a smaller numeral in front of a larger in order to subtract the smaller from the larger, became commonplace to shorten Roman Numeral expressions. Subtractive pairs cannot be chained, like in the following invalid expression: IXL.



The following are the modern day rules for additive and subtractive pairing.



  1. Only one I, X, and C can be used as the leading numeral in part of a subtractive pair.

  2. I can only be placed before V or X in a subtractive pair.

  3. X can only be placed before L or C in a subtractive pair.

  4. C can only be placed before D or M in a subtractive pair.

  5. Other than subtractive pairs, numerals must be in descending order (meaning that if you drop the leading numeral of each subtractive pair, then the numerals will be in descending order).

  6. M, C, and X cannot be equalled or exceeded by smaller denominations.

  7. D, L, and V can each only appear once.

  8. Only M can be repeated 4 or more times.

Further Notes



  • We will not be using the bar notation; rather, we will simply add more Ms to express any number.


  • These are the only rules that we will follow for our roman numerals. That means that odd expressions, such as IVI, will also be considered valid in our system.


  • Also remember that we are not counting the number of numbers that have expressions of length n, since some numbers have multiple expressions. Instead, we are solely counting the number of valid expressions.


Test Cases



1 → 7



2 → 31



3 → 105



I checked the above by hand, so please make sure to double check the test cases, and add more if you can!



Winning Criteria



This is a code-golf challenge, so have fun! I will only accept solutions that can handle at least inputs from 1 through 9. Any more is bonus!



Edit



As requested by commenters, find below, or at this pastebin link, the 105 combos I counted for n=3




III
IVI
IXI
IXV
IXX
VII
XII
XIV
XIX
XVI
XXI
XXV
XXX
XLI
XLV
XLX
XCI
XCV
XCX
XCL
XCC
LII
LIV
LIX
LVI
LXI
LXV
LXX
CII
CIV
CIX
CVI
CXI
CXV
CXX
CXL
CXC
CLI
CLV
CLX
CCI
CCV
CCX
CCL
CCC
CDI
CDV
CDX
CDL
CDC
CMI
CMV
CMX
CML
CMC
CMD
CMM
DII
DIV
DIX
DVI
DXI
DXV
DXX
DXL
DXC
DLI
DLV
DLX
DCI
DCV
DCX
DCL
DCC
MII
MIV
MIX
MVI
MXI
MXV
MXX
MXL
MXC
MLI
MLV
MLX
MCI
MCV
MCX
MCL
MCC
MCD
MCM
MDI
MDV
MDX
MDL
MDC
MMI
MMV
MMX
MML
MMC
MMD
MMM




Edit 2:



Use the following non-golfed code, as courtesy of Jonathan Allan to check your results.



Edit 3:



I apologize for all of the errors in this challenge. I'll make sure to do a better job next time!










share|improve this question























  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 11 at 0:20












up vote
19
down vote

favorite
2









up vote
19
down vote

favorite
2






2





Background



This challenge is inspired by this website, which published the following diagram:



enter image description here



This diagram shows us that the longest Roman Numeral expression under 250 is that of 188, which requires 9 numerals to express.



Challenge



The standard symbols used to express most Roman Numerals are the following: I, V, X, L, C, D, M, where the characters' numeric values are M=1000, D=500, C=100, L=50, X=10, V=5, I=1.



In this challenge, your goal is to, given an positive integer n, compute the number of valid Roman Numeral representations that can be composed through concatenating n of the standard symbols.



Then, your program must output the result of this computation!



Input: A positive integer n.



Output: The number of valid roman numeral expressions of length n.



Rules for Roman Numeral Expressions



Roman Numerals originally only had "additive" pairing, meaning that numerals were always written in descending order, and the sum of the values of all the numerals was the value of the number.



Later on, subtractive pairing, the use of placing a smaller numeral in front of a larger in order to subtract the smaller from the larger, became commonplace to shorten Roman Numeral expressions. Subtractive pairs cannot be chained, like in the following invalid expression: IXL.



The following are the modern day rules for additive and subtractive pairing.



  1. Only one I, X, and C can be used as the leading numeral in part of a subtractive pair.

  2. I can only be placed before V or X in a subtractive pair.

  3. X can only be placed before L or C in a subtractive pair.

  4. C can only be placed before D or M in a subtractive pair.

  5. Other than subtractive pairs, numerals must be in descending order (meaning that if you drop the leading numeral of each subtractive pair, then the numerals will be in descending order).

  6. M, C, and X cannot be equalled or exceeded by smaller denominations.

  7. D, L, and V can each only appear once.

  8. Only M can be repeated 4 or more times.

Further Notes



  • We will not be using the bar notation; rather, we will simply add more Ms to express any number.


  • These are the only rules that we will follow for our roman numerals. That means that odd expressions, such as IVI, will also be considered valid in our system.


  • Also remember that we are not counting the number of numbers that have expressions of length n, since some numbers have multiple expressions. Instead, we are solely counting the number of valid expressions.


Test Cases



1 → 7



2 → 31



3 → 105



I checked the above by hand, so please make sure to double check the test cases, and add more if you can!



Winning Criteria



This is a code-golf challenge, so have fun! I will only accept solutions that can handle at least inputs from 1 through 9. Any more is bonus!



Edit



As requested by commenters, find below, or at this pastebin link, the 105 combos I counted for n=3




III
IVI
IXI
IXV
IXX
VII
XII
XIV
XIX
XVI
XXI
XXV
XXX
XLI
XLV
XLX
XCI
XCV
XCX
XCL
XCC
LII
LIV
LIX
LVI
LXI
LXV
LXX
CII
CIV
CIX
CVI
CXI
CXV
CXX
CXL
CXC
CLI
CLV
CLX
CCI
CCV
CCX
CCL
CCC
CDI
CDV
CDX
CDL
CDC
CMI
CMV
CMX
CML
CMC
CMD
CMM
DII
DIV
DIX
DVI
DXI
DXV
DXX
DXL
DXC
DLI
DLV
DLX
DCI
DCV
DCX
DCL
DCC
MII
MIV
MIX
MVI
MXI
MXV
MXX
MXL
MXC
MLI
MLV
MLX
MCI
MCV
MCX
MCL
MCC
MCD
MCM
MDI
MDV
MDX
MDL
MDC
MMI
MMV
MMX
MML
MMC
MMD
MMM




Edit 2:



Use the following non-golfed code, as courtesy of Jonathan Allan to check your results.



Edit 3:



I apologize for all of the errors in this challenge. I'll make sure to do a better job next time!










share|improve this question















Background



This challenge is inspired by this website, which published the following diagram:



enter image description here



This diagram shows us that the longest Roman Numeral expression under 250 is that of 188, which requires 9 numerals to express.



Challenge



The standard symbols used to express most Roman Numerals are the following: I, V, X, L, C, D, M, where the characters' numeric values are M=1000, D=500, C=100, L=50, X=10, V=5, I=1.



In this challenge, your goal is to, given an positive integer n, compute the number of valid Roman Numeral representations that can be composed through concatenating n of the standard symbols.



Then, your program must output the result of this computation!



Input: A positive integer n.



Output: The number of valid roman numeral expressions of length n.



Rules for Roman Numeral Expressions



Roman Numerals originally only had "additive" pairing, meaning that numerals were always written in descending order, and the sum of the values of all the numerals was the value of the number.



Later on, subtractive pairing, the use of placing a smaller numeral in front of a larger in order to subtract the smaller from the larger, became commonplace to shorten Roman Numeral expressions. Subtractive pairs cannot be chained, like in the following invalid expression: IXL.



The following are the modern day rules for additive and subtractive pairing.



  1. Only one I, X, and C can be used as the leading numeral in part of a subtractive pair.

  2. I can only be placed before V or X in a subtractive pair.

  3. X can only be placed before L or C in a subtractive pair.

  4. C can only be placed before D or M in a subtractive pair.

  5. Other than subtractive pairs, numerals must be in descending order (meaning that if you drop the leading numeral of each subtractive pair, then the numerals will be in descending order).

  6. M, C, and X cannot be equalled or exceeded by smaller denominations.

  7. D, L, and V can each only appear once.

  8. Only M can be repeated 4 or more times.

Further Notes



  • We will not be using the bar notation; rather, we will simply add more Ms to express any number.


  • These are the only rules that we will follow for our roman numerals. That means that odd expressions, such as IVI, will also be considered valid in our system.


  • Also remember that we are not counting the number of numbers that have expressions of length n, since some numbers have multiple expressions. Instead, we are solely counting the number of valid expressions.


Test Cases



1 → 7



2 → 31



3 → 105



I checked the above by hand, so please make sure to double check the test cases, and add more if you can!



Winning Criteria



This is a code-golf challenge, so have fun! I will only accept solutions that can handle at least inputs from 1 through 9. Any more is bonus!



Edit



As requested by commenters, find below, or at this pastebin link, the 105 combos I counted for n=3




III
IVI
IXI
IXV
IXX
VII
XII
XIV
XIX
XVI
XXI
XXV
XXX
XLI
XLV
XLX
XCI
XCV
XCX
XCL
XCC
LII
LIV
LIX
LVI
LXI
LXV
LXX
CII
CIV
CIX
CVI
CXI
CXV
CXX
CXL
CXC
CLI
CLV
CLX
CCI
CCV
CCX
CCL
CCC
CDI
CDV
CDX
CDL
CDC
CMI
CMV
CMX
CML
CMC
CMD
CMM
DII
DIV
DIX
DVI
DXI
DXV
DXX
DXL
DXC
DLI
DLV
DLX
DCI
DCV
DCX
DCL
DCC
MII
MIV
MIX
MVI
MXI
MXV
MXX
MXL
MXC
MLI
MLV
MLX
MCI
MCV
MCX
MCL
MCC
MCD
MCM
MDI
MDV
MDX
MDL
MDC
MMI
MMV
MMX
MML
MMC
MMD
MMM




Edit 2:



Use the following non-golfed code, as courtesy of Jonathan Allan to check your results.



Edit 3:



I apologize for all of the errors in this challenge. I'll make sure to do a better job next time!







code-golf roman-numerals






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 11 at 0:15

























asked Aug 10 at 15:03









Rushabh Mehta

609120




609120











  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 11 at 0:20
















  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 11 at 0:20















Comments are not for extended discussion; this conversation has been moved to chat.
– Mego♦
Aug 11 at 0:20




Comments are not for extended discussion; this conversation has been moved to chat.
– Mego♦
Aug 11 at 0:20










4 Answers
4






active

oldest

votes

















up vote
3
down vote



accepted











Retina, 111 bytes



~(`.+
*$(CM)CDXCXCXCXLIXIXIXIVII
.(.)
.+¶$$&$¶$$&$1$¶$$&$&¶L`.0,$+b¶D`¶
¶$
¶.+¶$$&$¶$$&I¶L`[A-Z]$+b¶D`¶.+


Try it online! This is a complete rewrite as I misunderstood rule 1. to mean that you could only use one each of subtractive I, X and C. Explanation: The first part of the script expands the input into a string of CM pairs followed by the other possible subtractive pairs. Each pair is optional, and the first character of each pair is also optional within the pair. The third stage then expands the list of pairs into a list of Retina commands that take the input and create three copies with the option of the second or both characters from the pair, then trims and deduplicates the results. The final stage then appends code to perform the final tasks: first to expand the input to possibly add a final I, then to filter out results of the wrong length, then to deduplicate the results, and finally to count the results. The resulting Retina script is then evaluated.



Note: In theory 15 bytes could be saved from the end of the 4th line but this makes the script too slow to demonstrate on TIO even for n=1.






share|improve this answer






















  • @JonathanAllan Ah, then you're including multiple subtractive pairs with the same leading numeral, which is wrong.
    – Neil
    Aug 10 at 23:27






  • 2




    @JonathanAllan New rewrite, coincidentally for the exact same byte count!
    – Neil
    Aug 11 at 15:24

















up vote
5
down vote














Python 2, 177 168 162 bytes





import re,itertools as q
f=lambda n:sum(None!=re.match("^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$",(''.join(m)))for m in q.product('MDCLXVI',repeat=n))


Try it online!



I'm pretty new, help me golf this! This checks for actual roman numerals, the regex needs to be adjusted to account for the odd cases such as IVI



-9 bytes thanks to @Dead Possum!



-6 bytes thanks to @ovs






share|improve this answer






















  • Yeah I think the n=3 case might be wrong in the example. I was originally getting 93 with ^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$
    – Easton Bornemeier
    Aug 10 at 16:54











  • 171 bytes
    – Dead Possum
    Aug 10 at 16:55






  • 1




    @JonathanAllan I spent around two days asking around on Math stackexchange trying to make sure these rules made sense. Guess I didn't do enough :(
    – Rushabh Mehta
    Aug 10 at 18:00






  • 1




    @RushabhMehta This is a very well formatted challenge and fun to program, don't feel bad about an unfortunate nuance in nitty-gritty of roman numeral definition. It is your challenge, specify it as you see fit. it is workable in the other sense, just more difficult
    – Easton Bornemeier
    Aug 10 at 18:31






  • 1




    This doesn't seem to give the right answer for 3. 93 instead of 105
    – Jo King
    Aug 11 at 2:53


















up vote
3
down vote













JavaScript (ES7), 133 bytes



Edit: Fixed to match the results returned by Jonathan Allan's code, which was given as a reference implementation by the OP.




n=>[...Array(m=k=7**n)].reduce(s=>s+/^1*5?40,33?20,36?00,3$/.test((--k+m).toString(7).replace(/0[62]|2[34]|4[51]/g,s=>s[1])),0)


Try it online!



How?



1) We generate all numbers of $N$ digits in base 7 with an extra leading $1$:



[...Array(m = k = 7 ** n)].reduce(s => … (--k + m).toString(7) …, 0)


From now on, each digit will be interpreted as a Roman numeral symbol:



$$beginarray0longleftrightarrow textI, & 1longleftrightarrow textM, & 2longleftrightarrow textX, & 3longleftrightarrow textL,\
4longleftrightarrow textC, & 5longleftrightarrow textD, & 6longleftrightarrow textV
endarray$$



2) We replace all valid subtractive pairs of the form AB with B:



.replace(/0[62]|2[34]|4[51]/g, s => s[1])) // in the code
.replace(/I[VX]|X[LC]|C[DM]/g, s => s[1])) // with Roman symbols


Examples:




  • XLIXIV becomes LXV


  • XIIV becomes XIV, leaving a I that will make the next test fail


  • IC remains unchanged, which also leaves an invalid I in place

3) We check that the remaining symbols are in the correct order and do not appear more times than they're allowed to:



/^1*5?40,33?20,36?00,3$/.test(…) // in the code
/^M*D?C0,3L?X0,3V?I0,3$/.test(…) // with Roman symbols





share|improve this answer






















  • Holy cow, I didn't expect this one to be done in less than 200 bytes in non esoteric languages! Mind explaining how this works?
    – Rushabh Mehta
    Aug 10 at 15:53










  • However, I have noticed that this doesn't work for *n*>4 on TIO, which is somewhat unfortunate.
    – Rushabh Mehta
    Aug 10 at 15:57










  • @RushabhMehta I've added a non-recursive version to test higher values. I'll add an explanation when I'm done golfing this.
    – Arnauld
    Aug 10 at 16:07

















up vote
0
down vote













C, 150 123 bytes



I didn't read the description closely enough, so this produces the number of standard Roman numerals (where expressions like IVI aren't counted). Since I put some effort into it, I thought I would share anyway.



#define F(X) for(X=10;X--;)
x=0,1,2,3,2,1,2,3,4,2;f(i,o,a,b,c)for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];return o;


Original (150 bytes):



#define F(X) for(X=10;X--;)
i,o,a,b,c,x=0,1,2,3,2,1,2,3,4,2;main()scanf("%i",&i);for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];printf("%in",o);





share|improve this answer


















  • 1




    You're only allowed to post valid submissions.
    – Okx
    Aug 12 at 8:45










  • @CurtisBechtel You can keep the solution here I suppose, but I would try to modify it to satisfy the rules of the challenge.
    – Rushabh Mehta
    Aug 12 at 13:11






  • 1




    I think you can remove the space between F(X) and for(X=10;X--;)
    – Zacharý
    Aug 12 at 17:10











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f170437%2fwhen-in-rome-count-as-romans-do%23new-answer', 'question_page');

);

Post as a guest






























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted











Retina, 111 bytes



~(`.+
*$(CM)CDXCXCXCXLIXIXIXIVII
.(.)
.+¶$$&$¶$$&$1$¶$$&$&¶L`.0,$+b¶D`¶
¶$
¶.+¶$$&$¶$$&I¶L`[A-Z]$+b¶D`¶.+


Try it online! This is a complete rewrite as I misunderstood rule 1. to mean that you could only use one each of subtractive I, X and C. Explanation: The first part of the script expands the input into a string of CM pairs followed by the other possible subtractive pairs. Each pair is optional, and the first character of each pair is also optional within the pair. The third stage then expands the list of pairs into a list of Retina commands that take the input and create three copies with the option of the second or both characters from the pair, then trims and deduplicates the results. The final stage then appends code to perform the final tasks: first to expand the input to possibly add a final I, then to filter out results of the wrong length, then to deduplicate the results, and finally to count the results. The resulting Retina script is then evaluated.



Note: In theory 15 bytes could be saved from the end of the 4th line but this makes the script too slow to demonstrate on TIO even for n=1.






share|improve this answer






















  • @JonathanAllan Ah, then you're including multiple subtractive pairs with the same leading numeral, which is wrong.
    – Neil
    Aug 10 at 23:27






  • 2




    @JonathanAllan New rewrite, coincidentally for the exact same byte count!
    – Neil
    Aug 11 at 15:24














up vote
3
down vote



accepted











Retina, 111 bytes



~(`.+
*$(CM)CDXCXCXCXLIXIXIXIVII
.(.)
.+¶$$&$¶$$&$1$¶$$&$&¶L`.0,$+b¶D`¶
¶$
¶.+¶$$&$¶$$&I¶L`[A-Z]$+b¶D`¶.+


Try it online! This is a complete rewrite as I misunderstood rule 1. to mean that you could only use one each of subtractive I, X and C. Explanation: The first part of the script expands the input into a string of CM pairs followed by the other possible subtractive pairs. Each pair is optional, and the first character of each pair is also optional within the pair. The third stage then expands the list of pairs into a list of Retina commands that take the input and create three copies with the option of the second or both characters from the pair, then trims and deduplicates the results. The final stage then appends code to perform the final tasks: first to expand the input to possibly add a final I, then to filter out results of the wrong length, then to deduplicate the results, and finally to count the results. The resulting Retina script is then evaluated.



Note: In theory 15 bytes could be saved from the end of the 4th line but this makes the script too slow to demonstrate on TIO even for n=1.






share|improve this answer






















  • @JonathanAllan Ah, then you're including multiple subtractive pairs with the same leading numeral, which is wrong.
    – Neil
    Aug 10 at 23:27






  • 2




    @JonathanAllan New rewrite, coincidentally for the exact same byte count!
    – Neil
    Aug 11 at 15:24












up vote
3
down vote



accepted







up vote
3
down vote



accepted







Retina, 111 bytes



~(`.+
*$(CM)CDXCXCXCXLIXIXIXIVII
.(.)
.+¶$$&$¶$$&$1$¶$$&$&¶L`.0,$+b¶D`¶
¶$
¶.+¶$$&$¶$$&I¶L`[A-Z]$+b¶D`¶.+


Try it online! This is a complete rewrite as I misunderstood rule 1. to mean that you could only use one each of subtractive I, X and C. Explanation: The first part of the script expands the input into a string of CM pairs followed by the other possible subtractive pairs. Each pair is optional, and the first character of each pair is also optional within the pair. The third stage then expands the list of pairs into a list of Retina commands that take the input and create three copies with the option of the second or both characters from the pair, then trims and deduplicates the results. The final stage then appends code to perform the final tasks: first to expand the input to possibly add a final I, then to filter out results of the wrong length, then to deduplicate the results, and finally to count the results. The resulting Retina script is then evaluated.



Note: In theory 15 bytes could be saved from the end of the 4th line but this makes the script too slow to demonstrate on TIO even for n=1.






share|improve this answer















Retina, 111 bytes



~(`.+
*$(CM)CDXCXCXCXLIXIXIXIVII
.(.)
.+¶$$&$¶$$&$1$¶$$&$&¶L`.0,$+b¶D`¶
¶$
¶.+¶$$&$¶$$&I¶L`[A-Z]$+b¶D`¶.+


Try it online! This is a complete rewrite as I misunderstood rule 1. to mean that you could only use one each of subtractive I, X and C. Explanation: The first part of the script expands the input into a string of CM pairs followed by the other possible subtractive pairs. Each pair is optional, and the first character of each pair is also optional within the pair. The third stage then expands the list of pairs into a list of Retina commands that take the input and create three copies with the option of the second or both characters from the pair, then trims and deduplicates the results. The final stage then appends code to perform the final tasks: first to expand the input to possibly add a final I, then to filter out results of the wrong length, then to deduplicate the results, and finally to count the results. The resulting Retina script is then evaluated.



Note: In theory 15 bytes could be saved from the end of the 4th line but this makes the script too slow to demonstrate on TIO even for n=1.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 11 at 15:23

























answered Aug 10 at 20:26









Neil

75.2k744170




75.2k744170











  • @JonathanAllan Ah, then you're including multiple subtractive pairs with the same leading numeral, which is wrong.
    – Neil
    Aug 10 at 23:27






  • 2




    @JonathanAllan New rewrite, coincidentally for the exact same byte count!
    – Neil
    Aug 11 at 15:24
















  • @JonathanAllan Ah, then you're including multiple subtractive pairs with the same leading numeral, which is wrong.
    – Neil
    Aug 10 at 23:27






  • 2




    @JonathanAllan New rewrite, coincidentally for the exact same byte count!
    – Neil
    Aug 11 at 15:24















@JonathanAllan Ah, then you're including multiple subtractive pairs with the same leading numeral, which is wrong.
– Neil
Aug 10 at 23:27




@JonathanAllan Ah, then you're including multiple subtractive pairs with the same leading numeral, which is wrong.
– Neil
Aug 10 at 23:27




2




2




@JonathanAllan New rewrite, coincidentally for the exact same byte count!
– Neil
Aug 11 at 15:24




@JonathanAllan New rewrite, coincidentally for the exact same byte count!
– Neil
Aug 11 at 15:24










up vote
5
down vote














Python 2, 177 168 162 bytes





import re,itertools as q
f=lambda n:sum(None!=re.match("^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$",(''.join(m)))for m in q.product('MDCLXVI',repeat=n))


Try it online!



I'm pretty new, help me golf this! This checks for actual roman numerals, the regex needs to be adjusted to account for the odd cases such as IVI



-9 bytes thanks to @Dead Possum!



-6 bytes thanks to @ovs






share|improve this answer






















  • Yeah I think the n=3 case might be wrong in the example. I was originally getting 93 with ^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$
    – Easton Bornemeier
    Aug 10 at 16:54











  • 171 bytes
    – Dead Possum
    Aug 10 at 16:55






  • 1




    @JonathanAllan I spent around two days asking around on Math stackexchange trying to make sure these rules made sense. Guess I didn't do enough :(
    – Rushabh Mehta
    Aug 10 at 18:00






  • 1




    @RushabhMehta This is a very well formatted challenge and fun to program, don't feel bad about an unfortunate nuance in nitty-gritty of roman numeral definition. It is your challenge, specify it as you see fit. it is workable in the other sense, just more difficult
    – Easton Bornemeier
    Aug 10 at 18:31






  • 1




    This doesn't seem to give the right answer for 3. 93 instead of 105
    – Jo King
    Aug 11 at 2:53















up vote
5
down vote














Python 2, 177 168 162 bytes





import re,itertools as q
f=lambda n:sum(None!=re.match("^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$",(''.join(m)))for m in q.product('MDCLXVI',repeat=n))


Try it online!



I'm pretty new, help me golf this! This checks for actual roman numerals, the regex needs to be adjusted to account for the odd cases such as IVI



-9 bytes thanks to @Dead Possum!



-6 bytes thanks to @ovs






share|improve this answer






















  • Yeah I think the n=3 case might be wrong in the example. I was originally getting 93 with ^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$
    – Easton Bornemeier
    Aug 10 at 16:54











  • 171 bytes
    – Dead Possum
    Aug 10 at 16:55






  • 1




    @JonathanAllan I spent around two days asking around on Math stackexchange trying to make sure these rules made sense. Guess I didn't do enough :(
    – Rushabh Mehta
    Aug 10 at 18:00






  • 1




    @RushabhMehta This is a very well formatted challenge and fun to program, don't feel bad about an unfortunate nuance in nitty-gritty of roman numeral definition. It is your challenge, specify it as you see fit. it is workable in the other sense, just more difficult
    – Easton Bornemeier
    Aug 10 at 18:31






  • 1




    This doesn't seem to give the right answer for 3. 93 instead of 105
    – Jo King
    Aug 11 at 2:53













up vote
5
down vote










up vote
5
down vote










Python 2, 177 168 162 bytes





import re,itertools as q
f=lambda n:sum(None!=re.match("^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$",(''.join(m)))for m in q.product('MDCLXVI',repeat=n))


Try it online!



I'm pretty new, help me golf this! This checks for actual roman numerals, the regex needs to be adjusted to account for the odd cases such as IVI



-9 bytes thanks to @Dead Possum!



-6 bytes thanks to @ovs






share|improve this answer















Python 2, 177 168 162 bytes





import re,itertools as q
f=lambda n:sum(None!=re.match("^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$",(''.join(m)))for m in q.product('MDCLXVI',repeat=n))


Try it online!



I'm pretty new, help me golf this! This checks for actual roman numerals, the regex needs to be adjusted to account for the odd cases such as IVI



-9 bytes thanks to @Dead Possum!



-6 bytes thanks to @ovs







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 10 at 17:44

























answered Aug 10 at 16:36









Easton Bornemeier

29116




29116











  • Yeah I think the n=3 case might be wrong in the example. I was originally getting 93 with ^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$
    – Easton Bornemeier
    Aug 10 at 16:54











  • 171 bytes
    – Dead Possum
    Aug 10 at 16:55






  • 1




    @JonathanAllan I spent around two days asking around on Math stackexchange trying to make sure these rules made sense. Guess I didn't do enough :(
    – Rushabh Mehta
    Aug 10 at 18:00






  • 1




    @RushabhMehta This is a very well formatted challenge and fun to program, don't feel bad about an unfortunate nuance in nitty-gritty of roman numeral definition. It is your challenge, specify it as you see fit. it is workable in the other sense, just more difficult
    – Easton Bornemeier
    Aug 10 at 18:31






  • 1




    This doesn't seem to give the right answer for 3. 93 instead of 105
    – Jo King
    Aug 11 at 2:53

















  • Yeah I think the n=3 case might be wrong in the example. I was originally getting 93 with ^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$
    – Easton Bornemeier
    Aug 10 at 16:54











  • 171 bytes
    – Dead Possum
    Aug 10 at 16:55






  • 1




    @JonathanAllan I spent around two days asking around on Math stackexchange trying to make sure these rules made sense. Guess I didn't do enough :(
    – Rushabh Mehta
    Aug 10 at 18:00






  • 1




    @RushabhMehta This is a very well formatted challenge and fun to program, don't feel bad about an unfortunate nuance in nitty-gritty of roman numeral definition. It is your challenge, specify it as you see fit. it is workable in the other sense, just more difficult
    – Easton Bornemeier
    Aug 10 at 18:31






  • 1




    This doesn't seem to give the right answer for 3. 93 instead of 105
    – Jo King
    Aug 11 at 2:53
















Yeah I think the n=3 case might be wrong in the example. I was originally getting 93 with ^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$
– Easton Bornemeier
Aug 10 at 16:54





Yeah I think the n=3 case might be wrong in the example. I was originally getting 93 with ^M*(CM|CD|D?C0,3)(XC|XL|L?X0,3)(IX|IV|V?I0,3)$
– Easton Bornemeier
Aug 10 at 16:54













171 bytes
– Dead Possum
Aug 10 at 16:55




171 bytes
– Dead Possum
Aug 10 at 16:55




1




1




@JonathanAllan I spent around two days asking around on Math stackexchange trying to make sure these rules made sense. Guess I didn't do enough :(
– Rushabh Mehta
Aug 10 at 18:00




@JonathanAllan I spent around two days asking around on Math stackexchange trying to make sure these rules made sense. Guess I didn't do enough :(
– Rushabh Mehta
Aug 10 at 18:00




1




1




@RushabhMehta This is a very well formatted challenge and fun to program, don't feel bad about an unfortunate nuance in nitty-gritty of roman numeral definition. It is your challenge, specify it as you see fit. it is workable in the other sense, just more difficult
– Easton Bornemeier
Aug 10 at 18:31




@RushabhMehta This is a very well formatted challenge and fun to program, don't feel bad about an unfortunate nuance in nitty-gritty of roman numeral definition. It is your challenge, specify it as you see fit. it is workable in the other sense, just more difficult
– Easton Bornemeier
Aug 10 at 18:31




1




1




This doesn't seem to give the right answer for 3. 93 instead of 105
– Jo King
Aug 11 at 2:53





This doesn't seem to give the right answer for 3. 93 instead of 105
– Jo King
Aug 11 at 2:53











up vote
3
down vote













JavaScript (ES7), 133 bytes



Edit: Fixed to match the results returned by Jonathan Allan's code, which was given as a reference implementation by the OP.




n=>[...Array(m=k=7**n)].reduce(s=>s+/^1*5?40,33?20,36?00,3$/.test((--k+m).toString(7).replace(/0[62]|2[34]|4[51]/g,s=>s[1])),0)


Try it online!



How?



1) We generate all numbers of $N$ digits in base 7 with an extra leading $1$:



[...Array(m = k = 7 ** n)].reduce(s => … (--k + m).toString(7) …, 0)


From now on, each digit will be interpreted as a Roman numeral symbol:



$$beginarray0longleftrightarrow textI, & 1longleftrightarrow textM, & 2longleftrightarrow textX, & 3longleftrightarrow textL,\
4longleftrightarrow textC, & 5longleftrightarrow textD, & 6longleftrightarrow textV
endarray$$



2) We replace all valid subtractive pairs of the form AB with B:



.replace(/0[62]|2[34]|4[51]/g, s => s[1])) // in the code
.replace(/I[VX]|X[LC]|C[DM]/g, s => s[1])) // with Roman symbols


Examples:




  • XLIXIV becomes LXV


  • XIIV becomes XIV, leaving a I that will make the next test fail


  • IC remains unchanged, which also leaves an invalid I in place

3) We check that the remaining symbols are in the correct order and do not appear more times than they're allowed to:



/^1*5?40,33?20,36?00,3$/.test(…) // in the code
/^M*D?C0,3L?X0,3V?I0,3$/.test(…) // with Roman symbols





share|improve this answer






















  • Holy cow, I didn't expect this one to be done in less than 200 bytes in non esoteric languages! Mind explaining how this works?
    – Rushabh Mehta
    Aug 10 at 15:53










  • However, I have noticed that this doesn't work for *n*>4 on TIO, which is somewhat unfortunate.
    – Rushabh Mehta
    Aug 10 at 15:57










  • @RushabhMehta I've added a non-recursive version to test higher values. I'll add an explanation when I'm done golfing this.
    – Arnauld
    Aug 10 at 16:07














up vote
3
down vote













JavaScript (ES7), 133 bytes



Edit: Fixed to match the results returned by Jonathan Allan's code, which was given as a reference implementation by the OP.




n=>[...Array(m=k=7**n)].reduce(s=>s+/^1*5?40,33?20,36?00,3$/.test((--k+m).toString(7).replace(/0[62]|2[34]|4[51]/g,s=>s[1])),0)


Try it online!



How?



1) We generate all numbers of $N$ digits in base 7 with an extra leading $1$:



[...Array(m = k = 7 ** n)].reduce(s => … (--k + m).toString(7) …, 0)


From now on, each digit will be interpreted as a Roman numeral symbol:



$$beginarray0longleftrightarrow textI, & 1longleftrightarrow textM, & 2longleftrightarrow textX, & 3longleftrightarrow textL,\
4longleftrightarrow textC, & 5longleftrightarrow textD, & 6longleftrightarrow textV
endarray$$



2) We replace all valid subtractive pairs of the form AB with B:



.replace(/0[62]|2[34]|4[51]/g, s => s[1])) // in the code
.replace(/I[VX]|X[LC]|C[DM]/g, s => s[1])) // with Roman symbols


Examples:




  • XLIXIV becomes LXV


  • XIIV becomes XIV, leaving a I that will make the next test fail


  • IC remains unchanged, which also leaves an invalid I in place

3) We check that the remaining symbols are in the correct order and do not appear more times than they're allowed to:



/^1*5?40,33?20,36?00,3$/.test(…) // in the code
/^M*D?C0,3L?X0,3V?I0,3$/.test(…) // with Roman symbols





share|improve this answer






















  • Holy cow, I didn't expect this one to be done in less than 200 bytes in non esoteric languages! Mind explaining how this works?
    – Rushabh Mehta
    Aug 10 at 15:53










  • However, I have noticed that this doesn't work for *n*>4 on TIO, which is somewhat unfortunate.
    – Rushabh Mehta
    Aug 10 at 15:57










  • @RushabhMehta I've added a non-recursive version to test higher values. I'll add an explanation when I'm done golfing this.
    – Arnauld
    Aug 10 at 16:07












up vote
3
down vote










up vote
3
down vote









JavaScript (ES7), 133 bytes



Edit: Fixed to match the results returned by Jonathan Allan's code, which was given as a reference implementation by the OP.




n=>[...Array(m=k=7**n)].reduce(s=>s+/^1*5?40,33?20,36?00,3$/.test((--k+m).toString(7).replace(/0[62]|2[34]|4[51]/g,s=>s[1])),0)


Try it online!



How?



1) We generate all numbers of $N$ digits in base 7 with an extra leading $1$:



[...Array(m = k = 7 ** n)].reduce(s => … (--k + m).toString(7) …, 0)


From now on, each digit will be interpreted as a Roman numeral symbol:



$$beginarray0longleftrightarrow textI, & 1longleftrightarrow textM, & 2longleftrightarrow textX, & 3longleftrightarrow textL,\
4longleftrightarrow textC, & 5longleftrightarrow textD, & 6longleftrightarrow textV
endarray$$



2) We replace all valid subtractive pairs of the form AB with B:



.replace(/0[62]|2[34]|4[51]/g, s => s[1])) // in the code
.replace(/I[VX]|X[LC]|C[DM]/g, s => s[1])) // with Roman symbols


Examples:




  • XLIXIV becomes LXV


  • XIIV becomes XIV, leaving a I that will make the next test fail


  • IC remains unchanged, which also leaves an invalid I in place

3) We check that the remaining symbols are in the correct order and do not appear more times than they're allowed to:



/^1*5?40,33?20,36?00,3$/.test(…) // in the code
/^M*D?C0,3L?X0,3V?I0,3$/.test(…) // with Roman symbols





share|improve this answer














JavaScript (ES7), 133 bytes



Edit: Fixed to match the results returned by Jonathan Allan's code, which was given as a reference implementation by the OP.




n=>[...Array(m=k=7**n)].reduce(s=>s+/^1*5?40,33?20,36?00,3$/.test((--k+m).toString(7).replace(/0[62]|2[34]|4[51]/g,s=>s[1])),0)


Try it online!



How?



1) We generate all numbers of $N$ digits in base 7 with an extra leading $1$:



[...Array(m = k = 7 ** n)].reduce(s => … (--k + m).toString(7) …, 0)


From now on, each digit will be interpreted as a Roman numeral symbol:



$$beginarray0longleftrightarrow textI, & 1longleftrightarrow textM, & 2longleftrightarrow textX, & 3longleftrightarrow textL,\
4longleftrightarrow textC, & 5longleftrightarrow textD, & 6longleftrightarrow textV
endarray$$



2) We replace all valid subtractive pairs of the form AB with B:



.replace(/0[62]|2[34]|4[51]/g, s => s[1])) // in the code
.replace(/I[VX]|X[LC]|C[DM]/g, s => s[1])) // with Roman symbols


Examples:




  • XLIXIV becomes LXV


  • XIIV becomes XIV, leaving a I that will make the next test fail


  • IC remains unchanged, which also leaves an invalid I in place

3) We check that the remaining symbols are in the correct order and do not appear more times than they're allowed to:



/^1*5?40,33?20,36?00,3$/.test(…) // in the code
/^M*D?C0,3L?X0,3V?I0,3$/.test(…) // with Roman symbols






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 12 at 15:55

























answered Aug 10 at 15:51









Arnauld

64.2k580270




64.2k580270











  • Holy cow, I didn't expect this one to be done in less than 200 bytes in non esoteric languages! Mind explaining how this works?
    – Rushabh Mehta
    Aug 10 at 15:53










  • However, I have noticed that this doesn't work for *n*>4 on TIO, which is somewhat unfortunate.
    – Rushabh Mehta
    Aug 10 at 15:57










  • @RushabhMehta I've added a non-recursive version to test higher values. I'll add an explanation when I'm done golfing this.
    – Arnauld
    Aug 10 at 16:07
















  • Holy cow, I didn't expect this one to be done in less than 200 bytes in non esoteric languages! Mind explaining how this works?
    – Rushabh Mehta
    Aug 10 at 15:53










  • However, I have noticed that this doesn't work for *n*>4 on TIO, which is somewhat unfortunate.
    – Rushabh Mehta
    Aug 10 at 15:57










  • @RushabhMehta I've added a non-recursive version to test higher values. I'll add an explanation when I'm done golfing this.
    – Arnauld
    Aug 10 at 16:07















Holy cow, I didn't expect this one to be done in less than 200 bytes in non esoteric languages! Mind explaining how this works?
– Rushabh Mehta
Aug 10 at 15:53




Holy cow, I didn't expect this one to be done in less than 200 bytes in non esoteric languages! Mind explaining how this works?
– Rushabh Mehta
Aug 10 at 15:53












However, I have noticed that this doesn't work for *n*>4 on TIO, which is somewhat unfortunate.
– Rushabh Mehta
Aug 10 at 15:57




However, I have noticed that this doesn't work for *n*>4 on TIO, which is somewhat unfortunate.
– Rushabh Mehta
Aug 10 at 15:57












@RushabhMehta I've added a non-recursive version to test higher values. I'll add an explanation when I'm done golfing this.
– Arnauld
Aug 10 at 16:07




@RushabhMehta I've added a non-recursive version to test higher values. I'll add an explanation when I'm done golfing this.
– Arnauld
Aug 10 at 16:07










up vote
0
down vote













C, 150 123 bytes



I didn't read the description closely enough, so this produces the number of standard Roman numerals (where expressions like IVI aren't counted). Since I put some effort into it, I thought I would share anyway.



#define F(X) for(X=10;X--;)
x=0,1,2,3,2,1,2,3,4,2;f(i,o,a,b,c)for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];return o;


Original (150 bytes):



#define F(X) for(X=10;X--;)
i,o,a,b,c,x=0,1,2,3,2,1,2,3,4,2;main()scanf("%i",&i);for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];printf("%in",o);





share|improve this answer


















  • 1




    You're only allowed to post valid submissions.
    – Okx
    Aug 12 at 8:45










  • @CurtisBechtel You can keep the solution here I suppose, but I would try to modify it to satisfy the rules of the challenge.
    – Rushabh Mehta
    Aug 12 at 13:11






  • 1




    I think you can remove the space between F(X) and for(X=10;X--;)
    – Zacharý
    Aug 12 at 17:10















up vote
0
down vote













C, 150 123 bytes



I didn't read the description closely enough, so this produces the number of standard Roman numerals (where expressions like IVI aren't counted). Since I put some effort into it, I thought I would share anyway.



#define F(X) for(X=10;X--;)
x=0,1,2,3,2,1,2,3,4,2;f(i,o,a,b,c)for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];return o;


Original (150 bytes):



#define F(X) for(X=10;X--;)
i,o,a,b,c,x=0,1,2,3,2,1,2,3,4,2;main()scanf("%i",&i);for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];printf("%in",o);





share|improve this answer


















  • 1




    You're only allowed to post valid submissions.
    – Okx
    Aug 12 at 8:45










  • @CurtisBechtel You can keep the solution here I suppose, but I would try to modify it to satisfy the rules of the challenge.
    – Rushabh Mehta
    Aug 12 at 13:11






  • 1




    I think you can remove the space between F(X) and for(X=10;X--;)
    – Zacharý
    Aug 12 at 17:10













up vote
0
down vote










up vote
0
down vote









C, 150 123 bytes



I didn't read the description closely enough, so this produces the number of standard Roman numerals (where expressions like IVI aren't counted). Since I put some effort into it, I thought I would share anyway.



#define F(X) for(X=10;X--;)
x=0,1,2,3,2,1,2,3,4,2;f(i,o,a,b,c)for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];return o;


Original (150 bytes):



#define F(X) for(X=10;X--;)
i,o,a,b,c,x=0,1,2,3,2,1,2,3,4,2;main()scanf("%i",&i);for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];printf("%in",o);





share|improve this answer














C, 150 123 bytes



I didn't read the description closely enough, so this produces the number of standard Roman numerals (where expressions like IVI aren't counted). Since I put some effort into it, I thought I would share anyway.



#define F(X) for(X=10;X--;)
x=0,1,2,3,2,1,2,3,4,2;f(i,o,a,b,c)for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];return o;


Original (150 bytes):



#define F(X) for(X=10;X--;)
i,o,a,b,c,x=0,1,2,3,2,1,2,3,4,2;main()scanf("%i",&i);for(i++;i--;)F(a)F(b)F(c)o+=i==x[a]+x[b]+x[c];printf("%in",o);






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 12 at 7:13

























answered Aug 12 at 6:20









Curtis Bechtel

33618




33618







  • 1




    You're only allowed to post valid submissions.
    – Okx
    Aug 12 at 8:45










  • @CurtisBechtel You can keep the solution here I suppose, but I would try to modify it to satisfy the rules of the challenge.
    – Rushabh Mehta
    Aug 12 at 13:11






  • 1




    I think you can remove the space between F(X) and for(X=10;X--;)
    – Zacharý
    Aug 12 at 17:10













  • 1




    You're only allowed to post valid submissions.
    – Okx
    Aug 12 at 8:45










  • @CurtisBechtel You can keep the solution here I suppose, but I would try to modify it to satisfy the rules of the challenge.
    – Rushabh Mehta
    Aug 12 at 13:11






  • 1




    I think you can remove the space between F(X) and for(X=10;X--;)
    – Zacharý
    Aug 12 at 17:10








1




1




You're only allowed to post valid submissions.
– Okx
Aug 12 at 8:45




You're only allowed to post valid submissions.
– Okx
Aug 12 at 8:45












@CurtisBechtel You can keep the solution here I suppose, but I would try to modify it to satisfy the rules of the challenge.
– Rushabh Mehta
Aug 12 at 13:11




@CurtisBechtel You can keep the solution here I suppose, but I would try to modify it to satisfy the rules of the challenge.
– Rushabh Mehta
Aug 12 at 13:11




1




1




I think you can remove the space between F(X) and for(X=10;X--;)
– Zacharý
Aug 12 at 17:10





I think you can remove the space between F(X) and for(X=10;X--;)
– Zacharý
Aug 12 at 17:10


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f170437%2fwhen-in-rome-count-as-romans-do%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay