Skip to content

Instantly share code, notes, and snippets.

View boompig's full-sized avatar

Daniel Kats boompig

View GitHub Profile
@boompig
boompig / send_more_money.py
Created July 20, 2021 16:40
3 solver implementations for send+more=money problem
from typing import Optional, Tuple, Set, List, Dict
import copy
import time
from argparse import ArgumentParser
import random
import json
import numpy as np
import os
import uuid
from types import SimpleNamespace
from __future__ import print_function
import sys
def skip(fp):
for i, line in enumerate(fp):
if line.endswith("clearing screen\n"):
return i
raise ValueError("Error: skipped whole file")
def print_profile(time_by_file, occurrences_by_file):
2016/08/19 13:24:25 [INFO] Terraform version: 0.7.0 e822a79165dbc06bbf8271ee349fe256867d53dc
2016/08/19 13:24:25 [DEBUG] Detected home directory from env var: /Users/daniel_kats
2016/08/19 13:24:25 [DEBUG] Detected home directory from env var: /Users/daniel_kats
2016/08/19 13:24:25 [DEBUG] Attempting to open CLI config file: /Users/daniel_kats/.terraformrc
2016/08/19 13:24:25 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2016/08/19 13:24:25 [DEBUG] Detected home directory from env var: /Users/daniel_kats
2016/08/19 13:24:25 [DEBUG] Checking variable noop: var.region
2016/08/19 13:24:25 [DEBUG] No diff, not a noop
2016/08/19 13:24:25 [DEBUG] Checking resource noop: aws_s3_bucket.bucket
2016/08/19 13:24:25 [DEBUG] No diff, not a noop
class Item(object):
def __init__(self, time, val):
self.time = time
self.val = val
def get_over_limit_simul(interval_list, limit):
queue = Queue(lambda o: o.time)
for interval in interval_list:
o_in = Item(interval.start, interval.val)
o_out = Item(interval.end, -1 * interval.val)
import heapq
from collections import deque
def insert_into_queue(item, queue):
if not item.is_empty():
queue.push(item)
class Queue(object):
def __init__(self, fn):
class Interval(object):
def __init__(self, start, end, val):
self.start = start
self.end = end
self.val = val
def get_intersection(self, other):
"""Modify self and other to make non-overlapping intersections.
If there is another guy, return him. Otherwise return None.
Intervals can be changed to zero-length, which means they disappear."""
var makePalindrome = function(text) {
// take a letter from the beginning and add it to the end
var front = true;
var start = 0;
var end = text.length - 1;
while (start < end) {
console.log("compared " + text[start] + " and " + text[end]);
if (text[start] != text[end]) {
if (front) {
console.log("inserting " + text[start] + " before index " + (end + 1) + "(after char " + text[end] + ")");
@boompig
boompig / ece-main.py
Last active August 29, 2015 14:14
Auto-email Parser and Replyer
import cStringIO
import json
import re
import sendmail
import subprocess
import string
import sys
from time import sleep
UNDEF_GROUP = "undefined"
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
int romeEval(const int a, const int b) {
if (a < b) {
return b - a;
} else {
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <set>
#include <stdlib.h>
#include <math.h>
using namespace std;