Working on a WordPress theme from scratch!
It’s a bit slow going but I’m sure I’ll get there without too much trouble. So far I have a basic blog roll implemented, next to add the login link so it isn’t completely useless.
That’s all for now!
–G
Working on a WordPress theme from scratch!
It’s a bit slow going but I’m sure I’ll get there without too much trouble. So far I have a basic blog roll implemented, next to add the login link so it isn’t completely useless.
That’s all for now!
–G
So a new friend has posed a programming challenge to me:
given an array with positive and negative
numbers, find the best place to split it into two parts
such that the new arrays have a sum that is as close together as possible.Example: [5, -6, 3, 2, 4, 6]
For the above data, the splitting point would be right between the 4 and the 6.
Let’s see how long it takes me to get a working script… and how well it works.
A friend came across a question during an interview that I knew I could solve in JavaScript. When I get some time I’ll write this in PHP as well.
This simply takes repetition of characters and compresses it to be the number of repeating occurrences followed by the character that is repeated. For example “xxxyyyz” becomes “3x3y1z”.
This may not have much immediate use, but I’ll be modifying it for MUD speedwalk-like usage. For example “open east; east; south; south; west; enter portal; north; west; north; west” would become “open east; e2sw;enter portal;nwnw” configurable with the MUD client speedwalk character or the MUD-specific “run” command. I’ll probably write an AJAX/PHP based version that receives this type of string and expands it, basically creating a “run” type command usable for any MUD.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | var str = prompt("Please input a string to compress: ", "xxxyyyz"); function compress( long ){ if( long.length <= 1 ) { if( long.length < 1 ) { return ""; } else { return "1" + long; } } var strAry = long.split(''); var char = strAry[0]; var count = 0; var iter = 0; for( iter; iter < strAry.length; iter++ ){ if( strAry[iter] != char ){ break; } } return iter + char + compress( long.substring(iter) ); } alert(compress(str)); |
Or, without using recursion…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var str = prompt("Please input a string to compress: ", "xxxyyyz"); function compress( long ){ var ret = ""; while( long.length > 0 ){ var strAry = long.split(''); var char = strAry[0]; var count = 0; var iter = 0; for( iter; iter < strAry.length; iter++ ){ if( strAry[iter] != char ){ break; } } ret += iter + char; long = long.substring(iter); } return ret; } alert(compress(str)); |
Welcome to my blog!
Here I will blog about various topics, most often it will be code related.
Enjoy your stay and feel free to leave any feedback!
–Greg