Difference between revisions of "CSC103 Final Solutions Fall 2012"
(→Boolean Logic) |
(→Boolean Logic) |
||
Line 20: | Line 20: | ||
|0 | |0 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|0 | |0 | ||
Line 32: | Line 32: | ||
|1 | |1 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|0 | |0 | ||
Line 44: | Line 44: | ||
|0 | |0 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|0 | |0 | ||
Line 56: | Line 56: | ||
|1 | |1 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|1 | |1 | ||
Line 68: | Line 68: | ||
|0 | |0 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|1 | |1 | ||
Line 80: | Line 80: | ||
|1 | |1 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|1 | |1 | ||
Line 92: | Line 92: | ||
|0 | |0 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|1 | |1 | ||
Line 104: | Line 104: | ||
|1 | |1 | ||
|1 | |1 | ||
− | | | + | |1 |
|- | |- | ||
|} | |} | ||
+ | |||
+ | * The equation is | ||
+ | |||
+ | Y = D or NOT( C AND NOT( A AND B ) ) ) | ||
+ | |||
+ | * There were also longer forms, which were also valid. | ||
=Assembly= | =Assembly= |
Revision as of 10:19, 31 October 2012
--D. Thiebaut 10:11, 31 October 2012 (EDT)
Boolean Logic
A | B | C | D | Y |
0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 |
0 | 0 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 |
0 | 1 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
0 | 1 | 1 | 0 | 0 |
0 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 0 | 0 |
1 | 0 | 0 | 1 | 1 |
1 | 0 | 1 | 0 | 0 |
1 | 0 | 1 | 1 | 1 |
1 | 1 | 0 | 0 | 0 |
1 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 0 | 0 |
1 | 1 | 1 | 1 | 1 |
- The equation is
Y = D or NOT( C AND NOT( A AND B ) ) )
- There were also longer forms, which were also valid.
Assembly
This program provided by Erika is simple, short, and will compute the exact sum.
; CSC 103 Final – Problem 2
; Erika Miguel
; Computes the sum of all the multiples of 3 between 0 and 30
; and stores the result in variable sum.
@0
jmp start
;
; data section with 2 variables
;
counter: 30
sum: 0
;
; code section
;
start:
; sum <- counter
lod counter
sto sum
; counter <- counter - 3
loop:
lod counter
sub-c 3
sto counter
; if counter is 0, then jump out of loop
jmz done
; sum <- sum + counter
lod sum
add counter
sto sum
; go back to compute new sum
jmp loop
; if we reach this point, then we are done with
; the loop and sum should contain the result
done: hlt
Processing
// D. Thiebaut
// This program displays random circles on the screen when the mouse is pressed.
// When the mouse is pressed and moves to the left, circles shrink, while still remaining
// of random radius. Similarly, circles grow when the mouse moves to the right, while
// still remaining random in size.
float diameter;
void setup() {
size( 500, 500 );
smooth();
}
void draw() {
diameter = random( mouseX / 2 );
if (mousePressed == true){
fill( mouseX/3, random( 255 ), random( 255 ) );
ellipse( random( 500 ), random( 500 ), diameter, diameter );
}
}