December 24th, 2009
I came across an article in Wikipedia about Dudeney numbers. These are numbers whose digit sum add up to their cube root:
1 = 1 x 1 x 1 ; 1 = 1
512 = 8 x 8 x 8 ; 8 = 5 + 1 + 2
4913 = 17 x 17 x 17 ; 17 = 4 + 9 + 1 + 3
5832 = 18 x 18 x 18 ; 18 = 5 + 8 + 3 + 2
17576 = 26 x 26 x 26 ; 26 = 1 + 7 + 5 + 7 + 6
19683 = 27 x 27 x 27 ; 27 = 1 + 9 + 6 + 8 + 3
The wiki page went on to proclaim that those are the only six such numbers. Somebody on the talk page asked where the proof was.
I poked on Google and didn’t find anything, so I wondered if I could just prove it myself. Here’s what I came up with off the cuff. Perhaps others would find it interesting.
Read the rest of this entry »
Tags: rebol
Posted in Math, Puzzles | 3 Comments »
December 2nd, 2009
Merely plugging a removable drive into a mac (when it has write access) makes OS/X think it can take the liberty to write a lot of hidden garbage onto that disk. If you want to stop this from happening, you have to put some special files on that disk before you plug it in.
To stop OS/X from doing Spotlight indexing, you need a file called .metadata_never_index in the root directory of the removable drive.
To stop OS/X from making a .Trashes directory, you need to make your own file that *isn’t* a directory and call it .Trashes
To keep it from doing logging of filesystem events on the drive, you need to make a directory called .fseventsd and inside that folder put a single file named no_log
The contents of these files don’t matter, so you can make them empty files using touch. Even better, you could make it a text file with a link to this post, so that you (or someone else) wandering across the files will know what they’re for.
Apple’s choice to do this is incredibly self-serving and shameful. At bare minimum, hidden files and features like these should be off by default for any non-mac-only filesystem formats. They should only be enabled when the user has been made aware of them.
Posted in Uncategorized | 11 Comments »
November 22nd, 2009
Ubuntu has a nice install screen that lets you press F4 for Modes or F6 for Other Options. If you have an older laptop, you may find that you can’t boot unless you turn on “Safe Graphics” or check “acpi=off”.
(Note: In my case, the failure I was experiencing on boot was accompanied by horrible graphic corruption on the LCD. This made me think I’d need safe graphics mode, but that had no effect. It turned out the acpi=off was the setting I needed to get through the boot. YMMV.)
Yet there’s a catch to getting Ubuntu working this way. It may get you through the install, but once you’re finished and try to boot from your hard disk these options aren’t there any more. As of 9.10, it seems that it does not slipstream these settings into the configuration files on your hard disk.
As more of an exercise than anything else, I looked into how to address this after installing Ubuntu onto an old Pentium III laptop. Hopefully it can help someone else. Here goes…
Read the rest of this entry »
Tags: GRUB, Linux, Ubuntu
Posted in Uncategorized | No Comments »
October 26th, 2009
Historically, I have always disliked the idea of using boolean test operations on types that can take a number of values. This deep-seated aesthetic grudge comes from cases like this:
int x = 0;
if (not x)
cout << "X is zero" << endl;
I’m simply bothered by this. Perhaps it’s a cognitive thing where I just don’t feel there’s any “truth” to the idea that every non-zero integer is somehow “true” but zero is somehow “false”. It could just as easily be that negative numbers are false and non-negative numbers are true. Or if you ask a mathematical purist, they might suggest that at a more foundational level it is primes that are true and non-primes are false!
My comfort zone is when I’m only testing for “truth” and “falsehood” those things that can only have the values true and false. If I could, I would enforce this. So in the example above I would always write something more like:
int x = 0;
if (x == 0)
cout << "X is zero" << endl;
That particular example is not very controversial, and I think most programmers would agree with me that’s a better way to test against a literal zero. It’s just better code for capturing the intention.
Yet I have historically considered that a logical extension of “zero is not false” is the premise that “null pointers are not false”. And that belief is contrary to practice:
shared_ptr< foo > fooPointer;
if (not fooPointer)
cout << "fooPointer is null" << endl;
In fact, look what a mouthful you get if you insist on comparing against null literally:
shared_ptr< foo > fooPointer;
if (fooPointer.get() == nullptr)
cout << "fooPointer is null" << endl;
In the past I have tried to work around this by creating inline template wrappers like “isNull()” so that I could stick to my guns and avoid flattening pointers into booleans. It doesn’t cost any more in the runtime, so I figured what’s the harm?
template< class T > inline bool isNull(shared_ptr< T > ptr) {
return !ptr;
}
Yet I’ve decided this is a lost cause and too much of a speed bump in sharing my code with other C++ programmers. They’ve accepted the notion that null pointers are false and non-null pointers are true, and you use boolean logic to test this—not some other operator. It’s not worth it to pick this particular fight.
I’m not happy about it. But I now accept this for pointers only. And I’m going to use “not” instead of “!”… it’s part of the language and a lot more readable.
Posted in C++ | 1 Comment »
August 29th, 2009
Jeremy Friesner brought this site about analog literals to my attention. It provides the long-needed ability to represent integer constants in C++ not as numbers (like 42) but rather as 1-D, 2-D, or 3-D shapes whose length, area, or volume correspond to the number’s quantity. So for instance:
assert( ( o-------------o
|L \
| L \
| L \
| o-------------o
| ! !
! ! !
o | !
L | !
L | !
L| !
o-------------o ).volume ==
( o-------------o
| !
! !
! !
o-------------o ).area * int(I-------------I) );
That’s great! As the inventor of Arecibo ASCII, I fully support this visual double-check with our intuitions about numbers! What if aliens are trying to read our code, but don’t know about our arbitrary choices of digits and numeric base?? This could bridge that important gap!
But there’s one nagging concern I have, which is that I don’t think the 1-D numeric values are very intuitive. Look at these examples from the site:
assert( I-I == 0 );
assert( I---I == 1 );
assert( I-----I == 2 );
assert( I-------I == 3 );
I’d prefer it to more consistently depict the historic concept of zero, and be less arbitrary with the “2N+1″ formula of dashes to implement value N. So why not overload dereference and multiply, and define “II” to be the constant value zero? This way you can get:
assert(II == 0);
assert(I*I == 1);
assert(I**I == 2);
assert(I***I == 3);
The implementation is relatively straightforward from the proposal. But I went ahead and wrote it, and it is complete enough to give errors when compiling invalid literal specifications:
int test1 (I); // compile error!
int test2 (*I); // compile error!
int test3 (I*); // compile error!
int test4 (*I*I); // compile error!
int test5 (I*I*); // compile error!
I hope this makes it more practical for people to apply analog literals to real-world situations! Source below…
Read the rest of this entry »
Tags: cplusplus, humor
Posted in Ideas | 1 Comment »