Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.programming Subject: Re: are you interested in number theory AND programming Date: Sat, 13 Jun 2020 17:02:45 +0100 Organization: A noiseless patient Spider Lines: 61 Message-ID: <87k10boswq.fsf@bsb.me.uk> References: <2122d884-f04b-42f8-b95a-a257b61fef86o@googlegroups.com> <3a3b6135-9e6e-42f5-8088-2774a660f504o@googlegroups.com> <87wo4bp8xo.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="9914b4f20b45521076a678e7fa6ca915"; logging-data="6556"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UPmZIWbX/M+HBTPwuUjz70uUwN3VG+L4=" Cancel-Lock: sha1:CHMSNFFSFD6jIgTQO9hizhPBfXw= sha1:0UOhzNLbD5nD0pxOyUn01caFc3o= X-BSB-Auth: 1.6ded4950bac0e042adbf.20200613170245BST.87k10boswq.fsf@bsb.me.uk Xref: csiph.com comp.programming:10924 syedanwarowais5@gmail.com writes: > As part of a (hopefully growing) exploration in number theory, I need > to find solutions to the following diophantine equation : > ab(a+b)=cd(c+d) (in positive integers) > The first solution set is a=1,b=5 and c=2,d=3. > I know there are several more solution sets, though I don't know if > there are an infinite number of solutions sets to this diophantine > equation. > Would you like to write a program to solve this puzzle? It's quite interesting. Here's a first stab using Haskell (I always use Haskell for this sort of investigation): import System.Environment psum (a, b) = a * b * (a + b) get_b_from product a = (floor (sqrt(fromIntegral (4*a*product + a^4))) - a^2) `div` (2*a) possible_pairs_from product = takeWhile (\(a, b) -> a <= b) $ map (\a -> (a, get_b_from product a)) [1..] actual_pairs_from product = filter ((==product).psum) $ possible_pairs_from product solution_list = filter ((>1).length) $ map actual_pairs_from [2,4..] main = do [n] <- getArgs mapM (putStrLn.showSolution) $ take (read n) $ solution_list where showSolution s = foldl1 (\s1 s2 -> s1 ++ " " ++ s2) $ map show s The first 10 solution sets this program finds are: (1,5) (2,3) (1,14) (3,7) (1,15) (2,10) (4,6) (2,13) (3,10) (1,20) (5,7) (1,21) (3,11) (3,15) (6,9) (2,20) (5,11) (4,14) (7,9) (3,17) (5,12) and there are a few 6-pair solutions that come up: (1,384) (6,154) (8,132) (14,96) (28,60) (40,44) (9,231) (12,198) (21,144) (22,140) (42,90) (60,66) (6,385) (15,238) (23,187) (46,119) (51,110) (69,85) > Once you respond, I will go deeper into the mathematics this connects > to. Probably best not to hold back like this. Just make it fun with as much information as you can. That will encourage more responses. -- Ben.