-
Notifications
You must be signed in to change notification settings - Fork 0
/
school-bus.js
executable file
·57 lines (47 loc) · 1.17 KB
/
school-bus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"
"use strict";
//basic schoolbus algorithm
function school_bus_basic(offsets, minRacking, maxRacking, xfer){
var stock = true;
for (let i = 0; i < offsets.length; i++) {
if (offsets[i]!=0) {
stock = false;
}
}
if (stock) {
return;
}
for (let i = 0; i < offsets.length; i++) {
xfer('f', i, 'b', i);
}
var currentOffset = minRacking;
while (currentOffset <= maxRacking) {
for (let i = 0; i < offsets.length; i++) {
if (offsets[i] == currentOffset) {
xfer('b', i, 'f', i+currentOffset);
}
}
currentOffset++;
}
}
module.exports.school_bus_basic = school_bus_basic;
if (require.main === module) {
console.log("Doing some test transfers.");
const testDriver = require('./test-driver.js');
//adaptor to fit into testDriver
function _school_bus_basic(offsets, firsts, orders, limit, xfer) {
school_bus_basic(offsets, -limit, limit, xfer);
}
if (process.argv.length > 2) {
testDriver.runTests(_school_bus_basic, {
skipCables:true,
skipLong:true,
//ignoreStacks:true,
//ignoreEmpty:true,
ignoreFirsts:true,
outDir:'results/schoolbus'
});
return;
}
}