Skip to content

Instantly share code, notes, and snippets.

# part 1
awk '
/forward/ { x += $2 }
/up/ {y-=$2}
/down/ {y+=$2}
END {print x*y}
' input.txt
# part 2
awk '
/forward/ {x+=$2;y+=$2*aim}
var widget = function(e) {
function t(r) {
if (n[r]) return n[r].exports;
var o = n[r] = {
i: r,
l: !1,
exports: {}
};
return e[r].call(o.exports, o, o.exports, t), o.l = !0, o.exports
}
@ramiror
ramiror / dto.php
Last active December 2, 2020 21:38 — forked from mcsee/dto.php
<?
final class SocialNetworkProfile {
private $userName;
private $friends; // friends is a reference to a large collection
private $feed; // feed references the whole user feed
public __construct($userName , $friends, UserFeed $feed) {
$this->assertUsernameIsValid($userName);
@ramiror
ramiror / boolean.php
Created November 28, 2020 19:12 — forked from mcsee/boolean.php
<?
function processBatch(bool $useLogin, bool $deleteEntries, bool $beforeToday ){
/...
}
@ramiror
ramiror / clever.js
Created November 28, 2020 18:45 — forked from mcsee/clever.js
function primeFactors(n){
var f = [], i = 0, d = 2;
for (i = 0; n >= 2; ) {
if(n % d == 0){
f[i++]=(d);
n /= d;
}
else{
d++;
let cuca = "Racha";
@ramiror
ramiror / intelligent.js
Last active November 28, 2020 12:36 — forked from mcsee/intelligent.js
function primeFactors(numberToFactor) {
var factors = [],
divisor = 2,
remainder = numberToFactor;
while (remainder >= 2) {
if (remainder % divisor === 0) {
factors.push(divisor);
remainder = remainder / divisor;
}
@ramiror
ramiror / enumish.php
Created June 21, 2020 23:33
A simpler enumish class
<?php
abstract class Pais {
const ARGENTINA = 'Argentina';
const URUGUAY = 'Uruguay';
static private $values = [];
static function init() {
$refle = new ReflectionClass(__CLASS__);
@ramiror
ramiror / pais.php
Last active June 21, 2020 22:12
Simplest PHP enum I could make -- a tradeoff between features and complexity
<?php
// pais.php
class Pais {
private function __construct() {}
static private $instance;
static function register() {
assert(self::$instance, 'Uninitialized Pais enum');
$name = get_called_class();