Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build, patch output #379

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 68 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,61 @@ function inspect() {
});
}

/** Temp patches until the package is fixed and updated */
function splitGroups(arr, groupSize) {
var strings = [],
zeroPos;

for (var i = 0; i < arr.length; i += groupSize) {
strings.push(arr.slice(i, i + groupSize));
}

return strings;
}

function splitStrings(arr) {
var strings = [],
zeroPos;

while (arr.length) {
zeroPos = arr.indexOf(0);
strings.push(arr.slice(0, zeroPos));
arr = arr.slice(zeroPos + 1);
}

return strings;
}

const outboxGeneratorPatches = {
4: function (inbox) {
// Output each pair with the items in reverse order
return splitGroups(inbox, 2).reduce(function (outbox, pair) {
return outbox.concat(pair.reverse());
}, []);
},
28: function (inbox) {
// For each triple, sort then output
return splitGroups(inbox, 3).reduce(function (outbox, triplet) {
return outbox.concat(triplet.sort((a, b) => a - b));
}, []);
},
41: function (inbox) {
// Split strings, sort items in each string, then output all strings
return splitStrings(inbox)
.map(function (string) {
return string
.map((n) => parseInt(n, 36))
.sort((a, b) => a - b)
.map((n) => n.toString(36).toUpperCase());
})
.reduce(function (output, string) {
return output.concat(string);
});
},
};

/** End of temp patches */

function benchmark() {
return plugins.tap((file) => {
try {
Expand All @@ -138,7 +193,9 @@ function benchmark() {

while (runs.length < 100) {
const inbox = inboxGenerator.generate(data.level.number);
const outbox = outboxGenerator.generate(data.level.number, inbox);
const outbox = outboxGeneratorPatches[data.level.number]
? outboxGeneratorPatches[data.level.number](inbox)
: outboxGenerator.generate(data.level.number, inbox);

runs.push({
inbox,
Expand Down Expand Up @@ -190,9 +247,13 @@ function benchmark() {
throw 'Program always failing';
}

if (data.successRatio !== 1) {
if (runs[0].success && data.path.type !== 'specific') {
throw `Non-specific program failing on novel inputs (${Math.round(
if (data.successRatio < 1) {
if (
// Special solutions should pass at least the first example
runs[0].success &&
!['specific', 'exploit', 'obsolete'].includes(data.path.type)
) {
throw `Regular program failing on novel inputs (${Math.round(
100 * data.successRatio,
)}% pass)`;
}
Expand Down Expand Up @@ -260,11 +321,9 @@ function buildDataPrograms() {
successRatio: data.successRatio,
type: data.path.type,
legal:
!/(exploit|specific|obsolete)/.test(data.path.type) &&
(data.successRatio === 1 ||
[4, 28, 41].includes(data.level.number)),
worky:
data.successRatio === 1 || [4, 28, 41].includes(data.level.number),
!['specific', 'exploit', 'obsolete'].includes(data.path.type) &&
data.successRatio === 1,
worky: data.successRatio === 1,
author: data.path.author,
hash: md5(data.source),
path: data.path.full,
Expand Down