Skip to content

Instantly share code, notes, and snippets.

View PurpleMyst's full-sized avatar

Nicolò Francesco Maria Spingola PurpleMyst

  • Italy
  • 20:20 (UTC +02:00)
View GitHub Profile
@PurpleMyst
PurpleMyst / shit_palindrome.py
Created March 2, 2018 16:01
Creates a RegExp that matches static-length palindromes. Solves Regex Golf badly.
#!/usr/bin/env python3
import math
def build_regex(max_size=13):
parts = []
for half_size in range(1, math.ceil(max_size / 2) + 1):
parts.append("^")
parts.append("(.)" * half_size)
@PurpleMyst
PurpleMyst / slow.py
Created February 24, 2018 21:25
Solution to Project Euler #31 in Python and Rust. The Python solution was written while just trying to get something to work and it's very, *very*, slow. The Rust solution was made with a bit more care and some insights from the post-solution forum for the problem. You can guess which code I like best.
#!/usr/bin/env python3
COINS = (200, 100, 50, 20, 10, 5, 2, 1)
COIN_INDEXES = {coin: index for index, coin in enumerate(COINS)}
class CoinsUsed:
def __init__(self, poopyjones=None):
self.poopyjones = poopyjones or ([0] * len(COINS))
@PurpleMyst
PurpleMyst / Makefile
Created February 23, 2018 17:56
My C Makefile template. (I place headers in the src/ directory)
CC := clang
CFLAGS := -std=c11 -Ofast -Wall -Wextra -Wshadow
SRCDIR := src
OBJDIR := obj
SRC := $(wildcard $(SRCDIR)/*.c)
OBJ := $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
EXEC := foo
@PurpleMyst
PurpleMyst / intermediate.c
Created February 21, 2018 17:22
Solution to DailyProgrammer Day 351 Intermediate. Run with the last input for a cool message!
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ever (;;)
typedef struct {
size_t size;
char *names;
@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;
@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;
@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 / 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,
#!/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 / 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,