cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

23-Emerald I

Rosetta Code - Compare a list of strings

I've added the following solution to the Rosetta Code task: Compare a list of strings

``````Given a list of arbitrarily many strings, show how to:
•	test if they are all lexically equal
•	test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order)
Each of those two tests should result in a single true or false value, which could be used as the condition of an if statement or similar.

If the input list has less than two elements, the tests should always return true.``````

As always, please feel free to improve upon and submit your own solution to this and the other Rosetta Stone tasks.

Stuart

8 REPLIES 8
23-Emerald IV
(To:StuartBruff)

Nice done, Stuart!

23-Emerald I

Nice done, Stuart!

Спасиво, Владимир.

(Как вы говорите «no worries» в разговорном русском языке?? «не беспокойтесь»? «Без пробле́м»? «не надо»? «не вопро́с»?)

23-Emerald IV
(To:StuartBruff)

"Нет проблем".

23-Emerald I

"Нет проблем".

Ещё раз спасибо, Владимир!

23-Emerald I
(To:StuartBruff)

I suppose you realise that, when ORIGIN is set to another value than 0, by accident or purposely, many of these functions will fail.

Luc

23-Emerald I
(To:LucMeekes)

@LucMeekes wrote:

I suppose you realise that, when ORIGIN is set to another value than 0, by accident or purposely, many of these functions will fail.

Luc

Yes, but I'm writing for those who will use/encounter vanilla Mathcad "out of the box" (like me! 😁).

I have a worksheet full of ORIGIN-independent functions, but I often find that, for illustrative purposes at least, the additional "ORIGIN"s tend to obscure the working of a function(*).  They also take up more of the very limited horizontal space than I like, even if I use "O" as a shorthand notation for "ORIGIN".  If I do use a base other than 0, I  tend to write functions specifically for that origin.  Besides, it's easy enough to "escape" the functions in an ORIGIN wrapper ... I think I did that in one example in the recent TDMA thread  ... yep, I did:

And, of course, there's no reason why some kind-hearted soul could not improve upon the current Rosetta Code Mathcad entries, or add a programmed version in M11/M15/Prime n ... 😈

Stuart

(*) To be more precise, I have a core set of functions that are ORIGIN-independent, which I then use to define other functions (eg, I use "head(v) in place of v{ORIGIN}, as in the string comparison excerpt above).

I could do the same with strings (eg, replace the 0 in strhead). but I'd have to know that the Calculation option was set and I don't know how to do that in Express (I suppose a try-catch would work in Prime).

23-Emerald I
(To:StuartBruff)

That should be easy, even in Express.

With the Calculation Option "ORIGIN in strings" not set (the default), you get:

With the Calculation option set, you get:

So you can replace the    0     as index of the first element

with       search("_0","0",ORIGIN)-1

Success!
Luc

Incidentally: I suppose you know about HAL 9000 and whether or not it was in any way "IBM compatible"...

23-Emerald I
(To:LucMeekes)

@LucMeekes wrote:

That should be easy, even in Express.

Neat, Luc.  And, yes, it works nicely in Express 7, as you surmised ...

... with a caveat.  Unless, I've made a typo (highly likely),  the method only works if ORIGIN = 0 or 1 when the string ORIGIN option isn't ticked.

I vaguely recall seeing a few worksheets that use oddball origins for specific purposes, including negative ORIGINS.  In fact, I dragged my ORIGIN-independent functions from one by @ValeryOchkov that I'd tried to Expressify: https://community.ptc.com/t5/PTC-Mathcad/Study-16/m-p/642393

I think the following might work for any ORIGIN but, again, I might be making some mistake ...

I can't think of a neat way to functionalize it in Express 7, as search has to be within the scope of the associated ORIGIN.

Incidentally: I suppose you know about HAL 9000 and whether or not it was in any way "IBM compatible"...

Who me?  No, I was getting ready for Buzz to fizz off into space at the time the film came out ...

Hmm, "HAL", "IBM", ... 🤔

Nope, can't think of a thing ... 🙂

(I started out writing a simple, and I mean simple, FizzBuzz implementation in Express and kind of got carried away.   I'm too lazy to create new "buzzwords" for every "buzznumber" (prime) I added to (3,Fizz),(5,Buzz), so I ended up writing a little routine to extrapolate new words from a pair of seed words.  It's great for creating names for aliens)

Stuart

Announcements
Check out the latest