Skip to content

Instantly share code, notes, and snippets.

const { readFileSync, writeFileSync } = require('fs');
const input = readFileSync('./input.txt').toString();
function d23b() {
let inp = input.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0)
let isValid = (y,x)=>!(y<0 || y>=inp.length || x<0 || x>=inp[0].length || inp[y][x] === '#');
// function leastFactor(n) returns:
// * the smallest prime that divides n
// * NaN if n is NaN or Infinity
// * 0 if n is 0
// * 1 if n=1, n=-1, or n is not an integer
leastFactor = function(n) {
if (isNaN(n) || !isFinite(n)) return NaN;
if (n==0) return 0;
if (n%1 || n*n<2) return 1;
@bk201-
bk201- / Library
Created November 18, 2019 05:58
Lazify & Proxy
const executeOperations = (operations, args) => {
return operations.reduce((args, method) => {
return [method(...args)];
}, args);
};
const $ = Symbol('RESULT_ARGUMENT');
function lazify(instance) {
const operations = [];
@bk201-
bk201- / PropertyWatcher.js
Created September 16, 2019 08:13
Property Watcher Template
function watchProperty(object, key) {
let propDescriptor = Object.getOwnPropertyDescriptor(object, key) || {
value: undefined,
configurable: true,
enumerable: true,
writable: true
};
let value = object[key];
@bk201-
bk201- / angular2-focus-directive
Created June 27, 2017 05:51
Focused on the element if condition is True, and blur the focus if condition is False
/**
* Focused on the element if condition is True, and blur the focus if condition is False
*
* Searching focusable element by allowing conditions:
* 1. Searching the element by selector from "focusOn" attribute
* 2. Searching the element with "autofocus" attribute
* 3. Searching the first element who can get cursor
* 4. Otherwise set yourself as focusable element
*/