Public
Edited
Jun 4, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
out = {
var blocks = records.split(/Dia [0-9]\n/), map = {}
blocks.shift()
for (var b in blocks) {
map[b] = {}
var lines = blocks[b].split("\n")
if (b != blocks.length - 1) lines.pop()
for (var l in lines) {
var values = lines[l].split(" "), from = values[0], to = values[1]
if (map[b][from] == undefined) map[b][from] = {}
map[b][from][to] = values[2]
}
}

var trades = {}
for (var d in map) {
trades[d] = []
for (var i in map[d]) {
for (var j in map[d][i]) {
if (map[d][i][j] > q && map[d][j][i] > q) {
if (i < j) {
trades[d].push([i, j, map[d][i][j], map[d][j][i]])
} else {
trades[d].push([j, i, map[d][j][i], map[d][i][j]])
}
delete map[d][j][i]
}
}
}

function compare(a, b) {
return a < b ? -1 : a > b ? 1 : 0
}

trades[d] = trades[d].sort((a, b) => compare(a[0], b[0]) || compare(a[1], b[1])).map(t => `⠀⠀Trocas entre ${t[0]}(v${Math.floor(t[2] / q)}) e ${t[1]}(v${Math.floor(t[3] / q)})`).join("<br>")
}

var out = []

for (var d in trades) {
var s = `Final dia ${+d + 1}<br>`
s += trades[d] != "" ? trades[d] : "⠀⠀Sem Trocas"
out.push(s)
}
return md`${out.join("<br>")}`
}
Insert cell
randomBlocks = (n, d) => {
var blocks = []
for (var k = 0; k < d; k++) {
var block = `Dia ${k + 1}`
for (var i = 0; i < n; i++) {
for (var j = 0; j < n; j++) {
if (j != i) {
block += `\n${i + 1} ${j + 1} ${Math.floor(Math.random() * 100)}`
}
}
}

blocks.push(block)
}

return blocks.join("\n")
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more