Skip to content

Instantly share code, notes, and snippets.

View zofy's full-sized avatar

Patrik Puchala zofy

  • https://www.ims.co.at/
  • Vienna, AT
View GitHub Profile
@zofy
zofy / tree_manager.hs
Created January 5, 2019 16:32
Haskell solution (using zipper) for tree_manager task at https://hackerrank.com
import Data.List (isPrefixOf, intercalate)
import Data.List.Split
import Control.Monad
data Tree a = Empty | Node a [Tree a] deriving (Show, Eq)
type Zipper a = (Tree a, [Tree a], [Int])
_nthItem :: [a] -> Int -> a
_nthItem (x:xs) 1 = x
@zofy
zofy / permutations.py
Created October 30, 2018 13:44
Lexicographical permutations algorithm
from itertools import chain, permutations as perm
from operator import ge, gt, le, lt
# Algorithm for finding permutations by moving from permutation to next lexicographical permutation
# for more info: https://www.nayuki.io/page/next-lexicographical-permutation-algorithm
def _suffix(cont, op):
"""