Files
TMA4135/exercise8/lib.typ
2025-10-12 18:44:32 +02:00

34 lines
874 B
Typst

#let title(cont, size: 18pt) = align(center)[
#text(size: size * 2, weight: "bold")[#underline[#cont]]
]
#let butcher(s, nums) = {
let nums = nums.map(x => if type(x) == float or type(x) == int {
$#x$
} else { x })
table(
stroke: (x, y) => if x == 0 and y == s {
(right: 0.7pt + black, top: 0.7pt + black)
} else if x == 0 {
(right: 0.7pt + black)
} else if y == s {
(top: 0.7pt + black)
},
align: (x, y) => (
if x > 0 { center } else { left }
),
columns: s + 1,
$0$, ..range(s).map(x => none), // first row
..range(2, s + 1)
.map(i => {
let p(i) = calc.floor(i * i / 2 + i / 2 - 1)
(
nums.slice(p(i - 1), p(i - 1) + i),
range(i, s + 1).map(x => none),
).flatten()
})
.flatten(),
none, ..nums.rev().slice(0, s).rev() // last row
)
}