Project Euler

June 9th, 2009

I’ve been doing the Project Euler puzzles in Python.  Here’s one:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.

My solution turned out to be unique.  Instead of multiplying three-digit numbers, filtering for palindromes, and then picking the largest, it generates palindromes directly by counting down from 999 and “mirroring” the digits to the right:

999999

998899

997799

Since the result will be six digits (nnn * nnn = nnnnnn), the first number in this series that has a three-digit factor must be the answer.  Here’s the code, which returns in under a second:

#!/usr/bin/python
from sys import exit
def mirror(n):
  s = str(n)
  return int(s + s[::-1])
r = range(999, 100, -1)
for i in r:
  pal = mirror(i)
  for j in r:
    if (pal % j == 0) and (pal / j < 1000):
      print pal
      exit(0)


Exams

May 29th, 2009

Got a 96 or better on all my exams, which I suppose shows they weren’t that hard.  Some students took them too seriously — I caught a glimpse of a classmate’s palm as we were discussing the grammar exam afterward:

crib

Soon after exams were finished, I woke up to a flooded living room.  A pipe under the floor had burst and flooded my apartment and the downstairs neighbor’s.  It took three or four days to fix, during which I had no water in my apartment (I showered at the gym).  When the crew were finished, there was an inch-thick layer of concrete dust over everything in my place.  It took a week to clean completely.  I was glad I had done the intensive studying early.

The day after everything was finally patched and cleaned, I went out to get my hair cut.  When I got back, the lock was broken.  The key turned, but the deadbolt wouldn’t retract.  Four hours and $80 later I had a new deadbolt and three new keys.


Shanghai Museum

May 27th, 2009

The Shanghai Museum is free, and I’ve been taking advantage of it to go during the week and just see one room at a time.  Coins, pottery, bronzes, jade.  It’s much more fun to take some time to look at one batch of objects than to try to see everything in two hours (my limit before I get tired of shuffling around).

This is the jade I liked best, it looks like a little Ebisu-sama, the Japanese god of wealth who is always depicted with a fish:

ebisu

If you go to the Shanghai Museum and a young couple or a group of students asks you to take their picture in front of the museum, you might want to say no.  Since I was going every day for a while, I got asked regularly and noticed the same people — who needs that many pictures of themselves?  I searched for “people’s park scam” and found many reports of students inviting foreigners to tea, then asking them to pay the inflated bill, claiming to be poor students.

It feels rude to decline to take a photo, but the last day before I read up on this, I took four photos on my way through the park.  No big deal if you’re only going once, but tedious if you’re going regularly.


Overheard again

May 25th, 2009

Well, it’s not just Chinese people who talk about foreigners thinking they can’t understand.  I got into the elevator here in my apartment building and saw a couple already in there.  As I got on, the guy started saying to his wife, in Japanese,  ”Wow, look at him, he’s really big.  Look how big he is!”  After a few floors of this, I said, also in Japanese, “Be careful, I can understand you.”  He was surprised enough to blurt, “あれ?!”.  His wife didn’t seem surprised (there are lots of expats in my building); she poked him in the stomach as a kind of reproach.


Avatar

May 22nd, 2009

I needed an avatar for the ShanghaiStuff website.

robert

I was playing around in Fireworks  and found that applying Find Edges and then Invert turns a photograph into something that looks like a drawing.  Since I removed some “life” by turning the photo into a sketch, I added some back by animating the result.


Walk to Jing’An Temple

May 21st, 2009

I finished studying around 4:30 this afternoon and decided to go for a walk since the sun had come out while I was working.  I ran into Donna right outside my apartment as I was heading toward HengShan Lu.  About three hours later I ran into her again on PanYu Lu on my way home.

Google Maps now has a “walking” option so you can see how far you went on foot.  Today’s tour was exactly 10 kilometers or 6¼ miles.

jinganwalk

Google’s beta warning for the new feature is especially appropriate for Shanghai:

warning


Further progress

May 15th, 2009

The month-long silence between my return from the Philippines and now was the sound of me studying.  As I mentioned before I went on the trip, I had memorized 500 characters — including pinyin, tones, and hanzi — in a little over six weeks in class.  It seemed like I could do better, so when I got back, I started drilling even more.  A month later, I’ve completed the first-year textbooks and now know 875 characters.  At this pace it will only take…two years before I can read a newspaper.

Studying so much every day really had an effect on my perception of characters.  I had a few interesting epiphanies, for example that the logos for China Telecom

ct

and Bank of China

bc

are both stylized versions of zhōng,

zh

the character that represents the Middle Kingdom.  I had seen that The Bank of China symbol is a version of the old Chinese coins with a square hole, but the resemblance to zhōng was something I hadn’t noticed.  The China Telecom character is supposed to look like a globe, and also like the characters C and T (borrowed from Toyota’s logo?).

I had a bizarre experience while waiting for the elevator.  I was subconsciously counting along with the digital display as the elevator approached my floor:   15, 16, 17…  I only noticed I was doing it because when the display changed to 18, I mentally read it as jiù, the character meaning old.

eighteen


Tongli

May 6th, 2009

Andrew’s friend Tats and his girlfriend were here from Tokyo, so we took a day trip to Tongli, a canal town not far from Shanghai.

The best part was the canal tour.  The guy let me steer/paddle for a while, but those photos are on Tat’s camera.

tongli

One woman on the canal had several trained fishing cormorants with strings tied around their throats.  I wish I had been able to get a picture.


The Great Firewall

April 17th, 2009

I got back from visiting Manny in the Philippines yesterday to find I couldn’t access this site.  It had been blocked by the Great Firewall of China.  I got my host’s support team to change the IP address, so let’s hope it was just a mistake and not criticism from the censors.

Here’s a relevant article from The Atlantic on “The Golden Shield”. I’ve met a lot of people here who don’t know what proxy server is or where to find one and just stop reading various sites they can’t access from China.


Manila and Angeles City

April 8th, 2009

Placeholder for photos from Manny’s niece’s camera.

I had a good time in Makati with Manny, but I’ll never schedule another trip over the Easter weekend — everything was shut down!  Things picked up after the weekend, and I got to see Manny’s family’s new house in Angeles City.

Thanks, Manny!