Newsgroups: comp.lang.ruby
From: Eric Mahurin <eric.mahu...@gmail.com>
Date: Mon, 3 Dec 2007 09:42:10 -0500
Local: Mon, Dec 3 2007 9:42 am
Subject: Re: [QUIZ] Postfix to Infix (#148)
Note: parts of this message were removed by the gateway to make it a legal Usenet post.
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: I obviously didn't test divide. My previously solution has a stupid typo in > > 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, Quotient#to_s. Should be: class Quotient < Product Here's a couple more tests: >ruby quiz148.rb "3 5 / 5 8 / /" 3 5 / 5 / 8 * => 3/5/5*8 => 0 >ruby quiz148.rb "3 5 5 8 / / /" 3 5 5 / 8 * / => 3/(5/5*8) => 0 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 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.
| ||||||||||||||