[racket] Order of Operations - Getting the brackets.

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Dec 22 10:22:24 EST 2010

Here's an algorithm for converting from "normal math" to Racket.

Write your expression:

people * ticket-price - (number-of-shows * 20 + people * ticket-price)

Notice that I didn't put parentheses anywhere that order of operations
didn't require them.

Now, add exactly one pair of parentheses for every operator that
doesn't have one. Make sure you don't add too many and make sure you
don't add too few. You should end up with the same number of operators
as pairs of parentheses:

((people * ticket-price) - ((number-of-shows * 20) + (people * ticket-price)))

Notice 5 operators (*, -, *, +, and *), 5 open parens, and 5 close parens.

Now, move each operator to right after the open paren of the pair that
encloses it. In other words, I'll move the first * to in front of
people (i.e. after the second open parenthesis), but the - will move
after the first open parenthesis.

(- (* people ticket-price) (+ (* number-of-shows 20) (* people ticket-price)))

Don't worry. This gets much easier with practice.

Todd

On Wed, Dec 22, 2010 at 5:44 AM, Sayth Renshaw <flebber.crue at gmail.com> wrote:
> What I am having trouble navigating is the brackets.
>
> Simply in normal math what I am trying to do is
>
> (people * ticket price)-((number of shows * 20)+(people * cost per person))
>
> Contrcat : total profit : attendees performance -> number
>
> ;; Purpose to calculate total profit of a theatre per show
>
> ;;Example: (total profit 20 1) should produce $70
>
> ;;Defintion: ( define (- profit cost))
> (* patrons 5( - (* patrons 0.5(+ (* shows 20)))))
>
> (define (patrons p)
>     ;p     a number
>     ...
>     )
>
> (define (shows s)
>     ;s        a number
>     ...
>     )
>
> (define (total_profit p s)
>     (* p 5( - (* p 0.5(+ s 20)))))
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>


Posted on the users mailing list.