Skip to content

Instantly share code, notes, and snippets.

View benbotto's full-sized avatar
💭
Because code.

benbotto

💭
Because code.
View GitHub Profile
@benbotto
benbotto / rubiks-cube-ida-star.cpp
Last active October 8, 2023 08:55
IDA* search for the Rubik's Cube
/**
* Non-recursive IDA* search (pseudocode).
* @param cube A scrambled cube to solve.
*/
vector<uint8_t> idaStar(RubiksCube& cube)
{
// Holds a copy of the cube, a move (L, R, etc.), and the search depth.
struct Node
{
RubiksCube cube;
@benbotto
benbotto / kaleidoscope.js
Created April 13, 2020 15:46
Mirror a Line in a Canvas 2: Kaleidoscope
function render() {
ctx.beginPath();
ctx.lineWidth = 2;
while (pointQueue.length > 1) {
const lastPoint = pointQueue.shift();
const curPoint = pointQueue[0];
// Render a line segment from lastPoint to curPoint, but mirrored in each
// quadrant.
@benbotto
benbotto / mirror-a-line.js
Created April 13, 2020 15:18
Mirror a Line in a Canvas 1
function render() {
ctx.beginPath();
ctx.lineWidth = 2;
while (pointQueue.length > 1) {
const lastPoint = pointQueue.shift();
const curPoint = pointQueue[0];
// First line: The line under the cursor.
ctx.resetTransform();
@benbotto
benbotto / draw-a-line.js
Last active April 13, 2020 15:00
Draw a Line in a Canvas
(function(window, gl) {
'use strict';
// The canvas element and a 2D rendering context.
const easel = document.getElementById('easel');
const ctx = easel.getContext('2d');
// This point (vec2) holds the first point in the drawing. Transformations
// happen about this point.
let startPoint = null;
@benbotto
benbotto / rectangle-rotating-and-orbiting-about-point.js
Created March 25, 2020 18:22
A rectangle rotating and orbiting about a point.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
// Rotation, updated before each render.
this.rotation = gl.mat2d.create();
@benbotto
benbotto / rectangle-orbiting-about-point.js
Created March 25, 2020 17:01
A rectangle orbiting about a point.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
// Rotation, updated before each render.
this.rotation = gl.mat2d.create();
@benbotto
benbotto / rectangle-orbiting-about-origin.js
Last active March 25, 2020 16:21
A rectangle orbiting about the origin.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
// Rotation, updated before each render.
this.rotation = gl.mat2d.create();
@benbotto
benbotto / rectangle-rotating-at-point.js
Created March 25, 2020 15:44
A rectangle rotating at a point.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
// Rotation, updated before each render.
this.rotation = gl.mat2d.create();
@benbotto
benbotto / Rectangle.js
Created March 25, 2020 14:59
Rectangle rotating at the origin.
class Rectangle {
constructor(gl, color, width, height) {
this.gl = gl;
this.color = color;
this.width = width;
this.height = height;
this.rotation = gl.mat2d.create();
}
@benbotto
benbotto / generic.cpp
Last active May 26, 2019 15:47
Sequentially Indexing Permutations O(n) (Generic)
#include <cstddef>
using std::size_t;
#include <array>
using std::array;
#include <bitset>
using std::bitset;
#include <iostream>
using std::cout;
using std::endl;