Fast String Reversal

Post Reply
MagneticMonopole
Posts: 26
Joined: Fri Nov 07, 2008 3:19 pm

Fast String Reversal

Post by MagneticMonopole »

Reverse an input string of length 100 in 60 cycles?
I am very, very amazed.
therethinker
Posts: 144
Joined: Fri Mar 28, 2008 11:29 pm
Location: #hacker.org on Freenode

Post by therethinker »

The trick: threading. It takes only 1 cycle to run thousands of threads.
User avatar
efe
Posts: 45
Joined: Sun Oct 26, 2008 10:28 am
Location: germany

Post by efe »

But you can only create 32 threads!
How can you keep them synchronized?
therethinker
Posts: 144
Joined: Fri Mar 28, 2008 11:29 pm
Location: #hacker.org on Freenode

Post by therethinker »

Good point. I guess I was being a bit too dramatic :P

I think I have a basic understanding of how it's done, but I won't spoil the fun ;-)
ShardFire
Posts: 26
Joined: Wed May 30, 2007 4:26 pm
Location: United Kingdom

Post by ShardFire »

I did a rewrite of the program using a superior technique and cut 20% more off that time. It may be possible to make it even shorter still using some sort of hybrid/alternative method or other optimizations, but I think I'll stay with what I've got for now... :wink: I'm sure someone will still be able to beat me while I have a suboptimal solution, so until then...!
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

My first threaded functional version uses 34 cycles ... % is count as a cycle as well :(

I have some trick in sleeve ... not working in java version, but getting under 27 ?!

OK, I am on 33 now. And now on 32.

Codding in excell is more convenienet than in notepad ...
I have finished SuperHack debugger in Excell VBA, it helps in debugging, but not producing codding ideas.

(32 works for inputs of length upto 108)

I could probably evolve to 31, but I should make higher changes to reach required 29.

Already on 30 :) ... works for inputs of length upto 112 ... and now till 120 and now 122 ... 124

:) I had to add several blank lines to my code :)
And I have 29 ... upto 96

So finally on 29,117 ... and the input length could be prolonged a bit.

Oops php implementation differs from what I have expected :( ... back to codding
... no that was just wrongly sent solution...
Post Reply