Newsgroups: comp.lang.ruby
From: Christian von Kleist <cvonkle...@gmail.com>
Date: Mon, 3 Dec 2007 12:14:06 -0500
Local: Mon, Dec 3 2007 12:14 pm
Subject: Re: [QUIZ] Postfix to Infix (#148)
On Dec 3, 2007 9:42 AM, Eric Mahurin <eric.mahu...@gmail.com> wrote:
> On Dec 3, 2007 8:05 AM, Ken Bloom <kbl...@gmail.com> wrote: > > On Sun, 02 Dec 2007 22:23:23 -0500, Eric Mahurin wrote: > > > Note: parts of this message were removed by the gateway to make it a > > > On Nov 30, 2007 7:28 AM, Ruby Quiz <ja...@grayproductions.net> wrote: > > >> For an added bonus, try to keep the parentheses added to infix > > > My solution does the above, plus a few more things: > > > * maintains an OO data structure (to do everything below) * further > > > The basic idea of the solution is to have an object for each expression > > > Here are a few examples (result shows internal postfix, infix, and > > >>ruby quiz148.rb "2 3 5 + *" > > This doesn't look right. > > Thanks Ken, > I obviously didn't test divide. My previously solution has a stupid typo in > class Quotient < Product > Here's a couple more tests: > >ruby quiz148.rb "3 5 / 5 8 / /" > All the results are zero because it is using ruby's Fixnum#/. The last form > def rdiv(other) > you'll get this: > >ruby quiz148.rb "3 5 5 8 / / /" > 3 5 / 5 * 8 / => 3/5*5/8 => 0 Fine, here is my 5-minute solution which doesn't optimize parentheses: #!/usr/bin/ruby It was originally a few lines longer as the ternary operator was an You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||