Skip to content

Instantly share code, notes, and snippets.

View pauloricardokoch's full-sized avatar
🤖

Paulo Koch pauloricardokoch

🤖
  • Globo
  • Passo Fundo
View GitHub Profile
@pauloricardokoch
pauloricardokoch / dojo.js
Created April 1, 2022 13:57
Day 6 - Advent of Code (part two)
const regex = /(turn (on|off)|toggle) (\d+),(\d+) through (\d+),(\d+)/
const operations = []
operations['toggle'] = (light) => light + 2
operations['turn on'] = (light) => light + 1
operations['turn off'] = (light) => Math.max(light - 1, 0)
const parseLine = (s) => {
let [, operation, , x_start, y_start, x_finish, y_finish] = s.match(regex)
@pauloricardokoch
pauloricardokoch / dojo.js
Created March 31, 2022 23:09
Day 6 - Advent of Code (part one)
const regex = /(turn (on|off)|toggle) (\d+),(\d+) through (\d+),(\d+)/
const operations = []
operations['toggle'] = (light) => Number(!light)
operations['turn on'] = (light) => 1
operations['turn off'] = (light) => 0
const parseLine = (s) => {
let [, operation, , x_start, y_start, x_finish, y_finish] = s.match(regex)
@pauloricardokoch
pauloricardokoch / lib.rkt
Last active May 3, 2016 02:57
The little schemer
;; THE LAW OF CAR
;; The primitive car is defined only for non-empty lists.
;; THE LAW OF CDR
;; The primitive cdr is defined only for non-empty lists.
;; The cdr of any non-empty list is always another list.
;; THE LAW OF CONS
@pauloricardokoch
pauloricardokoch / functional_programming_compose.php
Last active April 29, 2016 21:49
Functions to currying and compose functions with PHP.
<?php
// This function allows creating a new function from two functions passed into it
//e.g.:
//php > $explode = curry_left("explode", ",");
//php > $toUpper = curry_left("strtoupper");
//php > $map = curry_left("array_map", $toUpper);
//php > $compose = compose($map, $explode);
//php > print_r($compose("paulo,ricardo,koch"));
//Array
//(