יום ראשון, 11 במרץ 2012

Chapters 7 and 8

-7.2
1.ok
2.parallel circuit...
3.no idea
4.ok.
5.A and B
6.Not A and B
7.Series of all 3.
8.huh?
9.A and B or Not A and B
10.ok
11.????
12.A and B and the A or B

-7.3
1.I was nervous when I found myself a little lost on this part of the chapter, but by the looks of other people's blogging, I'm not the only one. It seems not as important as the other stuff I've learnt so far.

-8.2
1.1000
2.30
3.2205
4.2^10
5.2^10?
6.10!+1
7.16^3
8.5!/2

-8.3
1.9*8*7
2.26!/21!
3.30!/25!+36!/31!
4.8!/2?
5.8!/2
6.12!/60 pages

-8.4
1.12!/2
2.120
3.1260
4.8?
5.5!
6.Not sure

-8.5
1.help
2.help again
3.40!/5!?
4.
def nChooseK(n, k):
 total = 1
 while (k>0):
  total*=(n/k)
   n--
   k--
  return total
5.?
6.? again.
7.not sure
8.n/x?
9.say what?
-I need help with what formulas to use when.

-8.6
1.20
2.6, im doing this all one by one, not sure how to do the simple way...
3. infinite
4.

Chapters 5 and 6

Chapter 5 Exercises

-5.2
1.18
2.10(a+b)-(a+b)=9a
3.don't get it
4.120,220
5.16,60
6.156
7.2222
8.113
9.220,112
10.ends with 2
11.uhhh

-5.3
1.127, 65535
2. 1001000010101011
3.2EB
4.170302
5.0b101110000
6.
def countBits(n)
 count =0
 n=bin(n)
 while (n!=0)
  if (n%2==1):
   count++
  n//=2
 return count
7.argh..

-5.4
1.-1329
2.error, too many bytes
3.rounding error
4.4211
5.16, 5
6.is it 7?

-6.2
1.I don't do
2.I did my homework and went to see a movie
3.either here or there
4.not P or Q
5.ok
6.ok.
7.pretty straightforward
8.P and not Q

-6.3
1.umm, okay.
2.okay
3.okay
4.okay...
5.Pretty sure I did this right, never been good with Sudoku
6.37
7.all true qs are true ps but not vise versa
8.Isn't it the same?
9.Kind of a waste of time

-6.4
1.return (n>0 and n%2==0)
2.x<-1 or x>1
3.b
4.such a waste of time
5.
def isLeapYear(n):
 if (n%400)
  return True
 elif (n%100)
  return False
 elif (n%4)
  return True
 else
  return False
6.
def isPrime (n):
 x=0
 while (x<=1000)
  if isPrime(x)
   Print x
   x++
  else x++
7.if (x and not s) or (s and not x)
8.ch in range(0,9)
9.negatives

Black Diamonds, wow.

יום שני, 13 בפברואר 2012

Programming in Python Chapters 3+4

3.2 Exercises

1. r=5
p=3.141592
area=p*r**2
2.10
3.name, d7, 2x, first_name, lastName, Amt
4.firstName='Tal'
lastName='Zilkha'
print (firstName+' '+lastName)
5.5 and 3
6.5, error, 'five', 4
7.
def pow4(x):
    return**4
8.+++++len = 5


3.3 Exercises

1. Local variables are for functions and global are variables which are not just for one function
2.??? how???
3.not sure?
4.one returns 50 the other returns 25


3.4 Exercises

1.
def f(x,y):
 return (x+' '+y)
2.I can do this.
3.
def rightJustify(s,w):
 return ((w-len(s))*' '+s)
4. dont get it
5. returns 2
6.21?, nothing
7.???
8.len(0), len((0))


3.5 Exercises

1.
def mystery(x,y):
  return x//y
2.
def mystery(x,y):
  return x/y
gives you division
3.
def test(a,b):
  return (a+b)/2
4.b=1 a=2
5.nope
6.don't get it
7.
from math import sqrt
def quadtratic(a,b,c):
  return (((-b+sqrt(b**2-4*a*c))/(2*a), ((-b-sqrt(b**2-4*a*c))/(2*a))
8.
9.


4.2 Exercises

1.add 2 starting from 1. 1+2n
2.1 over 2 times 3n
3.1,2,4,8,16 (1*2n), 1,4,16 (1*4n)
4.36
5.1:3
6.1+11k=1024
k=93
93(21)+1=1954
7. the difference is the same...
8. does it want me to give an example or prove it? not sure how to prove it
9.they can be. multiplication by 1 (addition by 0)
10. limit is 1
11. at 1?
12.1


4.3 Exercises

1. the middle term
2.what?
3.1
4.okay.
5.huh?
6.6543210
7.2^n-n
8.?


4.4 Exercises

1.1
2.yes? to 1/100?
3.??
4.less than 1 but greater than 0
5.2, i think, guessing here
6.i think at 2, not sure
7.there is a limit on the area and the perimeter i believe


4.5 Exercises

1.

יום שלישי, 7 בפברואר 2012

Programming in Python Chapters 1+2

1.2 Exercises

1.empty set, {a}, {a,b}, {b}
2.7, 25(?), n!+1(?)
3.f(x)=2x for 0<x<6
4.Can't really think of one, but I'm pretty sure it's possible.
5.Same thing ^^
6.f(x)=x%3
7.f(A)= ???
8.uh?
9.f(x)= if even -1 else return?
10.return all 1 lengthed substrings...
11.??
12.f(x)=1/x

1.3 Exercises

1.all reals except 2, range all reals except 0
2.domain all reals equal to or more than -1, range all positive reals
3.domain from -1 to 1, range all positive reals
4. domain from 100 to 999 (900 elements), range from 1 to 27 (27 elements)
5.f(x)=xsquared +1
6.f(x)=x??
7.what do you mean?
8.recursive; if f(x) isnt between -1 and 1 then f(x/10)
9.1,2
10.too-much-ahh...

1.4 Exercises

1.power, !
2.
c<-1
result<-0
while c<n
    result+=c
return result
3.
p<-0
r<-0
while n>m
  p+=1
  m-=n
r<-m
4.
result<-1
z<-0
while z<n
  result*=n
return result
5.
p<-0
result<-0
while result<=n
   result*=2
   p++
return p-1
6.
compare letters, then lengths.

1.5 Exercises

1.ITS MOD!!!!!.......
2.
def incrementByOne(n):
 return n+1
3.absolute value...
4.
def sum1ToN(n):
   return ((n+!)*n/2)
5.
def reciprocal(x)
  return 1/x
6.12,11
7.No.
8.it multiplies the string.
9.
def imSickOfWorkingIWantToSleep(n):
  return n[0]
10.returns first character
11. gives the appropriate functions...
12. 0,3
13.
def sum1ToN(n):
   return sum(range(n))+n
14.
def numDigits(n):
k=1
j=10
while j<k:
    j*=10
    k+=1
return k

2.2 Exercises

1. I can't.
2. D
3.234,375
4.4,8,256
5.ASCII has 128 characters. 1 byte is enough. 7bits is exact
6.??
7.BX is 15 and AX is 6. not really sure what this code computes though, maybe turns things into hexa from deci?
8.uhh I don't know assembly that well...
9.^^^

2.3 Exercises

1.Syntax which is uneeded
2.Yes they work
3.returns 4
4.power function
5.connectes them
6.121212, it repeats the string
7.order of operations
8.(x-2)**3+3x
9.function than other external operations
10.after product and quotients

2.4 Exercises

1.????
2.def, return, while
3.need colon and return is capitalized
4.
One is better than
none; two is better than one
5.Python is #1
6.not sure.
7.
def firstLast(s):
    return (s[0]+s[-1])
8.
def triangle(s):
    print (5*s/3*s/s)


cool.

יום שני, 12 בדצמבר 2011

Hash Tables, Maps, and Sets

8_1
No

8_2
Arraylists. Maybe queues, but that's pushing it.

8_3
you could have a temp which checks all the objects in a queue, and then adds them into another queue, if the object is the same as what you are looking for, you add it twice, otherwise you continue dumping everything into the other queue, which then  becomes your base queue for next time the method is called.

8_4
I believe they are called hash tables because they split the data into parts. I honestly still don't completely understand the process.

8_5


יום שני, 28 בנובמבר 2011

Queues & Heaps


QUEUES & HEAPS
Queues

7_1
Yes it works in the FIFO behavior.
7_2
Using implementation of LinkedLists is ideal because they are very flexible at adding new objects at the front and the back, in retrospect I am not sure why you couldn't also use ArrayLists. I am not sure how to calculate the BigO here.
7_3
The add() method adds to the beginning whilst the addLast() adds to the end. I believe addLast() was used because in the case of Queues, adding means adding to the end.
7_4
I had to look at the API.
import java.util.ArrayList;
public class ArrayListQueue implements Queue 
private ArrayList list;

public void ListQueue() 
    list = new ArrayList(); 
}//constructor

public void enqueue(Object x) 
    list.add(x); 
}//enqueue

public Object dequeue()
    return list.remove(0); 
}//dequeue

public Object peekFront()
    return list.get(0); 
}//peekFront

public boolean isEmpty() 
    return list.size() == 0; 
}//isEmpty

}//class ListQueue

7_5
Ease - Almost the same ease, almost all the methods were still one liners.
Efficiency - Not a change at all, ArrayLists still get the job done and the ease of writing its code is not much harder.

Heaps

Started.

Binary Trees 2

6_6