Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Beer Night PDX

Alex Chaffee
Saturday, May 19, 2007

front
back

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Extra Action

Alex Chaffee
Saturday, May 19, 2007

It was fate. A crew of Pivots in Portland on the same weekend as the Extra Action Marching Band We just had to seize the opportunity…

Will they be making an appearance at our Beer Night tonight? You never know…

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Ruby Puzzler

Alex Chaffee
Saturday, March 24, 2007

puzzler I was just sitting around my living room listening to NPR, and heard the following Car Talk puzzler:

I want you to get a pencil and write down the numbers, 1 – 9, inclusive, and leave enough space between them. At your disposal you have one plus sign and two minus signs. You can insert those plus and minus signs wherever you want, to make the total come out to 100.

Naturally, I thought, “Gee, that would be tedious to solve it by hand. But it would be fun to write a Ruby program to solve it!” 9 minutes later I was sending the result (and the source code) to Car Talk Plaza.

So here’s your challenge: can you write a program to solve this puzzle? And can you beat my time?

My solution is below the fold… don’t click “more” until you’ve taken a stab at it yourself.

#!/usr/local/bin/ruby

(1..8).each do |plus|
  (1..8).each do |minus1|
    next if minus1 == plus
    ((minus1+1)..8).each do |minus2|
      next if minus2 == minus1 or minus2 == plus
      exp = ""
      (1..9).each do |digit|
        exp = "#{exp}#{digit}"
        exp = "#{exp}+" if digit==plus
        exp = "#{exp}-" if digit==minus1 or digit==minus2
      end
      x = eval(exp)
      if x == 100
        puts "#{exp}=#{x}"
      end
    end
  end
end

And a follow-on challenge: can you refactor my code to make it either clearer or more concise (i.e. obfuscated)?

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Joe Moore

The best thing I've heard all day

Joe Moore
Friday, March 23, 2007

“This is either the stupidest or best idea I’ve ever heard”

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

My pair the be-whiskered

Pivotal Labs
Friday, February 9, 2007

Pair Programming for Ailurophiles

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (778)
  • rails (113)
  • testing (87)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (54)
  • techtalk (44)
  • rspec (38)
  • activerecord (29)
  • productivity (29)
  • gogaruco (29)
  • ironblogger (29)
  • git (28)
  • nyc (27)
  • rubymine (25)
  • bloggerdome (22)
  • mobile (22)
  • cucumber (20)
  • process (19)
  • pivotal tracker (19)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • tdd (13)
  • selenium (12)
  • css (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to fun Feed
  1. ←
  2. 1
  3. 2
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >