Skip to content

Instantly share code, notes, and snippets.

function aStar_compare(a, b) {
return a.cost + a.estimate < b.cost + b.estimate || (a.cost + a.estimate == b.cost + b.estimate && a.cost < b.cost);
}
var Heap = function(compare) {
if (!compare) {
compare = function(a, b) {return a < b;};
}
this.compare = compare;
this.heap = [];
#!/usr/bin/env/python3
import random
gaps = []
events = 0
current_gap = 0
for trial in range(1000000):
if random.random() < (1/500):
gaps.append(current_gap)
current_gap = 0
events += 1
do
local ArcGroup_class_table = {}
function ArcGroup(x, y)
-- construct an ArcGroup around the chosen point. The starting interval is a single arc,
-- containing the whole circle.
return setmetatable({x = x, y = y, intervals = {{0, 2*math.pi}}}, { __index = ArcGroup_class_table })
end
function ArcGroup_class_table:width()
Apr 12 19:49:38 <zHafydd> You can derive 11^5 from the 11th row of Pascal's triangle: 1, 5, 10, 10, 5, 1.
Apr 12 19:50:13 <lemonade`> how would that work?
Apr 12 19:50:28 <zHafydd> 11^5 = 1 + 5*10 + 10*10^2 + 10*10^3 + 5*10^4 + 1*10^5
Apr 12 19:51:11 <zHafydd> A consequence of the binomial theorem.
Apr 12 19:51:14 <lemonade`> weird.
Apr 12 19:51:50 <zHafydd> If you think it's weird, you haven't thought about it enough.
Apr 12 19:52:25 <baxx> zHafydd: should the binomial be obvious?
Apr 12 19:52:30 <lemonade`> I likely haven't. I'm on it now :)
Apr 12 19:53:08 <zHafydd> baxx: should the binomial theorem be obvious? To a person practicing mathematics beyond an elementary level, yes.
Apr 12 19:53:35 <baxx> zHafydd: because they've been told or because, using a basic toolset, it's obvious
/* this code is licensed CC-0 https://creativecommons.org/publicdomain/zero/1.0/ . use as you see fit.*/
function distance(a, b) {
/* Find the Euclidean distance between two 2-dimensional points.
*
* a: the first point.
* b: the second point.
*
* returns: the distance.
*/
function open_segments_intersect(a1, a2, b1, b2) {
if ((max(a1.x, a2.x) <= min(b1.x, b2.x)) || // a is left of b
(max(b1.x, b2.x) <= min(a1.x, a2.x)) ||
(max(a1.y, a2.y) <= min(b1.y, b2.y)) || // a is above b (in coordinates where (0,0) is topleft)
(max(b1.y, b2.y) <= min(a1.y, a2.y))
) {return false;}
else if ((vcross(vsub(b1,a1),vsub(a2,a1)) * vcross(vsub(b2,a1),vsub(a2,a1)) < 0) && // replace these with <= to make the segments act closed.
(vcross(vsub(a1,b1),vsub(b2,b1)) * vcross(vsub(a2,b1),vsub(b2,b1)) < 0)) {return true;}
else {return false;}
}