Skip to content

Instantly share code, notes, and snippets.

@nicolo-ribaudo
Last active August 26, 2023 11:52
Show Gist options
  • Save nicolo-ribaudo/1a3f393bad82941c47be3e89c304148d to your computer and use it in GitHub Desktop.
Save nicolo-ribaudo/1a3f393bad82941c47be3e89c304148d to your computer and use it in GitHub Desktop.
true -> false

true -> false

Goal

fn(/* ??? */) must return false

Rules

  • You can only edit /* ??? */ in the script below.
  • You can only replace /* ??? */ with a valid parameters list. e.g. things like true, 1) && (false ar not allowed.
  • The parameters which you replace /* ??? */ with can't modify other parts of the program (e.g. they can't override eval o Number.prototype). If this code is added to an existing program, it shouldn't be observable.
  • The result must be exactly false (result === false), so 0 or "false" are not valid values.

true -> false

Obbiettivo

Fare in modo che fn(/* ??? */) restiruisca false

Regole

  • Si può solo modificare /* ??? */.
  • Al posto di /* ??? */ bisogna mettere una lista di parametri valida, quindi non sono permesse cose come true, 1) && (false.
  • I parametri usati al posto di /* ??? */ non devono modificare nient'altro nel programma (ad esempio, eval o Number.prototype). Questo codice potrebbe ipoteticamente essere inserito all'interno di un altro programma senza influenzarlo.
  • Il risultato deve essere tale che result === false, quindi 0 o "false" non sono valori validi.
var unshift = Function.call.bind([].unshift);
var test = Function.call.bind(/./.test);
function update(ar) {
unshift(ar, ar[ar.length - 1]);
}
function fn(check, id) {
if (check != true) throw new Error("check must be true");
if (id != 1 && id != 2) throw new Error("id must be 1 or 2");
var ar1 = [ 0, 1, 2 ];
var ar2 = [ 7, 8, 9 ];
var name = "ar" + id;
if (test(/\W/, name)) throw new Error("Invalid eval input");
var ar = eval(name);
update(ar);
return check;
}
var result = fn(/* ??? */);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment