Amb: Difference between revisions
m
→Versatile
Cyril Nocton (talk | contribs) |
m (→Versatile) |
||
Line 2,719:
=ret
}
a=(1, 2, 3)
b=(7, 6, 4, 5)
Line 2,741:
Print "Small Pythagorean triples problem:"
a=range(1,11)
b=a▼
z=a▼
failure=lambda (a, b, z)->{
=not (a^2+b^2=z^2 and b>a)
}
all=amb(Any,failure, a,
k=each(all)
while k
Line 2,752 ⟶ 2,750:
Print z#str$()
end while
a=range(1,6)
c=range(0,6)
failure=lambda N (a, b, c, d, e)->{
=not (a+b+c+d+e=N and a>=b and b>=c and c>=d and d>=e)
▲ }
all=amb(Any,failure, a, a, c, c, c)
k=each(all)
document ret$
while k
z=array(k)
ret$=replace$("+0", " ", z#str$("+"))+" ="+str$(N)+{
end while
Print #-2, ret$
clipboard ret$
}
AmbFunction
Line 2,761 ⟶ 2,774:
that thing grows slowly
Small Pythagorean triples problem:
3 4 5
6 8 10
5+4 = 9
5+3+1 = 9
4+4+1 = 9
5+2+2 = 9
4+3+2 = 9
3+3+3 = 9
5+2+1+1 = 9
4+3+1+1 = 9
4+2+2+1 = 9
3+3+2+1 = 9
3+2+2+2 = 9
5+1+1+1+1 = 9
4+2+1+1+1 = 9
3+3+1+1+1 = 9
3+2+2+1+1 = 9
2+2+2+2+1 = 9
</pre>
|