
Saturday, 22 May 2010
Google snooping WiFi? Don't panic! Don't panic!

Sunday, 28 March 2010
Wishing for a destructor (C#)
But, I have a pet peeve that I miss from C++.
Sunday, 28 February 2010
Paying for Power

In England, and most of the western world, we have a well established system of sending electricity from the power stations to me and sending money in the opposite direction. It works, but I think we can improve on it.
Saturday, 23 January 2010
The Making of an Evil Genius

I wasn't performing on stage though. Instead, I was in charge of the music. We had a cassette of all the music and the children on stage would sing along. I would press play when its time to sing and after, position the cassette for the next song.
I wouldn't know it at the time, but it would be this rather mundane task that taught me one of the most important lessons of my life.
Monday, 7 December 2009
is, then as (C#)
The C# language has a pair of related operators, is and as. Say you have an object, x, and you want to know if its really type Form underneath.
(x is Form) will be true if it is, or false if it isn't. The as operator will actually perform the conversion, returning null if it can't be converted to that type.
One common piece of advice to C# programmers is to avoid using the is operator. Here's how both of these operators are typically used together.
While the code works, all the is operator is doing is performing an as operation, and checking if the result is null or not. In other words, (x is Form) is equivalent to (x as Form != null). This means the code above is really saying...
(x is Form) will be true if it is, or false if it isn't. The as operator will actually perform the conversion, returning null if it can't be converted to that type.
One common piece of advice to C# programmers is to avoid using the is operator. Here's how both of these operators are typically used together.
if (x is Form) { Form frm = x as Form; /* Use frm. */ }
While the code works, all the is operator is doing is performing an as operation, and checking if the result is null or not. In other words, (x is Form) is equivalent to (x as Form != null). This means the code above is really saying...
Sunday, 29 November 2009
Computers are fast!
Killer Sudoku is a popular variant on the perennial Sudoku game found in British newspapers. The same rules about the numbers 1 to 9 appearing only once in row, column and 3x3 box still apply, but unlike Sudoku, the puzzle doesn't come with any numbers filled in. Instead, cells are groups with dotted lines and the total of all those cells are written in.
Here's part of a puzzle. The two cells grouped by a 10 could be 1+9, 2+8, 3+7 or 4+6. (It can't be 5+5 because that would mean two 5s in same box.) Not a lot to work on, but also look at the three cells grouped by a 23 in the same 3x3 box; The only possible fit is 6+8+9. This means the only possible fit for the 10 group is 3+7, as all the possibilities would clash with the 6,8 or 9 required to make the 23.
I could go on. If you want to complete the puzzle, its the Guardian's puzzle number 166. The point of this article isn't to solve the puzzle, but something I observed along the way.
Here's part of a puzzle. The two cells grouped by a 10 could be 1+9, 2+8, 3+7 or 4+6. (It can't be 5+5 because that would mean two 5s in same box.) Not a lot to work on, but also look at the three cells grouped by a 23 in the same 3x3 box; The only possible fit is 6+8+9. This means the only possible fit for the 10 group is 3+7, as all the possibilities would clash with the 6,8 or 9 required to make the 23.
I could go on. If you want to complete the puzzle, its the Guardian's puzzle number 166. The point of this article isn't to solve the puzzle, but something I observed along the way.
Subscribe to:
Posts (Atom)
