9.27.2010

Issorted algorithm

This is my version of the isSorted() algoritm.

def isSorted(n,nlist)
hit = true
for a in range(1, n):
if nlist[n] !< nlist[1+n]:
hit = false
return hit

This function will always return the correct answer because the for loop will check every value in the input list. Also, due to the function only comparing numbers n-1 times, the function will complete in finite time.

9.19.2010

Search program

This program will search a list for a give value. Python...
def searchList(inList, val):
hit = false
For x in inList:
if x == val:
hit = true
return hit

This function will always return the correct value as it looks through the entire list. It will also complete in finite time because it compares each value once.

9.12.2010

Program max()

Here is my program for finding the max value of a list in python.

[001]def findMax(inList):
[002]        maxV = inList[0]
[003]        for i in inList:
[004]                if maxV < i:
[005]                        maxV = i
[006]        return maxV


The function will terminate because the for loop is finite because the input inList is also finite.
The function compares the first value in the list with itself. Then it compares that value to the second value of inList. If the new value is larger than maxV, then it becomes maxV. Then maxV is compared to the third value in the list. This continues until all values in the list are compared. So, by comparing every value, the function will return the greatest value.

9.07.2010

Sorting

Sorting a list can be a very easy task, or one that is very daunting.
A method that i found called quicksort, seems to be very efficient, and interesting to think about.

  1. Pick an element, called a pivot, from the list.
  2. Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.
  3. Recursively sort the sub-list of lesser elements and the sub-list of greater elements.
-Taken from Wikipedia.org - Quicksort


So let's take the list:
3 7 8 5 2 1 9 5 4
For a pivot, let us take 5, because we know that that number is halfway between 1 and 9.
In the picture, the red numbers represent all numbers greater than 5, and the blue represent all numbers less than or equal to 5.
5 is first taken out of the list. Then the elements are sorted into the two groups, blue numbers, and red numbers. Next 5 is put back into the list. Now, the blue elements, numbers less than 5, and the red elements, numbers greater than 5, can now be sorted by using this process recursively.

So the first group goes like this:
3 4 2 1 5
5 4 2 1 3
2 4 5 1 3
2 1 5 4 3
2 1 3 4 5
Then the process will occur again, sorting the 1 and 2.

9.01.2010

Smoke in the hallways

So I guess in the dorm was a sweet smell, weed maybe? Whatever it was was having multiple people smell up and down the hallway. I don't think the source was found, but a strong scent of axe body spray came about...

Anyways, a little after midnight and I thought I'd make another post, maybe a little about my hobbies.
I like games and puzzles, particularly ones that make you think in interesting ways, such as a rubik cube, chess, or go. I like other games like Liar's Dice, Set, and even Munchkin from and then.
I also like table games, such as pool. I use to go to a bar and play billiards every other week or so. Ping pong I am also pretty big in, or least will be due to my floor having a ping pong table. I have my own bowling and would use it if I wasn so far away from the MU...
I also play Yugioh, but I'll not get into that.

If there's anything you'd be interested in knowing about me, just comment and I'll see what I can do.
Adios.

8.31.2010

Welcome to the Berk@Blog

Here at ASU, Matt Berk is the name.
Being a freshman is how i started my game.
From the programming to calculus, i really could not get much worse,
but at least if i drop out, i think my tuition gets reimbursed...
Engineering classes are really cool, but make me such a nerd
but at least some intramurals won't make me that absurd.
I only really hope to make it through at least this first semester,
and maybe, just maybe, if i wish really hard, i could even understand one professor.

Anyways...
I am writing this blog for anyone who is interested to here my story, the story of the lonely freshman in a grand party school. It may be just for myself, but maybe someone else will get a kick out of it.
I hope to have a new post once a week. Maybe more, maybe less, depends on how it gets around here.

About me:
So my name is Matt Berk and I'm a native to Arizona, living in Ahwatukee for all of my life. I just graduated from Mountain Pointe High School. My junior and sophomore i hung out with all of my friends, all of the time. It is a big transition coming here to ASU, living at Palo Verde Main and knowing only one other person on my floor. But it also turns out that everyone here in this dorm is also an engineering geek. So I may fit right in.

I'll post again when I have the time, but right now, i have Macro Economics to go to... Adios.