You are on page 1of 22

T o

H ow
ACSL
Contest #2
Contest 2 Topics
Intermediate and Senior:
Prefix/Infix/Postfix-2
Bit String Flicking-2
LISP-1
Prefix/Infix/Postfix
There are three ways to write an expression such as
Infix is the way you usually see it: A-B/(C+D).
To evaluate a function in infix, you must use order of
operations (PEMDAS) and look at parentheses
The other two formats are Prefix and Postfix
Prefix
The operands are written before the two terms they pertain to
A-B would be written as -AB.
Once two terms get an operator, think of them as a single term and apply the next
operator to that single term and the next term in line, so
/+ABC would be translated to (A+B)/C
is used for exponents, so AB would be A^B
It might help to put parentheses after two terms that have been operated on
Ex. To solve /-AB+CD
1. Apply the operand to the following two terms and put parentheses around
two terms /(A-B)(C+D)
2. Apply the remaining operator to the simplified terms to get (A-B) / (C+D)
Postfix
Follows all same rules except operator is after the two terms it
pertains to
AB+ would equal A+B
ABC-/ would equal A / (B-C)
AB-CD/+ would equal (A-B)+(C/D)
More Practice
The best way to approach simplifying a large prefix/infix/postfix
expression is apply 1 or 2 operands at a time and then keep
working from the simplified expression
Senior Division
Bit String Flicking
Bit String - a sequence of bits (0s and 1s)

e.g. 001001

Flicking - the process of operating on bit strings with logical


operators, shifts, and circulates
If you see an * , it means the bit can be either 0 or 1
For ACSL, all bit strings in an equation will be the same length
Bit String Flicking
The four binary operators you need to know are:

Name Symbol Description Digit 1 Digit 2 Result

NOT ~ opposite of bit 0 n/a 1

AND & if both are 1, return 1 0 1 0


else 0

OR | if either is 1, return 1 0 1 1
else 0

XOR same as or, 1 1 0


except 1 and 1 returns 0
Bit String Flicking
(L or R) SHIFT - (amount)
delete the number of digits specified (amount) from the specified side (L or R)
fill the empty space on opposite side with 0s
e.g., LSHIFT-2 11111 11110 11100
e.g., RSHIFT-1 11111 01111
(L or R) CIRC - (amount)
remove elements from specified side (L or R) and add them to the other side
e.g., LCIRC-2 10101 10110
e.g., RCIRC-3 10101 10110
CIRC Observations
If length of string is L, then LCIRC-x = RCIRC-(L-x)
If x > L, then CIRC-x = CIRC-(x mod L)
Bit String Flicking
From first priority to last, the order of operations is:
NOT
SHIFT and CIRC
AND
XOR
OR
There are two types of problems:
Evaluating the expression (easier)
Solving for a variable (annoying)
Bit String Flicking
Evaluate the following expression:
Bit String Flicking
Bit String Flicking
Bit String Flicking

We can represent the unknown x using a string of variables,


and solve for as many as possible. The rest can be one of two
values, so we can just do 2 ^ the number of those.
LISP
A computer language which stands for LISt Processing Language
The basis of LISP is a list in which elements are enumerated
inside pairs of parentheses
(23 (this is easy) hello 821)
This is an example of a list with four elements and the second element is a list
There are many different statements (functions) to evaluate the
elements
LISP-Arithmetic Statements
LISP-Statements

SET sets the first argument to the second argument , like setting a variable to a value
If the second argument has an before, it is not evaluated (similar to putting quotes)
SETQ is same as SET except you dont need before first argument
LISP-Statements

EVAL just evaluates the argument (unless it has before)


ATOM checks if argument is an atom
If atom, return true
If list, return NIL
LISP-Statements

CAR returns first element of a list


CDR returns the list without the first element
CONS adds the first element as the first term of the second elements list
LISP-DEF Statements
LISP also allows us to create our own functions using the DEF function. For example,

(DEF SECOND(parms) (CAR (CDR parms)))

defines a new function called SECOND which operates on a single parameter named parms. SECOND will take
the CDR of the parameter and then the CAR of that result. So, for example:

(SECOND (a b c d e))

would first CDR the list (yielding (b c d e)) and then CAR the result. So the value would be the single character b.
LISP Practice

You might also like