Improving a certain code in draft version of A387014

29 views
Skip to first unread message

José Hdz. Stgo.

unread,
Aug 15, 2025, 4:21:39 PMAug 15
to seq...@googlegroups.com
Good afternoon, everyone!

Would any of you be so kind as to provide a more succinct Mathematica routine that provides the same output as the cumbersome code in this proposal of mine?

Some editors requested that I improve the above code a wee bit; unfortunately, I  am not that fluent in the Wolfram language yet... 

I suppose that providing a routine in another language could also come in handy.

Thank you very much for your attention and support!

Best regards,

J. H.

Tomas Rokicki

unread,
Aug 15, 2025, 4:25:50 PMAug 15
to seq...@googlegroups.com
That link does not work for me.  Perhaps you can just copy the Mathematica code as
text into the body of your email?

Thanks!

-tom

--
You received this message because you are subscribed to the Google Groups "SeqFan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seqfan+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/seqfan/CADduyk_4FyGv4S21o90dkuLYceT-F%3DE0ZuADRz8RchagCOhZKQ%40mail.gmail.com.


--

Sean A. Irvine

unread,
Aug 15, 2025, 4:26:17 PMAug 15
to seq...@googlegroups.com
I think José is referring to:




--

José Hdz. Stgo.

unread,
Aug 15, 2025, 4:33:24 PMAug 15
to seq...@googlegroups.com
Sean is right...

I don't know why it is that the link I added isn't working properly.

The Mathematica code in question is the following one:

For[n = 1, n <= 100, n++, l = {}; t = {};
For[k = 1, k <= 2*n - 1, k++, AppendTo[l, RomanNumeral[k]]];
t = LexicographicSort[l];
middleElement = t[[(Length[t] + 1)/2]];
Print[FromRomanNumeral[middleElement], ", "]]

Best regards,

José Hdz.

Misha Lavrov

unread,
Aug 15, 2025, 6:18:26 PMAug 15
to seq...@googlegroups.com
The following Mathematica code should be equivalent (and produced the same results when I ran it in Wolfram Cloud):

Table[FromRomanNumeral[Sort[RomanNumeral /@ Range[2n-1]][[n]]], {n, 1, 100}]

Best,
Misha

José Hdz. Stgo.

unread,
Aug 15, 2025, 6:58:23 PMAug 15
to seq...@googlegroups.com
That's it...

Thank you very much!

Cordially yours,

J. H.

Misha Lavrov

unread,
Aug 16, 2025, 8:59:32 AMAug 16
to seq...@googlegroups.com
Possibly even better is the following variant:

Table[SortBy[Range[2n-1], RomanNumeral][[n]], {n, 100}]

It's a bit shorter, and it's also easier to generalize to other similar sequences, because it doesn't require the inverse function FromRomanNumeral to exist. (The intermediate calculation SortBy[Range[2n-1], RomanNumeral] sorts the list {1, 2, ..., 2n-1} by their RomanNumeral values.)

Best,
Misha

Kevin Ryde

unread,
Aug 16, 2025, 10:24:06 PMAug 16
to seq...@googlegroups.com
Misha Lavrov <mish...@gmail.com> writes:
>
> Table[SortBy[Range[2n-1], RomanNumeral][[n]], {n, 100}]

When calculating terms one by one, an expression inside an
array-making is not good for re-use. Function a[n] = something
is far better. Can call it for any desired n and combinations.
(Less of an issue in this case since finite and limited.)

The converse would be that if say making terms by inserting
new two elements, then that would certainly be array-making.
That comes up in bigger or harder problems where there's not
much good way except for making a block of initial terms.
Reply all
Reply to author
Forward
0 new messages