בתשובה להאייל האלמוני, 20/07/04 16:21
בהצלחה 234639
calc := function(pairs, ops)
local l, i, p, op, x, y, r, ind;

l := [1,2,3,4,5];

for i in [1..4] do
p := pairs[i];
op := ops[i];
x := l[p‏1];
y := l[p‏2];

if op=1 then r := x+y; fi;
if op=2 then r := x-y; fi;
if op=3 then r := x*y; fi;
if op=4 then
if y = 0 then r := 999999; else r := x/y; fi;
fi;

l[p‏1]:=r;
ind := [1..6-i]; RemoveSet(ind, p‏2);
l := l{ind};
od;

return l‏1;

end;

allpairs := Cartesian(Arrangements([1..5],2), Arrangements([1..4],2),
Arrangements([1..3],2), Arrangements([1..2],2));
allops := PermutationsList([1..4]);

for pairs in allpairs do for ops in allops do
c := calc(pairs, ops);
if c = 26 then Print(pairs, " ",ops, "\\n"); fi;
od; od;

הקופי-פייסט הרס את העימוד, מצטער. אם מישהו ממש מתעניין אני יכול להסביר מה יש פה, אבל נראה לי שכבר נסחפנו מספיק. לעניין האלגנטיות, נכון: זה חפוז ומכוער ממדרגה ראשונה; הקצבתי לזה כרבע שעה.

חזרה לעמוד הראשי המאמר המלא

מערכת האייל הקורא אינה אחראית לתוכן תגובות שנכתבו בידי קוראים