How to resolve the algorithm Pascal's triangle/Puzzle step by step in the 11l programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pascal's triangle/Puzzle step by step in the 11l programming language
Table of Contents
Problem Statement
This puzzle involves a Pascals Triangle, also known as a Pyramid of Numbers. Each brick of the pyramid is the sum of the two bricks situated below it. Of the three missing numbers at the base of the pyramid, the middle one is the sum of the other two (that is, Y = X + Z).
Write a program to find a solution to this puzzle.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pascal's triangle/Puzzle step by step in the 11l programming language
Source code in the 11l programming language
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.
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++
You may also check:How to resolve the algorithm Draw a rotating cube step by step in the Raku programming language
You may also check:How to resolve the algorithm Largest proper divisor of n step by step in the Julia programming language
You may also check:How to resolve the algorithm Bitcoin/address validation step by step in the Racket programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the Elixir programming language
You may also check:How to resolve the algorithm User input/Text step by step in the NS-HUBASIC programming language