Pascal's triangle/Puzzle: Difference between revisions

Content added Content deleted
m (→‎{{header|Factor}}: add works with template)
(Added 11l)
Line 17: Line 17:
Write a program to find a solution to this puzzle.
Write a program to find a solution to this puzzle.
<br><br>
<br><br>

=={{header|11l}}==
{{trans|D}}

<lang 11l>F e(&x, row, col) -> &
R x[row * (row + 1) I/ 2 + col]

F iterate(&v, &diff, do_print = 1B)
V tot = 0.0
L
e(&v, 0, 0) = 151
e(&v, 2, 0) = 40
e(&v, 4, 1) = 11
e(&v, 4, 3) = 4

L(i) 1..4
L(j) 0..i
e(&diff, i, j) = 0
I j < i
e(&diff, i, j) += e(&v, i - 1, j) - e(&v, i, j + 1) - e(&v, i, j)
I j != 0
e(&diff, i, j) += e(&v, i - 1, j - 1) - e(&v, i, j - 1) - e(&v, i, j)

L(i) 1..3
L(j) 0.<i
e(&diff, i, j) += e(&v, i + 1, j) + e(&v, i + 1, j + 1) - e(&v, i, j)

e(&diff, 4, 2) += e(&v, 4, 0) + e(&v, 4, 4) - e(&v, 4, 2)

L(i) 0 .< v.len
v[i] += diff[i] / 4

tot = sum(diff.map(a -> a * a))
I do_print
print(‘dev: ’tot)
I tot < 0.1
L.break

V v = [0.0] * 15
V diff = [0.0] * 15
iterate(&v, &diff)

V idx = 0
L(i) 5
L(j) 0..i
print(‘#4’.format(Int(0.5 + v[idx])), end' I j < i {‘ ’} E "\n")
idx++</lang>

{{out}}
<pre>
dev: 73410
dev: 17968.6875
dev: 6388.46484375
dev: 2883.337402344
dev: 1446.593643188
...
dev: 0.136503592
dev: 0.125866452
dev: 0.116055273
dev: 0.107006115
dev: 0.098659977
151
81 70
40 41 29
16 24 17 12
5 11 13 4 8
</pre>


=={{header|Ada}}==
=={{header|Ada}}==