Rules for making change

It happens a million times a day.  Somebody pays cash for something and gets change.  But there are rules, and Raymond’s friend seems to like to break those rules.  Luckily for Raymond’s friend, one of the rules is the customer is always right… or as Mr. Krabs would say, the money is always right.  This…

0

How to turn on HDCP or SCMS in an audio playback app

There’s an MSDN sample of how to turn on HDCP or SCMS in a playback app.  The sample is loosely based on a test app I wrote, but there are still some rough edges.  For example, the CMFAttributeImpl<T> template is not part of the SDK or the DDK.  Also, there’s a leak in the GetDigitalAudioEndpoint…

1

Perl one-liner: approximate pi via Monte Carlo method

http://programmingpraxis.com/2009/10/09/calculating-pi/ >perl -e”print 4/(map{$n+=rand()**2+rand()**2<1}1..pop)*$n” 5000 3.1336 59 characters, plus arguments.

0

Nitpicking László Polgár’s Chess: … #1071

I was reading László Polgár’s excellent book Chess: 5334 Problems, Combinations, and Games and ran across #1071, White to move and mate in 2: The purported solution is… 1. ♘xf6+ ♚xf62. ♕f7# … which, indeed, works – and there is no other mate in two that I can see – so why blog this? Because there’s…

2

Forcing Windows to install on a single partition

If you’re installing Windows via a boot DVD, and you choose Custom, you have the option to rearrange partitions.  I like use this to have each drive be one big partition. Windows 7 wants to set aside a 100 MB partition for something-or-other.  I’m sure there’s a very good reason for this but I am…

1

Tweaks I make every time I install Windows

As preparation for moving one of my machines from Vista to Windows 7, I’m compiling a list of all the little tweaks I like to make to machines that I use a lot: Boot from the Windows DVD.  Delete all partitions; make each hard drive one big partition.  (Hmm… apparently Windows 7 really wants a…

9

How to calculate a sine sweep – the right way

Three quarters are better than a dollar because they make noise!    — Lilly, Lilly’s Purple Plastic Purse Last time I talked about how to calculate a sine sweep mathematically.  There’s a closed-form solution which is quite elegant but, alas, useless in a practical computer implementation due to the very big numbers that are being fed…

4

Bad Perl: locker problem

Bad Perl solution to the “print the open lockers” problem: perl -e”print join’, ‘,map{$_*$_}1..sqrt pop” 100 54 characters.  I prefer this to the 53-character solution obtained by omitting the space after the first comma. EDIT: 49 characters: perl -e”print map{$_*$_,’ ‘}1..sqrt pop” 100 EDIT: 48: perl -e”print map{$_*$_.$/}1..sqrt pop” 100 EDIT: 47: perl -e”map{print$/.$_*$_}1..sqrt pop”…

0

How to calculate a sine sweep – the wrong way

Suppose you want to generate a continuous sine-sweep from time tstart to time tend. You want the starting frequency to be ωstart, and the ending frequency to be ωend; you want the sweep to be logarithmic, so that octaves are swept out in equal times. (The alternative would be to sweep linearly, but usually logarithmic…

4

Bad Perl: Josephus problem

Another programming contest asks to solve the Josephus problem. Bad Perl solution (83 characters… so close…) >perl -e”@_=(1..$ARGV[0]);++$c%$ARGV[1]?$i++:splice@_,$i%=@_,1while$#_;print@_” 40 328 EDIT: got it down to 80. >perl -e”@_=(1..shift);++$c%$ARGV[0]?$i++:splice@_,$i%=@_,1while$#_;print@_” 40 328 EDIT2: 78 dropping the parentheses. >perl -e”@_=1..shift;++$c%$ARGV[0]?$i++:splice@_,$i%=@_,1while$#_;print@_” 40 328 EDIT3: 66, shamelessly cannibalizing others’ ideas from the contest (though I refuse to use “say”) >perl…

1