面白いものがあったので…

http://gigazine.net/index.php?/news/comments/20081021_headwaters/
最後のほうに乗っている質問をPython使って解いてみる。
確認環境はpython2.5。
取り合えず第一問…それにしても俺のコード汚いなぁ。

ageMultiply = 36
result = 

print '3人の年齢を掛けた数値:' + str(ageMultiply)

for n1 in xrange(ageMultiply):
    if n1 and ageMultiply % n1 == 0 :
        ageDivision1 = ageMultiply / n1
        for n2 in xrange(ageMultiply):
            if n1 <= n2 and ageDivision1 % n2 == 0 :
                ageDivision2 = ageDivision1 / n2
                if n2 <= ageDivision2 :
                    tempList = 
                    tempList.append(str(n1))
                    tempList.append(str(n2))
                    tempList.append(str(ageDivision2))
                    tempList.sort()
                    result.append(tempList)
for anser in result:
    print anser

結果

3人の年齢を掛けた数値:36
['1', '1', '36']
['1', '18', '2']
['1', '12', '3']
['1', '4', '9']
['1', '6', '6']
['2', '2', '9']
['2', '3', '6']
['3', '3', '4']

年下の二人がお古を着まわせて番地の数字になりそうな年齢の組み合わせは…
['2', '3', '6']
['1', '4', '9']
辺りかな?