Full Version: Sorting 2 variables: one ascending, one descending
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Yeah, I agree with your main points. Together we can solve very difficult problems Wink

*I always wear unpenetratable skintanium armor when I'm asleep*

Er... pancakes are delicous!
Meg and Neo,
I think Meg gets most of the credit for the (100-age) idea. That goes along with what I was hinting at. However, it's still not 100%. What if we were sorting some field other than age, and it was alphanumeric instead of numeric? Then the (100-x) would not work. So what else could we do with the keys to still do only one ascending sort pass?

An old Turkish saying:
"Let the crazy man take the snake out of the hole".

I'm not going to be the crazy man and try to figure out what you're doing since you modified all the rules and basically created a problem and solution all your own.

An old American saying:
"Let's all sing out of the same hymn book".
I suppose if the sorting column were alphanumeric, you would be better off "subtracting" it from a string of CHR$(255)'s. For each character "x" in the string, replace it with CHR$(255-ASC("x")) in the sortkey.


Moneo, Meg:

Whatever type of data you select or whatever size it is, there always is an upper bound to the data. Whether it's alphanumerical, or numerical, respectively the upperbounds are ascii 255 and 9. Using this, we can convert any type of data from it's ascending form to it's descending form, or vice-versa, depending on the situation.

About all the credit and such, I think Meg gets most credit for the 100 - Age formula because he posted a solution before I was going to post it... Wink The only difference between our programs (which I was going to post the same time until I saw Meg's program! Big Grin) was that I used 99 - Age instead of 100 - Age. Oh well.

Here's some code to convert a string to it's ascending/descending version:
[syntax="QBasic"]FUNCTION Convert$ (ThaString AS STRING)
retstr$ = ""
FOR I = 1 TO LEN(ThaString)
retstr$ = retstr$ + CHR$(ASC(MID$(ThaString, I, 1)) XOR 255)
Convert$ = retstr$

So basically, what you do when you want something mixed ascending/descending, is look at which field(s) are easiest converted, and convert them. Then you sort ascending/descending, then convert these fields back. It is also possible to calculate the conversions on-the-fly.
Also, if you want to sort on other fields first, you just recombine the string to make it possible without extra IFs. Suppose we first wanted ascending on age, then on name, we would use:
SortKey$ = Age$ + PersonName$
Oh well, I'm just more or less repeating what Meg already said (she was first again! :rollSmile. Wink
Goedei, Moneo!..

Good thing beautiful America is overseas. And, good thing that all the Europe -- from Celtic to Angles, from Balkan people to Anatolians -- is a grand mosaic, and we, every single individual, all have 'our own hymn books' to sing out and share.

Fear not, Moneo. Change is good.

A PS: This isn't a flame, but some points got me giggling...
  • - Where did you lift that so-called Turkish saying? Where was that cited? Then again, translation might be poor.
    - Why disregard modificators like they were topic-polluters? Hint: Risk of being a 'tinkerer' ruler...
    - Where would you put yourself? The eloquent or the flatulent contrarian?
Truly curious, and feel free to ignore this post. :wink:

I don't mean to be offensive, but I think you're missing the point of the challenges section. We had the same problem in the challenge I posted--you completely ignored the guidelines and limitations with your entry. Then, you write gigantic posts explaining why your solution is more appropriate for the "real world."

In my opinion, the limitations we put on these challenges are representative of ones you might actually have to deal with in the real world--a place which seldom, if ever, lets you utilize the most efficient system to solve a problem.

Your code samples are generally very good, I think. For that I applaud you. If you want, please keep submitting them...just don't be surprised when we continue to dicount them for not adhering to the challenge criteria. Furthermore, understand that some people see it as impolite when you criticize their challenge guidelines because they limit your coding style. That's the whole POINT of many of these challenges. Check a few pages back for the Floodfill challenge(recursion was not allowed) as a great example of this.

I realize that English isn't your primary language, so I appologize if I'm just misreading your posts, but they come across as very arrogant. It makes them really hard to read. Bleh, this post is probably even worse, though, so I guess I'm being hypocritical. ::sigh::


You know a lot of really odd quotes. I haven't heard of either of those. w Oh, by the way, are you actually posting from Mexico City?


Yeah, that's kinda what I was getting at with the subtract from 255 thing. I wouldn't think to use XOR. My XORing needs practice. Incidentally, I'm not a "he." Though perhaps if I was, I'd be making a bit more money. >.<
Meg: I agree with your points on Tooh's entries.
Btw, my posts also always sound arrogant... I hate it when I post arrogant posts, oh well, maybe I'm just arrogant... Wink

Quote:You know a lot of really odd quotes. I haven't heard of either of those. w Oh, by the way, are you actually posting from Mexico City?
I haven't heard of the quotes either. Plus, Moneo is sometimes online on very strange times for someone in Mexico Wink

Quote:Yeah, that's kinda what I was getting at with the subtract from 255 thing. I wouldn't think to use XOR. My XORing needs practice. Incidentally, I'm not a "he." Though perhaps if I was, I'd be making a bit more money. >.<
:o :o Really? :o :o Wow... wonderful! :roll: I've corrected the "he"-s to "she"-s Wink
Also, I think it's still discrimination if women get less money than men, even if they are on the same level of knowledge or even higher (if you know what I mean Wink).
About XORing, well... I just like bits...
Meg, thanks for your troubled time to type up an insight.

I wasn't being arrogant, and, more: Talking the way I'm doing to a parent. It's barely seen that the culture-shock is on the scene again.

Your concerns about the 'language-barrier' reminds me of a not-so-distant memory which dates back to my freshman year at the Business School about four years ago. At the time, a French fine-arts lecturer lady, who recently moved to Istanbul after doing academic studies, one day with a pale face, rushed into the amphitheater and spoke up with a broken Turkish:
Quote:I swore at the traffic!.. Mon Deu, what I just can't do in French!..
If one, a very busy one, types up some 'gigantic' posts, then he/she isn't doing it just to hit the dust but for the sake of passion. Remember that, my prior posts 'strictly' adhered to the 'rules.' One of them got dismissed, because the author -- yours truly -- honestly told that he didn't test it!.. Do I bother to care? Not to some precise extent. Read on.
  • Discounted? What is discounted? What am I missing here?
I am totally frustrated by the level of isolation from a thread with a 'rule violation' excuse. 'It doesn't adhere to the rules' doesn't justify a statement by 'it is of no good.' Frivolousness, anyone? 'Ignoring' versus 'discounting from the challenge.' Second is no problem.

Again, as for your language concerns about my post, Meg, it doesn't need to be toned down. Attempts of eliciting emotive bias on issues through use of some 'old' sayings are equivalent of 'drooling' in my culture. Live with it.

My apologies if the English was unclear. It, of course, wasn't your fault, Meg. Should a sentence doesn't sound right, or is just unclear, ask away!.. Hey, I've never been abroad!..

Quality of my code? Probably better than average, yes: I'm doing graduate studies in Computer Science.
I now understand you perfectly.
Pages: 1 2 3