Showing posts with label algorithms. Show all posts
Showing posts with label algorithms. Show all posts

Friday, July 27, 2007

reverse an integer (in a crazy way)




compare this with my really old post about the same problem

Friday, January 26, 2007

Java: find nested balanced tags

Problem:
I needed to parse out some divs from a html page, and java's regex cant do it. atleast when you have arbitrary number of nested balanced elements.

Solution:

Use at your own risk.

Monday, November 27, 2006

quick mod by 11

1==1 (mod 11)
10==-1 (mod 11)
100==1 (mod 11)
1000==-1 (mod 11)

Therefore 123456 == 6 - 5 + 4 - 3 + 2 - 1 (mod 11) == 3 (mod 11)
Obviously you may need to do a further % operation after adding and subtracting digits, but it should be reasonably fast.

Thursday, February 09, 2006

A cool function

I wish i saw this when i had to do java homework, it would have helped.
to bad i never had to since reverse any numbers.