Skip to content

Instantly share code, notes, and snippets.

@walac
walac / mergesort.py
Last active December 11, 2015 08:29
A (kind of) functional implementation of the merge sort algorithm in Python.
def merge(a, b):
if not a:
return b
if not b:
return a
return a[:1] + merge(a[1:], b) if a[0] < b[0] else b[:1] + merge(a, b[1:])
def mergesort(a):
len_a = len(a)
if len_a == 1:
@walac
walac / name.sh
Last active May 28, 2016 02:25
A simple script to make the .avi and .srt file names of my favorite series equal.
#!/bin/bash
if [ $# -gt 0 ]; then
basepath="$1"
else
basepath=
fi
for i in "${basepath}"*.mkv; do
e=$(echo "${basepath}"$i | sed -e 's/.*[Ss][0-9]\+[Ee]\([0-9]\+\).*/\1/')
@walac
walac / NextPermutation.nb
Created August 22, 2012 00:07
An ugly "hurry up" implementation of NextPermutation algorithm in Mathematica
Vk[p_List] :=
Module[{r =
DeleteCases[
MapIndexed[If[#1[[1]] < #1[[2]], Length[p] - First[#2]] &,
Reverse@Partition[p, 2, 1]], Null]},
If[Length[r] > 0, First[r], Null]]
Vl[p_List, k_Integer] :=
Module[{r =
DeleteCases[