Categories
python wisdom

Project Euler Problem 25 Pitfalls

Project Euler problem 25 is reasonably straighforward. It asks you to find the first term in the Fibonacci sequence with more than 1000 digits. In ones like these, not reading the question properly is more likely to be your downfall than anything else. So:

  • Give the number of the first term which has 1000 digits, not the 1000-digit number itself
  • Make sure your Fibonacci number generator gives you the sequence correctly: ie F(1)=1 and F(2)=1. If you have F(1)=1 and F(2)=2, you’ll be off by one!
  • Lastly, and this only really applies to my own thickness… If the comment for your Fibonacci number generator says “returns nth Fibonacci number”, make sure it returns the nth Fibonacci number and not a Fibonacci number less than n.
  • If you’re getting a number greater than 5000 you’re off, recheck. Good luck!

Categories
linux

Lenny to Squeeze Upgrade Problems

http://linux-knowledgebase.com/en/Tipoftheday/February/error23errorwhileparsingnumber
saved my server. It wasn’t booting after an upgrade to Debian Squeeze, despite following the upgrade instructions. Connecting to the serial console showed there were problems with finding root (grub error while parsing number, error 23) which was at md1.

Changing the first line to root (hd0,0) and adding initrd /boot/initrd.img-2.6.32-5-amd64 allowed the system to boot normally. I’m not sure why grub-setup didn’t add the initrd line, but I can forgive that as it’s working now.

Remember to update grub’s config once you have it booting.

Categories
linux tech

Correct Way To Iterate Over Files In Bash

Because I keep forgetting, here’s a reminder to myself of the correct way to iterate through files and directories in bash, even considering spaces in filenames, whith a hat-tip to Thomas Howard Uphill:

find . -type f|grep .ext$ |while read file
do
/do/something/to "$file"
done

Silly rabbit.

Categories
all posts

Virtual Multiblog and .htaccess

TLDR: RTFM (http://striderweb.com/wp-content/multiblog/multiblog-readme.htm#permalinks)

I had problems with permalinks and Virtual Multiblog (yet another linky), basically that for every wordpress instance I added I would have to add another set of permalink-related Apache Rewrite rules to prevent individual entries 404-ing. This was fragile and prone to failure. Fortunately, there is a Proper Way To Do It:

RewriteEngine On
RewriteCond %{REQUESTURI} (/blog|/news)?/
RewriteCond %{REQUEST
FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . %1/index.php [L]

 

From the readme. Lovely.