# Older blog entries for fejj (starting at number 175)

4 Mar 2007 (updated 1 Apr 2011 at 19:43 UTC) »

Update: this article was moved: Quick Sort

4 Mar 2007 (updated 4 Mar 2007 at 14:50 UTC) »

I came across something cool the other day that I thought I'd share: a 25-byte long integer sort routine (that is to say, the routine itself is only 25 bytes long).

Here it is:

```
;---------------------------------------------------------------
; Sorts an array of ints. C-callable (small model). 25 bytes.
; void sort (int n, int a[]);
;
; Courtesy of David Stafford.
;---------------------------------------------------------------
.model small
.code
public _sort
top:    mov     dx,[bx]   ; swap two adjacent ints
xchg    dx,[bx+2]
xchg    dx,[bx]
cmp     dx,[bx]   ; in the right order?
jl      top       ; no, swap them back
inc     bx        ; go to the next integer
inc     bx
loop    top
_sort:  pop     dx        ; get return address (entry point)
pop     cx        ; get count
pop     bx        ; get pointer
push    bx        ; restore pointer
dec     cx        ; decrement count
push    cx        ; save count
push    dx        ; save return address
jg      top       ; if cx > 0
ret
end
```

fzort: Ah, thank you for the explanation :)

I was just about to note that expanding on my previous estimation, a slightly better one would be:

r = (x >> 1) - (x >> 2) - (x >> 3) + (x >> 6)

And then of course I could perhaps expand on the (x >> 6) in a similar fashion to get an even more accurate result.

Anyways... kind of an interesting problem.

1 Feb 2007 (updated 1 Feb 2007 at 10:50 UTC) »

Interesting interview questions:

Q: What's a fast way to divide an integer by 7 using the bit shift operator? (apparently asked by an EA Sports interviewer)
A: I thought about this for a bit and came up with the following estimation:

r = (x >> 2) - (x >> 3) + (x >> 6);

I mostly mention this because I had my own interview today where I felt... well, less than adequate. Suffice it to say, my ability to figure out the Big-O notation for algorithms was less than stellar. I was also unable to come up with a solution for his webcrawler scenario, which was along the lines of "if you've got some huge number of pages to crawl, how could you prevent the crawler from scanning the same page multiple times?" to which I had to admit to him, I hadn't the slightest idea how to go about it (the prelude to this question had been "the simplest way to do such a thing if memory was not an issue" to which I replied I'd use a hash table, using the page urls as the key).

Been listening to Drivin' Too Fast lately, really has a nice groove to it.

Amazing what a break from looking at code can do to help you fix a bug.

Back in 2004, I had been writing articles explaining different sorting algorithms, how they worked, and how to implement them in C (and in most cases, how to implement them more efficiently than the "standard textbook way"). Well, I had gotten distracted around the time I had been working on an article for Quick Sort and never got around to finishing it. I remember having a bug in my QuickSort routine somewhere that I wasn't able to find after a few nights of looking at it and having had more pressing things to attend to, set it aside for later (but not before documenting a few test cases that failed and how they failed).

Well, yesterday, after coming across that code, I opened it up in my trusty Emacs editor and in just a few minutes had a solution... it was basically a simple one-off bug.

Not long after, I got a call from someone at Google who had seen my resume and repeatedly told me they found it "interesting". I have no idea what that means, exactly, but I take it that it's a Good Thing(tm) :)

23 Jan 2007 (updated 24 Jan 2007 at 15:16 UTC) »

Thanks to Ross's blog for informing me about Dave Cridland's Push-IMAP projects (Polymer, Telomer) and the Lemonaide specs. This was quite an interesting read... I've been wanting something like this for years, it's really exciting stuff.

Despite what pvanhoof claims in his own response to this news, offline functionality is not the hardest part of implementing an IMAP client.

I find it hillarious that the only argument against what I've posted comes down to:

"No really, Bush is a Bad Man because I say so."

Very convincing argument, I must say.

bi: You claim that my arguments are unfalsifiable and somehow conclude that this means that Iraq did not have possession of WMDs? Huh? I simply cannot follow your logic. I agree that the claim that Iraq had WMDs is unfalsifiable, which is exactly my point - all of the people claiming that Iraq never had WMDs are simply mindlessly regurgitating what the news media is feeding them in order to manipulate the masses to be against the Bush Administration; a brainwashing if you will.

20 Dec 2006 (updated 20 Dec 2006 at 19:46 UTC) »

bi: you still fail to offer any evidence to the contrary. Is it safe to conclude, then, that you have none and that there is the possibility that what I have stated is truth?

Also, there were other compelling reasons to go to war with Iraq than simply the question of whether they had WMDs, as I pointed out in my last post which you failed to bother to even acknowledge (you focused only on one small portion of what I wrote to critique).

As to the issue of the Iraqi people being worse now than they were because of the mortality rate?

I present to you the following statistics in rebuttal (from markhumphrys.com ):

Opinion Polls in Iraq

Johann Hari on opinion polls after the war: "So what we now know is that on the day of the anti-war rally, with all the caveats ... a majority of Iraqis were saying: "Better this invasion than what we faced otherwise." They would not have been marching with you. They would have been marching for the invasion."

July 2003

Post-liberation, the majority of Iraqis in Iraq support the war! (also here and here and here and here)

Sept 2003

What Iraqis Really Think, September 10, 2003 (also here)

• The majority oppose an Islamic state.
• When asked what country they would want Iraq to be like - Syria, Saudi Arabia, Iran, Egypt or the US - the US was the no.1 answer.
• The majority want to punish the Baath Party rather than forgive their crimes.
• The majority want America to stay longer.

Mar 2004

Survey

• The majority who expressed an opinion supported the US invasion.
• The majority think things are better now than before the war.
• The majority oppose an Islamic state.
• 80 percent oppose the fascist "resistance".
• The majority want America to stay longer.

Who knows better: the Iraqi people or Spain's new PM? - discussion of the above survey by Janet Daley. Why does the ignorant socialist government of Spain listen to Al Qaeda on Iraq, instead of to the Iraqi people? Why do they do Al Qaeda's bidding on Iraq, instead of the bidding of the people of Iraq?

May 2004

Survey

• 84 percent of Iraqis say Saddam is guilty of murdering their countrymen.
• 83 percent say he was a torturer.
• 61 percent say he deserves the death penalty.

June 2004

Survey

• 76 per cent of Iraqis feel freer to express their political views in public today than under Saddam.
• More than 80 per cent feel freer to exercise their religious beliefs.
• 76 per cent do not believe their lives were made worse by the Coalition.
• 85 per cent feel safer with CPA in place.

Dec 2004 - Jan 2005

Survey

Do you support military action against the so-called resistance? 88 percent said "Yes".

Dec 2005

Survey (see here)

• 57 percent want democracy, 26 percent want a dictator, 14 percent want an Islamic state. Zarqawi is fighting for something that nobody wants. His stupid men are dying for something that nobody wants.
• When should the allies leave Iraq? 26 percent say leave now. 66 percent say stay longer.
• 80 percent of Kurds say the US was right to invade Iraq.
• 58 percent of Shiites say the US was right to invade Iraq.

Jan 2006

Survey

"Thinking about any hardships you might have suffered since the US-Britain invasion, do you personally think that ousting Saddam Hussein was worth it or not?"

• 77 percent of Iraqis think it was worth it.
• The Sunnis regret the end of apartheid, but if we exclude them, 91 percent of Kurds say it was worth it, and 98 percent of Shias say it was worth it.

So, despite a higher mortality rate, the Iraqi people seem to prefer life post-Saddam as compared to under Saddam.

166 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!