Skip to content

Instantly share code, notes, and snippets.

View PurpleMyst's full-sized avatar

Nicolò Francesco Maria Spingola PurpleMyst

  • Italy
  • 07:23 (UTC +02:00)
View GitHub Profile
@PurpleMyst
PurpleMyst / benchmark.py
Last active July 27, 2017 23:05
Fast way of calculating the number of digits in a number in Python, using C
#!/usr/bin/env python3
from math import floor, log10
from digits import bacherikow, intlen, bordum, stephen, bisect
def python_strlen(n, str=str, len=len):
return len(str(n))
#!/usr/bin/env python3
import collections
import inspect
import curio
from curio import socket
User = collections.namedtuple("User", ["nick", "user", "host"])
Server = collections.namedtuple("Server", ["name"])
@PurpleMyst
PurpleMyst / mandelbrot.c
Last active August 6, 2017 02:48
Simple grayscale mandelbrot set visualization outputted in PGM format.
#include <stdio.h>
#include <stdint.h>
#include <complex.h>
#define MAX_ITERATIONS 80
#define REAL_START -2
#define REAL_END 1
#define IMAG_START -1
#define IMAG_END 1
@PurpleMyst
PurpleMyst / 1bit_mandelbrot.c
Created August 7, 2017 19:29
A visualization of the mandelbrot set written in C99.
#include <stdio.h>
#include <stdint.h>
#include <complex.h>
#define MAX_ITERATIONS 255
#define REAL_START -2
#define REAL_END 1
#define IMAG_START -1
#define IMAG_END 1
@PurpleMyst
PurpleMyst / input.txt
Created December 8, 2017 13:38
Solution for AoC Day 7 Part 2
apcztdj (61)
ulovosc (61) -> buzjgp, iimyluk
awpvs (88)
ykbjhi (14)
gxvketg (49)
gpmvdo (78) -> jjixrr, zacrh, smylfq, fdvtn
nwpmqu (6025) -> aytrde, grokih, pjqaa, nzzved
keiakhg (50)
vkrlz (22)
myzkj (40)
@PurpleMyst
PurpleMyst / first.py
Created December 9, 2017 23:48
Solution to AoC 2017 Day 3 Part 1
#!/usr/bin/env python3
UP = (0, -1)
DOWN = (0, 1)
LEFT = (-1, 0)
RIGHT = (1, 0)
NEXT_DIRECTION = {
RIGHT: UP,
#!/usr/bin/env python3
import functools
import itertools
import math
def prime_factors(n, sqrt=math.sqrt):
limit = sqrt(n) + 1
i = 2
@PurpleMyst
PurpleMyst / assembunny.rs
Created December 22, 2017 19:46
An Assembunny interpreter. (AoC 2016 Day 12)
#[derive(Debug, Clone)]
enum Instruction {
Unary(String, String),
Binary(String, String, String)
}
#[derive(Debug)]
struct CPU {
a: isize,
b: isize,
@PurpleMyst
PurpleMyst / jeopardy_bot.py
Created January 24, 2018 16:52
A bot to play Jeopardy! in your favorite IRC channels.
#!/usr/bin/env python3
import json
import random
import curio
from nettirely import IrcBot, NO_SPLITTING
bot = IrcBot(state_path="jeopardy_state.json")
@PurpleMyst
PurpleMyst / intermediate.c
Created February 21, 2018 17:22
Solution to DailyProgrammer Day 351 [Intermediate]
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ever (;;)
typedef struct {
size_t size;
char *names;