Post Reply 
July 2018 little math problem
07-27-2018, 08:20 AM
Post: #17
RE: July 2018 little math problem
Hello,

Prime version: Brute force, executes in ~7s on my prime.

Code:

Spoiler alert











lstResult;

export recurse(l, p)
begin
  local p1;
  if (p>=6) then 
    p1:= l(1)+l(2)+l(3);
    if (p==6) and (p1 <> l(3)+l(4)+l(5)) then return; end;
    if (p==8) and (p1 <> l(5)+l(6)+l(7)) then return; end;
    if p==9 then
      if p1 == l(7)+l(8)+l(9) then print(string(l)+"->"+p1); lstResult(0):= l; end;
      return;
    end;
  end;

  for p1 from p to size(l) do
    local l2= l;
    l2(p):= l(p1); l2(p1):= l(p);
    recurse(l2, p+1);
  end;
end;

export mth()
begin
  lstResult:= {};
  print("Executed in "+time(recurse(makelist(X, X, 1, 9), 1)));
  print("found "+size(lstResult)+" solutions");
  lstResult;
end;

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
July 2018 little math problem - pier4r - 07-25-2018, 08:52 PM
RE: July 2018 little math problem - DavidM - 07-26-2018, 04:03 AM
RE: July 2018 little math problem - DavidM - 07-26-2018, 03:38 PM
RE: July 2018 little math problem - pier4r - 07-26-2018, 12:36 PM
RE: July 2018 little math problem - pier4r - 07-27-2018, 10:03 AM
RE: July 2018 little math problem - DavidM - 07-28-2018, 04:22 PM
RE: July 2018 little math problem - cyrille de brébisson - 07-27-2018 08:20 AM
RE: July 2018 little math problem - pier4r - 08-01-2018, 02:13 PM



User(s) browsing this thread: 1 Guest(s)