# Important Algorithm Finally Ported

**URL:** <https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304>\
**Category:** Ruby\
**Created:** [January 12, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304 "2006-01-12T18:10:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/1 "2006-01-12T18:10:38Z")

</div>

After months of work, gruelling hours, and a nice cup of coffee, the  
world’s most famous (and infamous) algorithm has been ported to the  
ruby language!

{applause}

Thank you, thank you.

The Slim Shady algorithm is a deceptively simple algorithm which finds  
use in many many aerospace and bio-informatics systems. Therefore, Ruby  
may now stand proud as… a… ummm… language to do those things.

Here is the algorithm…

def slim\_shady\_finder homies  
homies.each do |some\_guy|  
return some\_guy if (some\_guy.name.eql? “Slim Shady”)  
end  
return nil  
end

Thank you, I know you all can tell how many hours of work have gone  
into this conversion. For more information on the SSA and to see where  
our implementation has been added… go to the Uncyclopedia.

[http://uncyclopedia.org/wiki/Slim\_Shady\_Algorithm#The\_Actual\_Algorithm.27s\_implementations](http://uncyclopedia.org/wiki/Slim_Shady_Algorithm#The_Actual_Algorithm.27s_implementations)

---

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/2 "2006-01-12T18:16:48Z")

</div>

Hi –

On Fri, 13 Jan 2006, Hampton wrote:

> may now stand proud as… a… ummm… language to do those things.
> 
> Here is the algorithm…
> 
> def slim\_shady\_finder homies  
> homies.each do |some\_guy|  
> return some\_guy if (some\_guy.name.eql? “Slim Shady”)  
> end  
> return nil  
> end

I have no idea what you’re talking about, but you’ve triggered my  
code-massaging compulsion 🙂

def slim\_shady\_finder(homies)  
homies.find {|h| h.name.eql?(“Slim Shady”) }  
end

David

–  
David A. Black  
removed\_email\_address@domain.invalid

“Ruby for Rails”, from Manning Publications, coming April 2006!

> **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails)**
>
> NEWER EDITION AVAILABLE
> 
> The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> 
> 
> Ruby for Rails helps Rails...

---

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/3 "2006-01-12T18:31:55Z")

</div>

On Fri, Jan 13, 2006 at 02:08:07AM +0900, Hampton wrote:

> may now stand proud as… a… ummm… language to do those things.  
> Thank you, I know you all can tell how many hours of work have gone  
> into this conversion. For more information on the SSA and to see where  
> our implementation has been added… go to the Uncyclopedia.

Oh, thank goodness. I can finally write that plzstandup.rb program.

–  
Chad P. [CCD CopyWrite | [http://ccd.apotheon.org](http://ccd.apotheon.org) ]

unix virus: If you’re using a unixlike OS, please forward  
this to 20 others and erase your system partition.

---

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/4 "2006-01-12T20:08:43Z")

</div>

Hi –

On Fri, 13 Jan 2006, Hampton wrote:

> David, I’m sorry to say that there is no way to ever improve upon the  
> code I write.
> 
> For, you see, I am the Savior of Ruby. Actually, I’m just kidding. I’m  
> really the King of Ruby.
> 
> Well, I was trying to use the do and no () to make it as ruby-esque as  
> possible. But, I do like your use of find… so feel free to change it  
> on that wiki.

There’s nothing Ruby-esque about leaving off the parens, except when  
they’re empty, at which point there is 🙂 Nor is do/end more  
Ruby-esque than {}.

I specialize in nice-looking, short-but-readable code that runs really  
slowly 🙂 (I didn’t benchmark the two versions but if mine’s slower,  
it wouldn’t be the first time.)

David

–  
David A. Black  
removed\_email\_address@domain.invalid

“Ruby for Rails”, from Manning Publications, coming April 2006!

> **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails)**
>
> NEWER EDITION AVAILABLE
> 
> The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> 
> 
> Ruby for Rails helps Rails...

---

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/5 "2006-01-12T20:29:56Z")

</div>

I think you missed a bit:

def slim\_shady\_finder( homies )  
homies.find{ |some\_guy| some\_guy.name.eql?( “Slim Shady” ) and not  
some\_guy.imitating? }  
end

---

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/6 "2006-01-12T18:50:10Z")

</div>

David, I’m sorry to say that there is no way to ever improve upon the  
code I write.

For, you see, I am the Savior of Ruby. Actually, I’m just kidding. I’m  
really the King of Ruby.

Well, I was trying to use the do and no () to make it as ruby-esque as  
possible. But, I do like your use of find… so feel free to change it  
on that wiki.

---

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/7 "2006-01-12T22:04:03Z")

</div>

On Thu, 12 Jan 2006 19:26:40 -0000, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I think you missed a bit:
> 
> def slim\_shady\_finder( homies )  
> homies.find{ |some\_guy| some\_guy.name.eql?( “Slim Shady” ) and not  
> some\_guy.imitating? }  
> end

This is so important, I think we should do it _really_ slowly and  
carefully.

def find\_slim(homies)  
if (real\_slim = homies.select do |guy|  
guy.name.eql?(‘Slim Shady’)  
end.reject do |guy|  
guy.respond\_to?(:imitate\_shady)  
end.each do |guy|  
guy.send(:please\_stand\_up, Time.now)  
end).length == 1  
real\_slim.first  
else  
homies.shady\_missing(:real\_slim)  
end  
end

---

<div class="post-metadata">

**Author:** ![Hampton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Hampton](https://www.ruby-forum.com/u/Hampton)\
**Post date:** [January 12, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/important-algorithm-finally-ported/52304/8 "2006-01-12T22:07:05Z")

</div>

On 1/13/06, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I think you missed a bit:
> 
> def slim\_shady\_finder( homies )  
> homies.find{ |some\_guy| some\_guy.name.eql?( “Slim Shady” ) and not  
> some\_guy.imitating? }  
> end

But surely you can’t just know if a slim shady is just imitating  
without first asking them to stand up.

Perhaps:

slim\_shadies.find { |slim\_shady| slim\_shady.stand\_up\_unless {  
slim\_shady.imitating? } }

Of course, that has problems - for one, it messes up the shadies’  
persistent ‘standing’ state. This could cause serious problems with  
false negatives if they were asked to “please stand up” twice in a  
row. It might be possible to subsequently make them sit again, but the  
whole thing loses thread safety easily (what if two programs  
simultaneously need to find the real slim shady?).

To top it all off, there are potential accessibility issues for  
disabled slim shadies who are unable to stand. I consider this  
particularly likely to become a problem if every person is a slim  
shady lurking. I think the only real solution here is to accept that  
there is a slim shady in all of us and make slim\_shady\_finder simply  
return nil.

Sam
