Skip to content

Instantly share code, notes, and snippets.

Avatar

Loo Rong Jie rongjiecomputer

View GitHub Profile
@rongjiecomputer
rongjiecomputer / prime.cpp
Created Apr 5, 2017
Sieve of Eratosthenes with C++ constexpr
View prime.cpp
#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 / ascii-win.c
Created Dec 20, 2016
Ascii Fluid Simulation (Windows)
View ascii-win.c
// 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>
View bsearch.cpp
/* 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--) {
@rongjiecomputer
rongjiecomputer / cano-trim.py
Created Jun 4, 2016
Python code to trim raw text of Complete Sherlock Holmes
View cano-trim.py
"""
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.
"""
You can’t perform that action at this time.