Diary for mettw

Older blog entries for mettw (starting at number 14):

30 Aug 2000  »

Grab a copy of esr's Ethics from the barrel of a gun and run the following sed script on it:

sed -e s/[gG]un/Penis/g -e s/[bB]ear/Dangl/g -e s/[aA]rms/Phaluses/g -es/[tT]rigger/Glans/g gun-ethics.html > penis-ethics.html

It's the funniest thing you'll read all day. You can see a copy of it at my web site.

12 Aug 2000  »

The coconut problem

Yep, you all got it - it's too easy for people who know mathematics. bwtaylor's solution skipped a few dozen steps, so here's a more complete solution:

Each sailor gets n coconuts,

So before they split up the pile there were 5n+1 coconuts
Before the 5th sailor split up the pile there were (5/4)(5n+1)+1
Before 4Th sailor (5/4)((5/4)(5n+1)+1)+1
Before 3 (5/4)((5/4)((5/4)(5n+1)+1)+1)+1
Before 2 (5/4)((5/4)((5/4)((5/4)(5n+1)+1)+1)+1)+1
Before 1 (5/4)((5/4)((5/4)((5/4)((5/4)(5n+1)+1)+1)+1)+1)+1
which is the original number of coconuts, N.

N = (5n+1)(5/4)^5 + (5/4)^4 + (5/4)^3 + (5/4)^2 + (5/4) + 1
= 15n + 11 + (n+1)/4 + (n+1)/128 + (n+1)/1024

Since 4 and 128 are both multiples of 1024 we can simply say

n = 1024c-1, c = 1,2,...

N = 15625c - 4, c = 1,2,...

The seven bridges of Koenigsberg

This one is a classic from topology. In the Prussian city of Koenigsberg (Modern ???) there are two islands in the river with seven bridges thus:

        
     ---v--v-------v----
    /   |  |       |    \
   /  --^--^---  --^--   \
---   |       |  |   |    -------
      |       >--<   |
---   |       |  |   |    -------
   \  --v--v---  --v--   /
    \   |  |       |    /
     ---^--^-------^----

A popular passtime of the inhabitants was to try to cross every bridge only once. Prove that it can not be done.

Ha! The thirteen coin problem!

bwtaylor:
It's possible to do this with thirteen coins. Work that one out! 8)

Hmm... Well you'll be having trouble - It can't be done. I didn't count up how many coins were being measured in each go, obviously the scales are supposed to balance with each measure, but mine weren't. 12 is the maximum.

At most you can search for (((3^n)-1)/2)-((((3^n)-1)/2)%2) coins so that the scales will balance. Searching for ((3^n)-1)/2 coins will require an extra measuring to callibrate the scales if it is not divisible by two. The -1 is required to eliminate the zero permutation (where one coin is not measured) since it does not tell us whether the forgery is heavier or lighter

For those who are having trouble with 12 coins, the trick is to stop thinking like a programmer and start thinking like a mathematician. Trying to walk a tree in your head is going to lead you no-where.

rillian's frog

It would have to be induction with the frog being perpendicular to the field and, my intuition says, there should be some resitance to rotation. But don't flame me if I'm wrong - It's been five years since I did any physics.

11 Aug 2000  »

bwtaylor on the twelve coin problem:

Sorry, I misread your problem at first... the answer is:

...Damn it! what is the answer?

The coconut problem

Five sailors are shipwreaked on an island and decide that the first thing they should do is look for food. All they find are coconuts and a monkey, so they spend all day gathering up the coconuts and then decide to split them up tomorrow morning.

During the night one of the sailors wakes up and thinks to himself, "If I don't take my share of coconuts now then one of the others will steal them." So he divides the coconuts up into five piles and has one left over, which he throws to the monkey, hides his share and puts the rest back in the pile.

Later on another sailor wakes up and has the same thought, so he divides the coconuts into five piles with one left over that he throws to the monkey. He hides his share and puts the rest back into a pile.

Throughout the rest of the rest of the night each of the other sailors wakes up and has the same thought, and each time there is one coconut left over which they throw to the monkey.

The next morning the pile of coconuts is obviously smaller, but they are all guilty so none of them says anything. They divide up the coconuts into five piles and again there is one left over that is thrown to the monkey.

How many coconuts were there?

8 Aug 2000  »

Over on cnet they have an Article about publius, a freenet like system from AT&T. When talking about the criminal uses of it they say:
But the AT&T developers say those risks are worth taking, in order to protect free speech.
I don't know about anybody else, but I'm not interested in their opinions, only in demonstrable fact. Ethics has degenerated into each side shouting their own opinions. Or, more commonly, each side creates a set of opinions to justify how they behave.

If the Publius/FreeNet/... developers want us to beleive their assertions then how about they try to come up with some scientific demonstrations of them. The fact that none of them has done this yet only leads me beleive that their opinions are merely a justification of what they want to do - not what they should do.

30 Jul 2000  »

miniver

The US constitution is designed to say what the government can't do, or atleast that's the impression I've been given. The Australian constitution on the other hand is a list of things that the government is allowed to do. So if it's not in the constitution the governement can't do it. There are some parralells to the US bill of rights though, burried right in the middle of the constitution is a little clause about religion. I think would could probably do with a debate about whether some of the rights granted in legislation properly belong in the constitution though.

Licenses..

They're at it again... Over at Technocrat they're hasling galeon over using the GPL with the MPL. First of all, the authors can do whatever they like, and can link against whatever they like. They aren't bound by their own license terms and can make exceptions to the GPL at will, so if galeon links against mozilla then the authors are implicitly making an exception for that library. Second of all - What the hell is going through these people's minds? The point of the FSF was to set up a free software community, but by hasling people over the minutia of licensing terms stallman is destroying the free software comminity by breaking it up into little license enclaves and stopping code reuse. Isn't that what Stallman is supposedly fighting against? To me all these debates prove is that the GPL is a garbage bin of Stallmans contradictory beleifs and needs to be replaced with something more consistent with the stated aims of the FSF.

28 Jul 2000  »

dto on CWEB:

While it is possible for people to write modular functions with C, generally it is a pain in the arse because you end up having to pass heaps of parameters and pointers around. It's because of this that people write functions in C that are way too long. CWEB removes that pain because the code from each module is inserted straight into the function where it belongs, so CWEB encourages people to write short modules.

From what you wrote it seems that you are doing a javadoc style system, is that right? Javadoc never produces good code because it encourages people to do a oneliner about the function. CWEB on the other hand provides a place for you to set out your thoughts before starting each modules. I've found that I just started automatically writing down my thoughts in the comment section and then revising it with my new ideas before even writing a single line of code. Given that this comment will be fairly general this also encourages making the code even more modular. When writing the code I just naturally now insert a @<...@>; where some more thought needs to be put into that section of code.

What I'm trying to say is that, for me, CWEB isn't about writing a book. It's about a new method of programming that ensures that your code is highly modular and well documented as well as ensuring that you straighten out your thoughts before writing code. I just don't see those benefits in javadoc style systems.

27 Jul 2000  »

Is free software really all that radical? I'm starting to think that maybe it isn't. Everything goes down in price over time - my father paid AU$1,100 for a Commodore SX-64 (A precursor of the laptop) which today would be lucky to fetch AU$50. Software hasn't depreciated as much as other products, probably because the number of programmers needed increases as you add features.

I think that free software may just be another way for prices to fall. Software companies already give away older versions of their products with the current version being just as expensive as ever. This is akin to cars in that the price doesn't change much but the number of features added keeps on increasing.

The way free software seems to be going with companies is that the company, instead of giving away older versions, gives away a base system and charges for the add-ons. Now since you aren't making any money from the base system it makes sense to make it free software so that you can palm off some of the development work onto free labour. So if free software takes off then the price of the add-ons should come down somewhat.

Free software may be radical from a comercial software company's perspective, but taking a larger view of economics there may not be anything too radical about it at all.

27 Jul 2000 (updated 22 Jul 2006 at 23:10 CDT)  »

21 Jul 2000  »

Finally got the next release of XDBM out. This release puts back all of the node ordering code I had to take out because of performance issues. I had to make some major changes to the code in the process.

I've removed the list of attributes from the node blocks (you can do a search for them if needed) and replaced it with a lastAttribute in the file data. Basically, every node now has a treeNextPos and treePreviousPos stored in file (but not in memory) which points to the next node in tree traversal order. Doing this avoids having to do heaps of tree traversals when setting the dewey for a node.

So if you insert an attribute then XDBM grabs the last child of the last attribute of the parent and uses that as the treePreviousPos and then gets that node's treeNextPos for the treeNextPos of the new node. If you insert a non-attribute then it grabs the treeNextPos of the new node's nextSibling and then gets treePreviousPos from the treeNextPos's treePreviousPos. If there is no nextSibling then we (as a last resort) have to do a basic tree traversal by grabbing the lastChild of the lastChild ... of the lastChild of the new node's previousSibling. You then check for attributes as before.

If this diary entry seemed ever so slightly recursive then welcome to tree land.

21 Jul 2000  »

steved wrote:

Inefficient? Can we have some examples here? Sure, if you declare all your methods virtual, you're going to take a hit on the double indirection for each call. So don't do that. Use virtual only in places where you'd use function pointers in C. There's a more general point here, I think. You can produce unreadable, inefficient piles of cruft in C++, and it may be easier to do than in C. But I think with careful and thoughtful design you can also write easier-to- read code in C++.

What I was refering to was where you have a method prototyped as receiving a string object and then pass it char*. It seemed to me that this would be a pretty simple conversion, but seeing the number of hoops it had to go through was a bit of a shock to the system. It made me wonder what other unexpected gymnastics g++ libraries go through.

In a language like Java I wouldn't mind stuff like that because you get a much cleaner environment to work in. With C I don't mind the pain in the arse debugging because I can optimise everything to death. But with C++ it seems to me that to get the added features of a language like Java you get the stick but not the carrot. If C++ removed the bad aspects of C in return for the tradeoffs mentioned above then I wouldn't mind at all.

On C++ code being more readable, that's true for C coders who don't use literate programming, but not for those who do. I really can't stress enough to others how great CWeb is - everyone should be using it.

5 older entries...

 [ Home | Articles | Account | People | Projects