Skip to main content
deleted 9 characters in body
Source Link
Greg Martin
  • 16.7k
  • 4
  • 23
  • 73

Mathematica, 113 9090 83 bytes

Thanks to Martin Ender for two suggestions that reduced the length by over 20%25%!

Showing off the high-level commands in Mathematica.

Nest[Flatten@(Characters/@Nest[Flatten[Characters@{RomanNumeral@#,#2}&@@@(Reverse@#&@@@Tally&@@@Reverse@@@Tally/@Split@#))&@Split@#]&,{"I"},#]& 

A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence, as a list of characters. Spread out a bit:

Nest[ Flatten@Flatten[ (Characters/ @ {RomanNumeral@#,#2}& @@@   (Reverse@# &Reverse @@@ Tally /@ Split@#) Split@ #  ) &]& , {"I"}, #] &#]& 

The outer Nest iterates the middle four-line function, starting on {"I"}, N times. Line 4 splits the character list of the input Roman numeral into runs of like characters, counts each run with Tally, and puts the counts before the characters they're counting. Line 3 renders the counts as Roman numerals, then splits those Roman numerals up into lists of characters. The Flatten command reduces the whole list-of-lists to a one-dimensional list.

Here's the initial version:

Nest[ "" <> Flatten[{RomanNumeral@#[[1]], #[[2]]} & /@ (Reverse@#[[1]] & /@ Tally /@ Split@Characters@#)] &, "I", #] & 

Mathematica, 113 90 bytes

Thanks to Martin Ender for two suggestions that reduced the length by over 20%!

Showing off the high-level commands in Mathematica.

Nest[Flatten@(Characters/@{RomanNumeral@#,#2}&@@@(Reverse@#&@@@Tally/@Split@#))&,{"I"},#]& 

A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence, as a list of characters. Spread out a bit:

Nest[ Flatten@ (Characters/@ {RomanNumeral@#,#2}& @@@   (Reverse@# & @@@ Tally /@ Split@#)  ) & , {"I"}, #] & 

The outer Nest iterates the middle four-line function, starting on {"I"}, N times. Line 4 splits the character list of the input Roman numeral into runs of like characters, counts each run with Tally, and puts the counts before the characters they're counting. Line 3 renders the counts as Roman numerals, then splits those Roman numerals up into lists of characters. The Flatten command reduces the whole list-of-lists to a one-dimensional list.

Here's the initial version:

Nest[ "" <> Flatten[{RomanNumeral@#[[1]], #[[2]]} & /@ (Reverse@#[[1]] & /@ Tally /@ Split@Characters@#)] &, "I", #] & 

Mathematica, 113 90 83 bytes

Thanks to Martin Ender for suggestions that reduced the length by over 25%!

Showing off the high-level commands in Mathematica.

Nest[Flatten[Characters@{RomanNumeral@#,#2}&@@@Reverse@@@Tally/@Split@#]&,{"I"},#]& 

A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence, as a list of characters. Spread out a bit:

Nest[ Flatten[ Characters @ {RomanNumeral@#,#2}& @@@ Reverse @@@ Tally /@ Split@ #  ]& , {"I"}, #]& 

The outer Nest iterates the middle four-line function, starting on {"I"}, N times. Line 4 splits the character list of the input Roman numeral into runs of like characters, counts each run with Tally, and puts the counts before the characters they're counting. Line 3 renders the counts as Roman numerals, then splits those Roman numerals up into lists of characters. The Flatten command reduces the whole list-of-lists to a one-dimensional list.

Here's the initial version:

Nest[ "" <> Flatten[{RomanNumeral@#[[1]], #[[2]]} & /@ (Reverse@#[[1]] & /@ Tally /@ Split@Characters@#)] &, "I", #] & 
added 361 characters in body
Source Link
Greg Martin
  • 16.7k
  • 4
  • 23
  • 73

Mathematica, 113113 90 bytes

Didn't golf much—just showingThanks to Martin Ender for two suggestions that reduced the length by over 20%!

Showing off the high-level commands in Mathematica.

Nest[""<>Flatten[Nest[Flatten@(Characters/@{RomanNumeral[#1[[1]]]RomanNumeral@#,#1[[2]]#2}&)/@&@@@(Reverse[#1[[1]]]&)/@TallyReverse@#&@@@Tally/@Split[Characters[#1]]]&@Split@#))&,{"I"},#1]&#]& 

A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence, as a list of characters. Spread out a bit:

Nest[ "" <>Flatten@  Flatten[{RomanNumeral@#[[1]], #[[2]]} & (Characters/@  {RomanNumeral@#,#2}& (Reverse@#[[1]]@@@  & /@    (Reverse@# & @@@ Tally /@  Split@#)  Split@Characters@#)] & , {"I"}, #] & 

The outer Nest iterates the middle four-line function, starting on {"I"}, N times. Line 54 splits the characterscharacter list of the input Roman numeral into runs of like characters; Line 4characters, counts each run; Line 3run with Tally, and puts the counts before the letterscharacters they're counting. Line 23 renders the counts as Roman numerals, and then all thesplits those Roman numeral strings get concatenatednumerals up into lists of characters. The Flatten command reduces the whole list-of-lists to a one-dimensional list.

Here's the initial version:

Nest[ "" <> Flatten[{RomanNumeral@#[[1]], #[[2]]} & /@ (Reverse@#[[1]] & /@ Tally /@ Split@Characters@#)] &, "I", #] & 

Mathematica, 113 bytes

Didn't golf much—just showing off the high-level commands in Mathematica.

Nest[""<>Flatten[({RomanNumeral[#1[[1]]],#1[[2]]}&)/@(Reverse[#1[[1]]]&)/@Tally/@Split[Characters[#1]]]&,"I",#1]& 

A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence. Spread out a bit:

Nest[ "" <> Flatten[{RomanNumeral@#[[1]], #[[2]]} & /@  (Reverse@#[[1]] & /@    Tally /@  Split@Characters@#)] &, "I", #] & 

The outer Nest iterates the middle four-line function, starting on "I", N times. Line 5 splits the characters of the input Roman numeral into runs of like characters; Line 4 counts each run; Line 3 puts the counts before the letters they're counting. Line 2 renders the counts as Roman numerals, and then all the Roman numeral strings get concatenated.

Mathematica, 113 90 bytes

Thanks to Martin Ender for two suggestions that reduced the length by over 20%!

Showing off the high-level commands in Mathematica.

Nest[Flatten@(Characters/@{RomanNumeral@#,#2}&@@@(Reverse@#&@@@Tally/@Split@#))&,{"I"},#]& 

A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence, as a list of characters. Spread out a bit:

Nest[ Flatten@  (Characters/@ {RomanNumeral@#,#2}& @@@  (Reverse@# & @@@ Tally /@ Split@#)  ) & , {"I"}, #] & 

The outer Nest iterates the middle four-line function, starting on {"I"}, N times. Line 4 splits the character list of the input Roman numeral into runs of like characters, counts each run with Tally, and puts the counts before the characters they're counting. Line 3 renders the counts as Roman numerals, then splits those Roman numerals up into lists of characters. The Flatten command reduces the whole list-of-lists to a one-dimensional list.

Here's the initial version:

Nest[ "" <> Flatten[{RomanNumeral@#[[1]], #[[2]]} & /@ (Reverse@#[[1]] & /@ Tally /@ Split@Characters@#)] &, "I", #] & 
Source Link
Greg Martin
  • 16.7k
  • 4
  • 23
  • 73

Mathematica, 113 bytes

Didn't golf much—just showing off the high-level commands in Mathematica.

Nest[""<>Flatten[({RomanNumeral[#1[[1]]],#1[[2]]}&)/@(Reverse[#1[[1]]]&)/@Tally/@Split[Characters[#1]]]&,"I",#1]& 

A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence. Spread out a bit:

Nest[ "" <> Flatten[{RomanNumeral@#[[1]], #[[2]]} & /@ (Reverse@#[[1]] & /@ Tally /@ Split@Characters@#)] &, "I", #] & 

The outer Nest iterates the middle four-line function, starting on "I", N times. Line 5 splits the characters of the input Roman numeral into runs of like characters; Line 4 counts each run; Line 3 puts the counts before the letters they're counting. Line 2 renders the counts as Roman numerals, and then all the Roman numeral strings get concatenated.