Skip to content

Instantly share code, notes, and snippets.

@killroy42
killroy42 / sudokupad_hint_plugin.js
Last active November 23, 2023 11:49
Prototype Hinting User Plugin
const generateHintFunc = (() => {
/*let board = Array.from({ length: 9 }, () => Array(9).fill(0));
board[0][0] = 1;
board[2][2] = 2;
board[0][1] = 3;
board[1][0] = 4;
*/
let board = [
@killroy42
killroy42 / sudokupad emoji-replacement.js
Created September 13, 2023 17:39
Replaces emoji symbols in SudokuPad (paste into console)
(async () => {
const requireScript = async src => new Promise((onload, onerror) => document.getElementsByTagName('head')[0].appendChild(Object.assign(document.createElement('script'), {src, onload, onerror})));
const requireDependencies = async deps => Promise.all(deps.filter(url=>performance.getEntriesByName(url, 'resource').length==0).map(requireScript));
await requireDependencies([`https://unpkg.com/twemoji@14.0.2/dist/twemoji.min.js`]);
const style = `img.emoji { height: 1em; width: 1em; margin: 0 .05em 0 .1em; vertical-align: -0.1em; }`;
await attachStylesheet(style);
const opts = {ext: '.svg', folder: 'svg'};
twemoji.parse(document.querySelector('.controls-info'), opts);
const textNodes = document.querySelectorAll('#svgrenderer text');
for(const node of textNodes) if([...node.innerHTML].length === 1 && node.innerHTML.length !== 1) {
@killroy42
killroy42 / sudoku_p20.js
Last active July 17, 2023 08:06
Solved Sudoku Compactor P81->p20
(()=>{
const p20 = (()=>{
const F=[1,1,2,6,24,120,720,5040,40320,362880];
const chrLUT = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_~', encNum = n=>chrLUT[n], decNum = c=>chrLUT.indexOf(c);
const sizeMap = [9,6,6,6,6,6,6,6,6,6,3,3,3], bitMap = [19,10,10,10,10,10,10,10,10,10,3,3,3], reBitMap = new RegExp(bitMap.map(n=>`(.{${n}})`).join(''));
const N9 = [...Array(9).keys()], boxLUT = N9.map(b=>N9.map(n=>(~~(b/3)*27+b*3%9)+~~(n/3)*9+n%3)), rowLUT = N9.map(r=>N9.map(c=>r*9+c)), colLUT = N9.map(c=>N9.map(r=>r*9+c));
const getLc = (perm,s=[...perm.keys()])=>perm.map((n,_,a,i=s.indexOf(n))=>(s.splice(i,1),i));
const fromLc = (code,s=[...code.keys()])=>code.map((i,_,a,e=s[i])=>(s.splice(i, 1),e));
const lcToInt = (lc,l=lc.length)=>lc.reduce((int,n,i)=>int+n*F[l-i-1],0);
const intToLc = (int,z=9)=>[...Array(z)].map((_,i,a,c=F[z-i-1],n=Math.floor(int/c))=>(int%=c,n));
// ==UserScript==
// @name SudokuPad Screenshot & Replay Recorder
// @namespace https://svencodes.com/
// @version 0.6
// @downloadURL https://gist.github.com/killroy42/5f78381f3994ae5f4e460fd31e7101f0/raw/sudokupad-screenshot&replay.user.js
// @updateURL https://gist.github.com/killroy42/5f78381f3994ae5f4e460fd31e7101f0/raw/sudokupad-screenshot&replay.user.js
// @supportURL https://svencodes.com
// @description Puzzle screenshots and replay GIF recording for Sven's SudokuPad
// @author sven@svencodes.com
// @match https://*.sudokupad.app/*
@killroy42
killroy42 / fpuzzles-solution.user.js
Last active November 20, 2022 08:00 — forked from dclamage/fpuzzles-solution.user.js
Allows setters to specify a solution to the puzzle, which is checked in solve mode when the final digit is entered.
// ==UserScript==
// @name Fpuzzles-Solution
// @namespace http://tampermonkey.net/
// @version 1.6
// @description Can input a solution to a puzzle
// @author Rangsk
// @match https://*.f-puzzles.com/*
// @match https://f-puzzles.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// Exmaples to convert f-puzzles URL to CTC url and extract CTC JSON
// Paste in console on ctc app site to load libraries
await (async () => {
// f-puzzles URL to CTC JSON
const fpuzzlesUrlToCtcJson = async url => JSON.parse(PuzzleZipper.unzip(await loadFPuzzle(url.replace(/.*?fpuzzles(.*)/, '$1'))));
// f-puzzles URL to CTC URL
const fpuzzlesUrlToCtcUrl = async url => `https://sudokupad.app/ctc${loadFPuzzle.compressPuzzle(await loadFPuzzle(url.replace(/.*?fpuzzles(.*)/, '$1')))}`;
@killroy42
killroy42 / sudokuSolverNL Bookmarklet
Created March 4, 2022 11:49
Puzzle Bookmarklets for sudokupad.app
Randomly generated Classic, X-Sudoku and Windoku (and mixed) puzzles from a twitter bot:
Puzzle source:
https://twitter.com/sudokuSolverNL
Bookmarklet:
javascript:(function()%7B((%5B%2Cv%2Cp%5D)%3D>window.open('%2F%2Fsudokupad.app%2Fscf'%2Bp.replace(%2F.0%7B0%2C5%7D%2Fg%2Cd%3D>String.fromCharCode((d%3D%2Bd%5B0%5D%2B10*d.length)%2B(d<20%3F38%3Ad<46%3F45%3A51)))%2B(%7Bxsudoku%3A'x'%2Cfoursquare%3A'w'%2Cx4square%3A'wx'%7D%5Bv%5D%7C%7C'')))('undefined'!%3Dtypeof angular%3F((%7Bpuzzle%3Ap%2Cvariant%3Av%7D)%3D>%5B%2Cv%2Cp%5D)(angular.element(document.body).scope().queryParams)%3A%5B...document.querySelectorAll('a%5Btarget%3D"_blank"%5D')%5D.map(a%3D>a.textContent.match(%2Fpuzzle%5C%2F(%3F%3A(%5B%5E%5C%2F%5D%2B)%5C%2F)%3F(%5B0-9%5D%2B)%2F)).filter(_%3D>_)%5B0%5D)%7D)()
Description:
Bookmarklet will find the first tweet on the page with puzzle data and open it on sudokuepad.app. It will also open puzzles on https://sudokusolver.nl/
@killroy42
killroy42 / 0.rules.js
Last active May 30, 2021 15:16
The cracking The Cryptic Fan Discord Code Golf Club
/*
Basic rules for length measurements:
- Same function name as original, but reasonably short
- Terminate in ";"
- No "var", "const", "let", etc
- Same input/output
- May make certain assumptions, for example, input is only 0-9, etc
*/
; Ever since I saw TINYFIRE.ASM by Rex Deathstar I desired
; to write a fire routine which is not only small but fast
; and in full color as well.
;
; Well, here it is:
; - 192 shades of red and yellow set at run-time
; - 160 by 100 resolution for higher speed
; - limited screen area based at the bottom of the screen
; - NO Memory variables used
; - LESS THAN 200 bytes! (186 in July 1997)
@killroy42
killroy42 / tiny_promise.js
Created July 1, 2019 11:27
Minimal, tolerant and feature-rich promise polyfill
(function(scope) {
var Fcb = Function.call.bind, Apt = Array.prototype;
var slice = Fcb(Apt.slice);
var concat = Fcb(Apt.concat);
var forEach = Fcb(Apt.forEach);
//var setT = XS['set_Timeout'];
// async
var queue = [];
function async(callback) {