Skip to content

Instantly share code, notes, and snippets.

Verifying that +gustavoatt is my blockchain ID. https://onename.com/gustavoatt
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Copy {
@gustavoatt
gustavoatt / gist:3236201
Created August 2, 2012 10:45
Division without arithmetic operators
#!/usr/bin/env python
def slow_divide(x, y):
res = 0
while x >= y:
x = x - y
res += 1
return res
def divide(x, y):
@gustavoatt
gustavoatt / gist:3225094
Created August 1, 2012 08:44
List reverse
#!/usr/bin/env python
class List(object):
def __init__(self):
self.val = None
self.next = None
def add(self, val):
current = self
while current.next is not None:
@gustavoatt
gustavoatt / gist:3217842
Created July 31, 2012 15:30
Sort of a stack with two stacks using insertion sort
#!/usr/bin/env python
from collections import deque
# Sort using insertion sort with stacks O(n^2)
def sort_stack(l):
res_stack = deque()
# We keep res_stack always sorted
while len(l) > 0: