Problem 39

Problem 39

If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p <= 1000, is the number of solutions maximised?

Kolejny problem rozwiazany:

[code=ruby]#!/usr/bin/env ruby
P = 1000

+

|\

b | \ c

| \

±–+

a

t = Array.new(P+1, 0)
(1…P).each do |a|
(1…P-a).each do |b|
c = Math.sqrt(aa+bb).floor
t[a+b+c] += 1 if a+b+c <= P && aa+bb == c*c
end
end
n = t.max
p = t.index { |m| n == m }
puts “p=#{p}, n=#{n}”[/code]