Design a method to find the frequency of occurrences of any given word in a
book. What if we were running this algorithm mUltiple times?

if(word== book.word)

while book.next != null

Given two straight line segments (represented as a start point and an end point)'
compute the point of intersection, if any.

x0 y0 x1 y1
a0 b0 a1 b1

imperative programming vs functional

"compute the point of intersection" what does it mean for two line segments to intersect === different slopes   OR they have the same slopes which means they better be the same line

Point intersection(Point start1, Point end1, Point start2, Point end2){
if(start1.x > end1.x) swap(start1, end1)
if (start2.x > end2.x) swap(start2, end2);   (make sure things are referring from same reference location

if(start1.x > start2.x){
    swap the x's and y's

compute lines

case parallel lines = > must have same y intersept

otherwise we can now get intersection coordinate 


Tic tac toe design decisions to consider
How many times will we call has won
tic tac is 3x3, but do we want to generalize?

efficient code vs clear code tradeoff


INT IS 32 bit   so 2^31 - 1 or -2^31

LONG 64
DOUBLE 64

Represent the WHOLE board as an int, 0,1,2

To convert a board to an int

enum Piece {Empty, Red, Blue};

int convertBoardToInt(Piece[][] board){
   int sum = 0;
for(int i =0; i < board.length; i++){
   for(int j=0; j< board[i].length;j++){
      int value = board[i][j].ordinal()

BUILD AN ITERATOR

Piece hasWon(Piece[][] board){
   if (board.length != board[0].length) you fucked
   int size = board.length
   
   ArrayList<PositionIterator> instructions = new ArrayList<PositionIterator>();
   for()
     instructions.add(new PositionIterator(new Position(0,i), 1, 0, size));
     instructions.add(new PositionIterator(new Position(0, size-1), 1, -1, size))



enum and ordinal  enumeration constant

Comments

Popular posts from this blog

ADVERTISING STYLES