This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
//( |