Skip to content

Instantly share code, notes, and snippets.

@tyfkda
tyfkda / sudoku-sample.txt
Created January 8, 2022 09:04
Sudoku solver
8....51..
..1...8..
.4.2...9.
....3...2
1234 6789
6...1....
.8...9.5.
..2...4..
..76....1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tyfkda
tyfkda / TensorFlow.js 上で6x6リバーシ対戦
Last active May 6, 2022 05:46
TensorFlow.js 上で6x6リバーシ対戦
// gist名指定用
@tyfkda
tyfkda / smallpt.c
Created June 11, 2022 03:42
smallpt on C language
// Original: https://www.kevinbeason.com/smallpt/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct { double x, y, z; } Vec; // position, also color (r,g,b)
Vec vadd(Vec a, Vec b) { return (Vec){a.x+b.x, a.y+b.y, a.z+b.z}; }
Vec vsub(Vec a, Vec b) { return (Vec){a.x-b.x, a.y-b.y, a.z-b.z}; }
Vec vscale(Vec a, double b) { return (Vec){a.x*b, a.y*b, a.z*b}; }
Vec vmult(Vec a, Vec b) { return (Vec){a.x*b.x, a.y*b.y, a.z*b.z}; }
double vdot(Vec a, Vec b) { return a.x*b.x+a.y*b.y+a.z*b.z; }
@tyfkda
tyfkda / mygetopt.c
Created September 20, 2022 02:06
My getopt implementation
#include "getopt.h"
#include <stdbool.h>
#include <stddef.h> // NULL
#include <stdio.h>
#include <string.h>
int optind, optopt;
int opterr = 1;
char *optarg;
@tyfkda
tyfkda / nan-boxing.c
Created April 22, 2023 23:07
NaN Boxing, referred to CLox (Crafting Interpreters)
// Ref. https://craftinginterpreters.com/
#include <assert.h>
#include <inttypes.h> // PRIx64
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h> // malloc
#include <stdint.h>
#include <string.h>
@tyfkda
tyfkda / rose.js
Last active January 28, 2024 09:26
Rose screen saver (p5.js)
const WIDTH = 600, HEIGHT = 600
const DIV = 64
const TWO_PI = 2 * Math.PI
const MIN_TIME = 60
const MAX_TIME = 300
const TRANSITION_RATIO = 1.0 / 100
function randi(min, max) {
return Math.floor(random(min, max + 1))
@tyfkda
tyfkda / reinforce_invpend_double_gym_v26.py
Created June 3, 2024 00:55
Reinforcement learning for Inverted Double Pendulum (Gymnasium)
# fmt: off
# https://gymnasium.farama.org/tutorials/training_agents/reinforce_invpend_gym_v26/
# https://gymnasium.farama.org/environments/mujoco/inverted_double_pendulum/
"""
Training using REINFORCE for Mujoco
===================================
.. image:: /_static/img/tutorials/reinforce_invpend_gym_v26_fig1.gif
@tyfkda
tyfkda / gen-macho-exe.c
Last active March 8, 2025 03:20
Mach-O実行ファイル形式を自分で生成する(aarch64用)
#include <mach-o/compact_unwind_encoding.h>
#include <mach-o/fixup-chains.h>
#include <mach-o/ldsyms.h>
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
#include <stdio.h>
#include <string.h>
#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
@tyfkda
tyfkda / macho-analyzer.rb
Last active March 26, 2025 00:02
Mach-Oファイルを解析するツール(Ruby)
LC_REQ_DYLD = 0x80000000
LC_SEGMENT = 0x01
LC_SYMTAB = 0x02
LC_SYMSEG = 0x03
LC_THREAD = 0x04
LC_UNIXTHREAD = 0x05
LC_LOADFVMLIB = 0x06
LC_IDFVMLIB = 0x07
LC_IDENT = 0x08