chipotle: (Default)
[personal profile] chipotle

This wins the internets: combining geek (and I mean, really geek) humor and Led Zeppelin.

stevenf’s zep.pl

*** Black Dog achieved in 36 ZepMarks ***

Naturally, someone else ported it to Python. And, because I’m just like that, I ported it to Ruby:

#!/usr/bin/env ruby

words = ['hey', 'mama', 'said', 'the', 'way', 'you',
  'move', 'gonna', 'make', 'sweat', 'groove']

success = [ 0, 0, 1, 2, 3, 4, 5, 6, 7,
  8, 5, 9, 7, 8, 5, 10]

iterations = 0
matches = 0
matched = Array.new

while matches < 16
  iterations += 1
  print "[#{iterations}] "

  0.upto(15) do |i|
    if matched[i]
      print words[success[i]], ' '
    else
      r = rand(11)
      print words[r], ' '
      if r == success[i]
        matches += 1
        matched[i] = true
      end
    end
  end

  print "\n"
end

puts "*** Black Dog achieved in #{iterations} ZepMarks ***"

(Oh, c’mon, it was only 604 bytes — don’t whine about it needing an LJ cut!)

Date: 2007-02-02 06:38 (UTC)
From: [identity profile] 3catsjackson.livejournal.com
Thank you! This made my evening. I've been spending more and more of my days in Ruby-land and less and less in Perl-land, but it's good to see both used to such productive ends. (Got 26, btw.)

Date: 2007-02-02 09:38 (UTC)
From: [identity profile] dour.livejournal.com
Gah, dammit... I had this in Smalltalk, but I thinkoed (tested success against r instead of i) and wound up with an infinite loop. And of course, hadn't saved the image before testing it. And of course, didn't have the workspace text anywhere but the workspace. And of course, now it's bedtime.

Coding with beer is fun, but unproductive.

On the clever side, because in Smalltalk 'nil' does not satisfy 'false' and I didn't want to waste lines initializing the array, I just tested against nil and put the words in place as I found them; my final 'matched' would have actually contained the verse. :)

My feedback

Date: 2007-06-03 01:53 (UTC)
From: (Anonymous)
good work...

Profile

chipotle: (Default)
chipotle

February 2018

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627 28   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 2025-12-28 04:31
Powered by Dreamwidth Studios