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
let input = [ | |
"1-3 a: abcde", | |
"1-3 b: cdefg", | |
"2-9 c: ccccccccc" | |
] | |
// wrong | |
// function testpassword(line){ | |
// let [_, lower, upper, char, password] = line.match(/^(\d+)-(\d+)\s(\w):\s(\w+)$/) | |
// console.log(line, {lower, upper, char, password}) |
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
// Find the complement to each highest number and search the lower numbers for the complement | |
// So it could be recursive, given a sorted array, loop through it from the top down, handing the lower half of the list to yourself | |
// base case: I have 2 numbers to fill. | |
let goal = 2020 | |
let list = [1721, 979, 366, 299, 675, 1456] | |
let [a,b] = findsum(list, goal, 2) | |
console.log(a, b, a + b, a * b) | |
// 1721 299 2020 514579 |
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
// complement sum | |
// ask "what is the complement for x number" and then "Do I have it?" | |
let goal = 2020 | |
let marbles = new Set([1721, 979, 366, 299, 675, 1456]) | |
let complement | |
main: | |
for(var marble of marbles){ | |
complement = goal - marble | |
if(marbles.has(complement)){ |
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
// blackjack sum | |
// given a goal sum and a list of integers, find pairs that add up to the goal | |
// return their product | |
// worse-case quadratic, for each in the list, I check all possibilities from the bottom up | |
// start at the highest number, scan up from the bottom, as soon as I break my goal I exit | |
let goal = 2020 | |
let bottomup = [1721, 979, 366, 299, 675, 1456].sort((a,b) => a - b) // sort from the largest to the smallest | |
let topdown = bottomup.slice().reverse() |
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
Manipulate[Module[{ | |
time = Time2Rotation[seconds], | |
origin = {0, 0}, | |
minutenorm = 6, (* length of minute hand the long side of the matrix *) | |
hournorm = 4, (* the length of the hour hand the short side of the matrix *) | |
minutehand, hourhand, | |
xbasis, ybasis, pts | |
}, | |
xbasis = {Cos[time["minutespin"]], Sin[time["minutespin"]]}; | |
ybasis = {Cos[time["hourspin"]], Sin[time["hourspin"]]}; |
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
<head> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> | |
<style> | |
body { | |
max-width: 800px; | |
margin: 0 auto; | |
} | |
h2 { | |
text-align: center; | |
} |
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
FourToSixSymmetry[FourWayImage_] := Module[ | |
{ | |
Hex = Graphics[Polygon[CirclePoints[6]], ImageSize -> 720], | |
Quarter = Graphics@Polygon[{{-1, -1}, {-1, 1}, {0, 0}, {1, 1}, {-1, 1}}], | |
Equalateral, SixWay | |
}, | |
Equalateral = ImageResize[ImageSubtract[FourWayImage, Quarter], {360, Sqrt[3]/2 * 720 }]; | |
SixWay = Table[ImageRotate[Equalateral, i * Pi/3], {i, -3, 2}]; | |
ImageAdd[Prepend[SixWay, Hex]] | |
] |
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
/* | |
This provides a getter / setter / emitter API for modifying HTML attributes | |
To replace element.setAttribute('name','nobody') with element.props.name = 'nobody' | |
And proviede a hook into being notified of attributes that are changed with this API | |
element.onAttributeChanged = function() | |
*/ | |
// you have to pass the HTMLElement context to the function, | |
function updateAttribute(prop, newValue){ | |
let attributeChange = {attribute: prop, oldValue: this.getAttribute(prop)} |
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
ExportVideo[prefix_, framerate_, frames_] := Module[{ | |
digits = Ceiling @ Log10 @ Length @ frames | |
}, | |
(* create directory (OK if already exist, | |
prints error and continues *) | |
CreateDirectory[prefix]; | |
(* export each frame as a png with an enumerated filename, | |
padded with zeroes *) | |
Table[ | |
Export[ |
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
import {ELElement, ELHTMLComment, ELHTMLStyleElement, ELHTMLElement, ELCSSStyleDeclaration, ELCSSStyleSheet} from "./schemas/elementary" | |
/** | |
* | |
* Elementary has to decide what to do based on the data structure passd to it | |
* An array is recursed over, an object is made into an HTMLElement or an HTMLStyleELement | |
* Null is turned into a blank string, bool, numbers and strings are returned as strings. | |
*/ | |
function elementary(el: ELElement | ELElement[]) : string | |
{ |