Created
September 16, 2018 15:46
-
-
Save jcreedcmu/1cd7b93a84aa8be7c61a4b83757083a7 to your computer and use it in GitHub Desktop.
enum.ts
This file contains hidden or 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
| export function range(n) { | |
| const rv = []; | |
| for (let i = 0; i < n; i++) | |
| rv.push(i); | |
| return rv; | |
| } | |
| const r = Math.random; | |
| type Point = {x: number, y: number}; | |
| const ITERS = [0,0,0,100,1000,10000,1000000,10000000]; | |
| for (let N = 3; N < 8; N++) { | |
| const seen = {}; | |
| let seen_count = 0; | |
| let last_seen_new; | |
| function accum(t, s) { | |
| if (!seen[s]) { | |
| seen[s] = 1; | |
| seen_count++; | |
| last_seen_new = t; | |
| } | |
| } | |
| for (let t = 0; t < ITERS[N]; t++) { | |
| const pts: Point[] = range(N).map(() => ({x: r(), y: r()})); | |
| pts.sort((a, b) => a.x - b.x); | |
| let s = ""; | |
| for (let i = 0; i < pts.length; i++) { | |
| for (let j = i+1; j < pts.length; j++) { | |
| for (let k = j+1; k < pts.length; k++) { | |
| const det1 = pts[i].x * pts[j].y + pts[j].x * pts[k].y + pts[k].x * pts[i].y; | |
| const det2 = pts[i].x * pts[k].y + pts[j].x * pts[i].y + pts[k].x * pts[j].y; | |
| s += (det1 > det2 ? "1" : "0"); | |
| } | |
| } | |
| } | |
| accum(t, s); | |
| } | |
| console.log(`count ${seen_count}, last seen new at t=${last_seen_new}/${ITERS[N]}`); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment