Skip to content

Instantly share code, notes, and snippets.

For simplicity, this will just go over the unsigned case
Written for someone, such as myself, who isn't as quick to put together the same logical steps

Given $y \in \mathbb{Z}$ where $y > 0$
Find $a,sh \in \mathbb{Z}$ such that $\forall x \in \mathbb{Z} \ (\ \lfloor \frac{x}{y} \rfloor = \lfloor x \cdot a / 2^{sh} \rfloor)$
To motivate what we'll be doing, lets start by considering:

$$ \begin{align*}

@B-Y-P
B-Y-P / char_class.hpp
Last active May 29, 2023 16:29
char class structure
/// 256 length bit-vector
struct CharClass{
u64 b[4];
bool lo_empty(){ return (b[0] | b[1]) == 0; }
bool hi_empty(){ return (b[2] | b[3]) == 0; }
u64 lo_count(){ return PopCnt(b[0]) + PopCnt(b[1]); }
u64 hi_count(){ return PopCnt(b[2]) + PopCnt(b[3]); }
bool empty(){ return (b[0] | b[1] | b[2] | b[3]) == 0; }
/// There might be some functionality you need to write for when the App closes
/// If so, I never bothered to implement it so... it's left as an exercise to the reader :)
#pragma pack(push, 8)
// Get Discord game SDK from https://discord.com/developers/docs/game-sdk/sdk-starter-guide
// Just use the C api, it's single-file and infinitely easier to implement
#include "path/to/discord_game_sdk.h"
#pragma pack(pop)
// Make sure the contents of the /lib/x86_64 is placed next to 4ed.exe