Tuesday, January 16, 2007

'Bogus' Programs

Computer algorithms:

Sorting
~~~~~~~
Random Sort:
RandomSort(int[] array)
{
do
{
array=random_permutation(array)
} while(!isSorted(array))
return array
}
Takes an array...permutates it in a random manner...n chks 2 c if its sorted. If its sorted, returns sorted array...ppl myt say dat dis algorithm will take infinitely long tym 2 xecute....but den again, it cud also return da correct array @ de first try...cudn't it? its ol a matter of perspective....of kourse, if u hav mah perspective on lyf, ur gonna end up wr8in bogus progrramzz


Lucky Sort
LuckySort(int [] array)
{
//Assume array is sorted
return array
}
This is lucky sort...a sort dat is inherently lucky...it is so lucky dat ne array u send it is olredy sorted....if it's not, it's assumed 2 be olredy sorted (ol a matter of perspective)

Bozo Sort
BozoSort(int[] array)
{
do
{
swap(randomElement1,randomElement2)
pray
} while(!isSorted(array))
}
This plucky little fellow...randomly chooses two array elements and then decydes 2 swap dem...4 no apparent reason...den he follows it up wit a little bit of prayin n den checks is da array is sorted...as wit random sort...it CUD giv u da correct array on da 1st try...(perspective)...

Stooge Sort
A terribly nyc sort algorithm that swaps the top and bottom items if needed, then sorts the bottom two-thirds, then the top two-thirds, then the bottom two-thirds again, n if required, does it again, and again, and again....persistent lil bugger.....but outsyd mah computing limits...

Searching
~~~~~~~~~
We hav ol heard of Binary search n linear search...now presenting..

Eyeball Search
EyeballSearch(int[] array, int element)
{
print " what do u think i am? some sort of searching algorithm? Search 4 it urself, u lazy git.."
print '_|_'
}
Axepts an array n an array element 2 be surched 4...den gives user da finger....4ces da user 2 look 4 da element wit one's own optical sensors...on da bryt syd, gets u sum xercyse...
Peace, Yo!

No comments: