Skip to content

Instantly share code, notes, and snippets.

@Tsunamicom
Tsunamicom / Permutations
Created February 23, 2016 16:56
Python permutations
def perm(text):
if len(text) == 1:
return [text]
else:
sub_perm = perm(text[1:])
first = text[0]
permutations = list()
for subset in sub_perm:
for i in range(len(subset)+1):
permutations.append(subset[:i]+ first+subset[i:])
@Tsunamicom
Tsunamicom / MultiplyInt
Last active February 23, 2016 23:38
Python Multiply Integers Recursive
def mult (a, b):
if b == 1: return a
elif b == 0: return 0
elif b < 0: return mult (-a, -b)
else: return a + mult (a, b-1)
@Tsunamicom
Tsunamicom / Matrix_Script.py
Last active April 14, 2016 05:24
Hackerrank: Matrix Script
# Python 3.4 Solution to Matrix Script Problem by Kurtis Mackey
# https://www.hackerrank.com/challenges/matrix-script
import re
# Import original script
matrix = list()
for _ in range(int(input().split()[0])):
matrix.append(list(input()))
@Tsunamicom
Tsunamicom / Longest_Palindrome.py
Created June 4, 2016 20:08
Longest Palindrome
import unittest
def ispalindrome(string):
"""Given a string, returns True if it is a Palindrome.
Notes: Case insensitive,
Spaces considered: (' aba ') == True
"""
string = string.lower()
return string == string[::-1] # Returns True if Palindrome
# Written in Python 3.51 by Kurtis Mackey (Developed Test First)
# Binary Search
import unittest
def binary_search(array, num):
"""Given a sorted array of numbers,
return True of num is in the array
using Binary Search.
"""
@Tsunamicom
Tsunamicom / VerboseNumberExample.cs
Last active February 4, 2019 10:55
Represent a number string as verbose
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Linq;
public static class Program
{
static void Main()