Skip to content

Instantly share code, notes, and snippets.

@rongjiecomputer
rongjiecomputer / prime.cpp
Created April 5, 2017 00:00
Sieve of Eratosthenes with C++ constexpr
#include <stdio.h>
template <size_t N>
struct PrimeTable {
constexpr PrimeTable() : sieve() {
sieve[0] = sieve[1] = false;
for (size_t i = 2; i < N; i++) sieve[i] = true;
for (size_t i = 2; i < N; i++) {
if (sieve[i])
for (size_t j = i*i; j < N; j += i) sieve[j] = false;
@rongjiecomputer
rongjiecomputer / cano-trim.py
Created June 4, 2016 08:50
Python code to trim raw text of Complete Sherlock Holmes
"""
Original raw text:
http://sherlock-holm.es/ascii/
Trimmed Format:
- Each line is a complete paragraph.
- Each line is ended with two new line characters ('\n\n') (including the last line).
- Disclaimer at the end of the raw text is not deleted, you need to delete it yourself.
"""
@rongjiecomputer
rongjiecomputer / ascii-win.c
Created December 20, 2016 10:23
Ascii Fluid Simulation (Windows)
// this de-obfuscated version by Davide Della Casa
// original obfuscated version by Yusuke Endoh
// modified for Windows (Mingw-w64)
// formatted in Chromium C/C++ style
// compile with gcc ascii-win.c -o ascii -O3 -s -flto
// usage and original repo see https://github.com/davidedc/Ascii-fluid-simulation-deobfuscated
#include <stdio.h>
#include <complex.h>
#include <math.h>
/* std::lower_bound + hand-written move */
void insert(Index x) {
auto it = std::lower_bound(begin(), end(), x);
if (it == end()) push_back(x);
else if (*it > x) {
Index i = it - begin();
resize(size() + 1);
for (Index j = size() - 1; j > i; j--) {