I was recently checking out what dead beef signifies and came across a blog with the name Dead Beef Cafe, which was apparently started by a few friends to talk about computer security, food and geeky stuff. An interesting read from one of the posts was Matt Bishop's writeup on Robust programming. It is quite amazing how most of the code that you would write in the first shot is most likely to be fragile. One of the conclusions I drew after reading the article was that working on Java was so much better than writing code in C! It takes care of so many of the factors mentioned in the article. Well, more on that later..
And of course, dead beef is actually a hexadecimal code 0xdeadbeef which was used by IBM in its RS/6000 series to signify freshly allocated memory. Some modern debugging tools deliberately fill freed memory with this value as a way of converting heisenbugs into Bohr bugs. As in “Your program is DEADBEEF” (meaning gone, aborted, flushed from memory) Some of the other amusing hexcodes that are/were used:
DEADDEAD - A Microsoft Windows STOP Error code used when the user manually initiates the crash.
ABADBABE - Used by Apple as the "Boot Zero Block" magic number (dunno what boot zero block is but that's funny)
C0DEDBAD - A memory leak tracking tool which it will change the MMU tables so that all references to address zero
Thursday, May 7, 2009
Sunday, May 3, 2009
GLAT
The GLAT (that's the Google Labs Aptitude Test) was announced in 2004 in a magazine like an advertise for people who might be intrigued by the test and the questions they saw in it. The test was interesting, one of the more interesting questions though was
Consider a function which, for a given whole number n, returns the number of 1s required when writing out all numbers between 0 and n. For example f(13)=6. What is the next largest n such that f(n)=n?
One of the more obvious solutions:
public static int f(int n) {
int f = 1;
for (int i=2;i<=n;i++) {
int j = 10;
int i1 = i;
while (i1/j > 0) {
if ((int)(i1/j) == 1)
f++;
if ((int) (i1%j) == 1)
f++;
i1 = i1/10;
}
}
return f;
}
Returned the correct answer: 199981
The solution is obviously pretty bad, but I guess I'm gonna improve it only after a good night's sleep :P
Consider a function which, for a given whole number n, returns the number of 1s required when writing out all numbers between 0 and n. For example f(13)=6. What is the next largest n such that f(n)=n?
One of the more obvious solutions:
public static int f(int n) {
int f = 1;
for (int i=2;i<=n;i++) {
int j = 10;
int i1 = i;
while (i1/j > 0) {
if ((int)(i1/j) == 1)
f++;
if ((int) (i1%j) == 1)
f++;
i1 = i1/10;
}
}
return f;
}
Returned the correct answer: 199981
The solution is obviously pretty bad, but I guess I'm gonna improve it only after a good night's sleep :P
Subscribe to:
Comments (Atom)