User login

Last Person to Reply Wins!

2588 replies [Last post]
stabguy's picture
stabguy
Offline
Administrator
male
Honolulu, HI USA
Joined: 09/15/2009

My programming contest is over for now. Round 3 of 3 closed this week. Now we have to wait for the judges to score rounds 2 and 3 to see if I will win the Grand Prize - a trip to San Francisco. Party

Round 3 was definitely my strongest. I expect my program to dominate the competition on any test the judges throw at it. Some of my competitors published their execution times on a set of benchmark tests we were all using. Here's how my program stacks up against theirs (all times in milliseconds, lower numbers are better):

Problem size
(in cycles)
Competitor A
(in msecs)
Competitor B*
(in msecs)
Competitor C
(in msecs)
stabguy
(in msecs)
4774N/A1.7512.9771.039
71962.444N/A2.8201.027
71792.205N/A3.1321.026
50392.584N/A2.9181.038
114191.688N/A2.7981.038
215931.695N/A2.9331.047
43178773543.51350.52923.6323.818
57439573433.88559.51330.73114.276
124151398460.255N/AN/A1.051
148369546066.790152.4477.0656.456
2626626062102.318268.011135.4174.233
4076988879144.773411.186190.5779.285
15332557248434.2531,517.950592.37410.994
794568949401,955.9897,836.130890.41311.952
1589137899523,892.730N/A1,623.424N/A
(* Competitor B claims to have doubled this speed prior to submitting his entry.)

Note how the other programs get progressively slower as the problem size grows. That's called linear or O(n) running time. My program solves any problem in 15 milliseconds or less. The 574395734 test is a near worst-case scenario for it.

Now I will go into some detail about the problem statement and my solution. This will get technical but at least there are pretty pictures...

The problem is called Running Numbers because it acts like a crazy odometer. Given three 128 bit input values (in hexadecimal):

Create an accumulator that starts with value Source. On the first cycle (cycle number zero), add DWORD adder to the accumulator. For this addition treat both the accumulator and the adder as four independent 32-bit words. If the result of any addition exceeds the 32-bit capacity it simply "rolls over", discarding the carry:

For the second cycle (number 1), add BYTE adder to the accumulator. This time the accumulator and adder will be treated as 16 individual bytes, each rolling over without carry:

Continue doing BYTE additions for 35 more cycles. On the 37th cycle (cycle number 36), the whole process starts over with a DWORD addition. In other words, do a DWORD addition whenever the cycle number is evenly divisible by 37. Otherwise, do a BYTE addition. Run this simulation until a cycle ends with all bytes equal to zero or all bytes equal Source (their original values). When that happens, print the number of cycles completed and exit.

Here's pseudocode for the simulation:

    a = Source
    cycle = 0
    do
        if cycle % 37 == 0
            a = a + DWORD adder
        else
            a = a + BYTE adder
        cycle = cycle + 1
    while a != 0 AND a != Source
    print cycle

So there's my winning solution. I think it's elegant in its simplicity. Just kidding!

When I read the problem description, it screamed "Streaming SIMD Extentions" (SSE):
Q. 128 bit integer registers?
A. SSE2
Q. Add as four DWORDS?
A. PADDD (_mm_add_epi32 intrinsic)
Q. Add as sixteen BYTES?
A. PADDB (_mm_add_epi8 intrinsic)

Meanwhile, the 37 cycle pattern whispered, "You have 40 cores. Use 37 threads to decompose it." Yet SSE and threading will only go so far when your basic algorithm is "grind it out". In order to go really fast one needs to optimize the algorithm.

I named my algorithm barrel lock because it's analogous to opening a 4 dial lock when you already know the combination.

Partition the 128 bit accumulator into four logical dials as indicated by the four colors in this diagram:

Each dial consists of 4 non-contiguous bytes. The red dial is made up of the least significant byte of each DWORD while the yellow dial is the set of most significant bytes. A dial is not considered solved until all four bytes reach their target values.

The algorithm works in four phases from right to left. The first phase gets the red dial into position. The second phase works on the green dial without moving the red dial, and so on.

For example consider a test where:

Source = d6b610c012e049601632f70094c145c0
BYTE adder = 1bbffa833f0e0f733ca510f5044ef24a
DWORD adder = 39499f0b48e0f3ec3cca214b7a1e0474

The solution proceeds as follows:

After phaseAccumulatorNumber of cycles
initiald6b610c0 12e04960 1632f700 94c145c00
red71f37400 087a6000 5adf7400 df42b0003520
greencf4f0000 aac80000 cd8f0000 18e40000344512
bluef8000000 40000000 f8000000 20000000434389440
yellow00000000 00000000 00000000 0000000015332557248

That should give you a flavor for how I solved this problem. For complete details, see the write up I did on the contest forums.

You won't even feel the blade.

Fly Like an Eagle's picture
Fly Like an Eagle
Offline
Citizen
male
CBus, Ohizzle
Joined: 11/11/2009

TLDR: Stabguy is a genius and deserves a vacation

Live by the creed, die by the creed!
Pussy, money, weed, that's all a n*gga need!

EzioAltair17's picture
EzioAltair17
Offline
Citizen
male
Joined: 05/31/2011
Fly Like an Eagle wrote:
TLDR: Stabguy is a genius and deserves a vacation

agreed Big smile Big smile Big smile Big smile

To be fair, you have to have a very high IQ to understand Rick and Morty. The humor is extremely subtle, and without a solid grasp of theoretical physics most of the jokes will go over a typical viewer's head. There's also Rick's nihilistic outlook, which

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

And a clever solution once again. I really like your threading setup as well. Not that I've got much experience in the field... Tongue

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

All those school years working on art projects...wasted. I don't know what the hell is going on in this topic anymore. Drunk

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

Don't worry, Joey, I wouldn't be able to draw if my life depended on it. Tongue

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Speaking of that, my girlfriend e-mailed me about a scholarship for comic book fans. I just need to submit a portfolio and actually know a good amount of graphic novel lore. I got this...

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

Joey, why didn't you take my advice? You should dump your girlfriend. It will save you a lot of money! And time! And time is money! So you're actually saving money^2! And since money is the root of all evil, you're saving (squareroot(evil))^2, which is the same as evil!
So by dumping your girlfriend, you not only save time and money, you're sparing yourself a lot of evil as well!

I. AM. A. GENIUS!!!111!!!!11!!!

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Holy f*ck, that makes sense! Shock

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

Pty James's picture
Pty James
Offline
Citizen
male
Panama City
Joined: 12/05/2009
161803398874989 wrote:
Joey, why didn't you take my advice? You should dump your girlfriend. It will save you a lot of money! And time! And time is money! So you're actually saving money^2! And since money is the root of all evil, you're saving (squareroot(evil))^2, which is the same as evil!
So by dumping your girlfriend, you not only save time and money, you're sparing yourself a lot of evil as well!

I. AM. A. GENIUS!!!111!!!!11!!!

That makes so much sense it scares me Puzzled

JoeyFogey wrote:
ROB_88 wrote:
[On the meaning of BAMF]i figured it was something similar to a MILF

Babes Await My..............Flap-a-doodle Laughing out loud

PatrickDeneny's picture
PatrickDeneny
Offline
Citizen
Joined: 05/24/2010

If saving money = having more money for yourself...

...then...

...saving evil = having more evil for yourself...

...hence...

evil is conserved and spread Evil

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

My girlfriend is a member on here, by the way. Wink

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

EzioAltair17's picture
EzioAltair17
Offline
Citizen
male
Joined: 05/31/2011
161803398874989 wrote:
Joey, why didn't you take my advice? You should dump your girlfriend. It will save you a lot of money! And time! And time is money! So you're actually saving money^2! And since money is the root of all evil, you're saving (squareroot(evil))^2, which is the same as evil!
So by dumping your girlfriend, you not only save time and money, you're sparing yourself a lot of evil as well!

I. AM. A. GENIUS!!!111!!!!11!!!

NAPPA: vageta how much sense dose this make?

VAGETA: TOOOO MUUUUCH!!!!

To be fair, you have to have a very high IQ to understand Rick and Morty. The humor is extremely subtle, and without a solid grasp of theoretical physics most of the jokes will go over a typical viewer's head. There's also Rick's nihilistic outlook, which

EzioAltair17's picture
EzioAltair17
Offline
Citizen
male
Joined: 05/31/2011
JoeyFogey wrote:
My girlfriend is a member on here, by the way. Wink

WHAAAAAT !! Shock

To be fair, you have to have a very high IQ to understand Rick and Morty. The humor is extremely subtle, and without a solid grasp of theoretical physics most of the jokes will go over a typical viewer's head. There's also Rick's nihilistic outlook, which

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Aww yeah

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

Actually, it doesn't make sense, but whatever. Tongue

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

stabguy's picture
stabguy
Offline
Administrator
male
Honolulu, HI USA
Joined: 09/15/2009
JoeyFogey wrote:
My girlfriend is a member on here, by the way. Wink

If it's the girl I'm thinking of, I had been wondering whether she was your girlfriend or a relative of yours (cousin or something).

You won't even feel the blade.

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Okay, you all really want to know? It's FLAE. There. It's out. Tongue

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

aurllcooljay's picture
aurllcooljay
Offline
Citizen
male
At Thehiddenblade.com. Where else?
Joined: 06/13/2010
JoeyFogey wrote:
Okay, you all really want to know? It's FLAE. There. It's out. Tongue

I thought it was JosieFogey or something like that.

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010
aurllcooljay wrote:
JoeyFogey wrote:
Okay, you all really want to know? It's FLAE. There. It's out. Tongue

I thought it was JosieFogey or something like that.

Ha. That's actually hilarious.

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

I actually chuckled. Tongue

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

Jack-Reacher's picture
Jack-Reacher
Offline
Citizen
male
NZ
Joined: 02/07/2010

Decided to check out this topic.... so that's what happened to 18. He must have "account suicided", im surprised he didn't just post porn everywhere. One time I was bored on gamefaqs I posted pain olympics on some board... was worth it.

aurllcooljay's picture
aurllcooljay
Offline
Citizen
male
At Thehiddenblade.com. Where else?
Joined: 06/13/2010
Jack-Reacher wrote:
So that's what happened to 18.

He was taken back to Abstergo. Wink

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Who thinks an Assassin smiley would be awesome for posts? Just the bottom (chin?) of a yellow circle with a white hood and a small line indicating a mouth. I think Ezio's wider hood with the loops at the neck would be better. Thoughts?

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

PatrickDeneny's picture
PatrickDeneny
Offline
Citizen
Joined: 05/24/2010
JoeyFogey wrote:
Who thinks an Assassin smiley would be awesome for posts? Just the bottom (chin?) of a yellow circle with a white hood and a small line indicating a mouth. I think Ezio's wider hood with the loops at the neck would be better. Thoughts?

Big smile Big smile Big smile

EzioAltair17's picture
EzioAltair17
Offline
Citizen
male
Joined: 05/31/2011
JoeyFogey wrote:
Who thinks an Assassin smiley would be awesome for posts? Just the bottom (chin?) of a yellow circle with a white hood and a small line indicating a mouth. I think Ezio's wider hood with the loops at the neck would be better. Thoughts?

nice idea !!!

To be fair, you have to have a very high IQ to understand Rick and Morty. The humor is extremely subtle, and without a solid grasp of theoretical physics most of the jokes will go over a typical viewer's head. There's also Rick's nihilistic outlook, which

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Where is the topic about writing Ian's bio for the "About" section? It's been stuck on one type since the last post. I've been having trouble finding it and the new "staff" post stab just put up reminded me of that.

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

stabguy's picture
stabguy
Offline
Administrator
male
Honolulu, HI USA
Joined: 09/15/2009
JoeyFogey wrote:
Where is the topic about writing Ian's bio for the "About" section? It's been stuck on one type since the last post. I've been having trouble finding it and the new "staff" post stab just put up reminded me of that.

Say what? I don't think there's a special topic for Ian's bio suggestions. Just post it here or wherever. And I didn't post anything new about "staff". Ian recently updated the About page to reflect piano wire in his pocket, presumably inspired by what you said here, Joey. That's why the page got bumped in the Recent Posts list.

You won't even feel the blade.

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Huh. I swear we made a topic about ian's bio. Or it could just be random posts. My mistake. Smile

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

EzioAltair17's picture
EzioAltair17
Offline
Citizen
male
Joined: 05/31/2011

To be fair, you have to have a very high IQ to understand Rick and Morty. The humor is extremely subtle, and without a solid grasp of theoretical physics most of the jokes will go over a typical viewer's head. There's also Rick's nihilistic outlook, which

GopherBlaine's picture
GopherBlaine
Offline
Citizen
male
Check your 6.
Joined: 01/21/2011

Back after a week of vacation with no internet connection. How I've missed you all.

The Templars were framed.

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

You were missing? I hardly noticed. Wink

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

GopherBlaine's picture
GopherBlaine
Offline
Citizen
male
Check your 6.
Joined: 01/21/2011
JoeyFogey wrote:
You were missing? I hardly noticed. Wink

Ha. And I missed you too.

The Templars were framed.

LisaMurphy's picture
LisaMurphy
Offline
Administrator
female
California
Joined: 03/20/2010
JoeyFogey wrote:
You were missing? I hardly noticed. Wink

I noticed, and I missed you too GB. Welcome back!

"Now you shall get an earful of my beloved sword! Behold, Pillow Talk! Let's rock, baby!"

GopherBlaine's picture
GopherBlaine
Offline
Citizen
male
Check your 6.
Joined: 01/21/2011
LisaMurphy wrote:
JoeyFogey wrote:
You were missing? I hardly noticed. Wink

I noticed, and I missed you too GB. Welcome back!

Well thank you Lisa.

The Templars were framed.

Fly Like an Eagle's picture
Fly Like an Eagle
Offline
Citizen
male
CBus, Ohizzle
Joined: 11/11/2009

Just read the last twenty posts... interesting choice of a partner, Joey...

Live by the creed, die by the creed!
Pussy, money, weed, that's all a n*gga need!

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Well they wouldn't stop bugging me about our partnership. I had to tell them. Tongue

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

I win! Laughing out loud no replies for 2 days! And i just beat myself. ;D

...wait...

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

That's not right, is it?

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

PatrickDeneny's picture
PatrickDeneny
Offline
Citizen
Joined: 05/24/2010

No. No it isn't...

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

Yeah, I thought so.

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Wink

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

----WARNING----
From this point on, you're entering a smiley free zone!

NO. MORE. F***ING. SMILEYS!

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

JoeyFogey's picture
JoeyFogey
Offline
Administrator
male
Indianapolis, IN
Joined: 02/16/2010

Shock Tongue Laughing out loud Cool Wink

PSN: JoeyFogey

Steam: JoeyFogey

Instagram: thatsketchyhero

GopherBlaine's picture
GopherBlaine
Offline
Citizen
male
Check your 6.
Joined: 01/21/2011
JoeyFogey wrote:
I win! Laughing out loud no replies for 2 days! And i just beat myself. ;D

...wait...

It's more fun if you plan with somebody else.

The Templars were framed.

GopherBlaine's picture
GopherBlaine
Offline
Citizen
male
Check your 6.
Joined: 01/21/2011
161803398874989 wrote:
----WARNING----
From this point on, you're entering a smiley free zone!

NO. MORE. F***ING. SMILEYS!

I'm on board with this.

The Templars were framed.

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010
JoeyFogey wrote:
(censored)

Base Phi reporting to Unit Gamma. We have a breach in Indianapolis, IN. Please proceed to immediate elimination.

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

GopherBlaine's picture
GopherBlaine
Offline
Citizen
male
Check your 6.
Joined: 01/21/2011
161803398874989 wrote:
JoeyFogey wrote:
(censored)

Base Phi reporting to Unit Gamma. We have a breach in Indianapolis, IN. Please proceed to immediate elimination.

Roger that Phi. Proceed.

The Templars were framed.

161803398874989's picture
161803398874989
Offline
Citizen
male
Joined: 12/13/2010

Wait, now I'm confused. Are you going to eliminate him, or am I going to do it? You're the unit, so you'll have to do it!

_________________

"Betraying the Assassins is never good for one's health."
"Well, neither is drinking liquor, but I'm drawn to its dangers all the same."

aurllcooljay's picture
aurllcooljay
Offline
Citizen
male
At Thehiddenblade.com. Where else?
Joined: 06/13/2010
GopherBlaine wrote:
161803398874989 wrote:
JoeyFogey wrote:
(censored)

Base Phi reporting to Unit Gamma. We have a breach in Indianapolis, IN. Please proceed to immediate elimination.

Roger that Phi. Proceed.

You may fire when ready.