CSC103 Final Solutions Fall 2012

From dftwiki3
Revision as of 10:16, 31 October 2012 by Thiebaut (talk | contribs) (Boolean Logic)
Jump to: navigation, search

--D. Thiebaut 10:11, 31 October 2012 (EDT)


Boolean Logic

A B C D Y
0 0 0 0 0
0 0 0 1 0
0 0 1 0 0
0 0 0 1 1
0 1 0 0 0
0 1 0 1 0
0 1 1 0 0
0 1 1 1 0
1 0 0 0 0
1 0 0 1 0
1 0 1 0 0
1 0 1 1 0
1 1 0 0 0
1 1 0 1 0
1 1 0 1 0
1 1 1 0 0
1 1 1 1 0

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 );
   }
}