Tuesday, October 4
Shadow

Tag: Untrusted

Solution to level 11 in Untrusted:

gist
/* * robot.js * * You'll need three keys in order to unlock the * Algorithm: the red key, the green key, and the * blue key. Unfortunately, all three of them are * behind human-proof barriers. * * The plan is simple: reprogram the maintenance * robots to grab the key and bring it through * the barrier to us. * * Let's try it on the red key first. */ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function startLevel(map) { // Hint: you can press R or 5 to "rest" and not move the // player, while the robot moves around. map.placePlayer(map.getWidth()-2, map.getHeight()-2); var player = map.getPlayer(); map.defineObject('robot', { 'type': 'dynamic', 'symbol': 'R', 'color': 'gray', ...

Lua script to delete/trim all processed messages from a Redis stream

gist
-- The goal of this script is to trim messages that have been processed by -- all extant groups from the a given Redis stream. It returns the number -- of messages that were deleted from the stream, if any. I make no -- guarantees about its performance, particularly if the stream is large -- and not fully processed (so a simple XTRIM isn't possible). -- First off, bail out early if the stream doesn't exist. if redis.call("EXISTS", KEYS[1]) == 0 then return false end -- To figure out what messages are deletable, we fetch the "last- -- delivered-id" for each consumer group of the stream, and set the lowest -- one of those ids as our upper bound. Next, we scan the pending lists -- for each group, because we also don't want to delete any events that -- are delivered but not acknowledg...

Solution to level 2 in Untrusted

gist
/******************** * theLongWayOut.js * ******************** * * Well, it looks like they're on to us. The path isn't as * clear as I thought it'd be. But no matter - four clever * characters should be enough to erase all their tricks. */ function startLevel(map) { map.placePlayer(7, 5); var maze = new ROT.Map.DividedMaze(map.getWidth(), map.getHeight()); maze.create( function (x, y, mapValue) { // don't write maze over player if (map.getPlayer().atLocation(x,y)) { return 0; } else if (mapValue === 1) { //0 is empty space 1 is wall map.placeObject(x,y, 'block'); } else { map.placeObject(x,y,'empty'); } }); map.placeObject(map.getWidth()-4, map.getHeight()-4, 'b...

Solution to level 6 in Untrusted

gist
/**************** * drones101.js * **************** * * Do you remember, my dear Professor, a certain introductory * computational rationality class you taught long ago? Assignment * #2, behavior functions of autonomous agents? I remember that one * fondly - but attack drones are so much easier to reason about * when they're not staring you in the face, I would imagine! */ function startLevel(map) { function moveToward(obj, type) { var target = obj.findNearest(type); var leftDist = obj.getX() - target.x; var upDist = obj.getY() - target.y; var direction; if (upDist == 0 && leftDist == 0) { return; } if (upDist > 0 && upDist >= leftDist) { direction = 'up'; } else if (upDist < ...

Solution to level 1 in Untrusted:

gist
/***************** * cellBlockA.js * ***************** * * Good morning, Dr. Eval. * * It wasn't easy, but I've managed to get your computer down * to you. This system might be unfamiliar, but the underlying * code is still JavaScript. Just like we predicted. * * Now, let's get what we came here for and then get you out of * here. Easy peasy. * * I've given you as much access to their code as I could, but * it's not perfect. The red background indicates lines that * are off-limits from editing. * * The code currently places blocks in a rectangle surrounding * you. All you need to do is make a gap. You don't even need * to do anything extra. In fact, you should be doing less. */ function startLevel(map) { map.displayChapter('Chapter 1\nBreakout'); map.placePla...

Solution to level 9 in Untrusted

gist
/********************** * fordingTheRiver.js * ********************** * * And there's the river. Fortunately, I was prepared for this. * See the raft on the other side? * * Everything is going according to plan. */ function startLevel(map) { var raftDirection = 'down'; map.placePlayer(map.getWidth()-1, map.getHeight()-1); var player = map.getPlayer(); map.defineObject('raft', { 'type': 'dynamic', 'symbol': '▓', 'color': '#420', 'transport': true, // (prevents player from drowning in water) 'behavior': function (me) { me.move(raftDirection); } }); map.defineObject('water', { 'symbol': '░', 'color': '#44f', 'onCollision': function (player) { player.killedBy('dr...