Skip to content

Instantly share code, notes, and snippets.

View syminical's full-sized avatar

Alexandru Manaila syminical

View GitHub Profile
@syminical
syminical / string_permutations_tail_recursion.py
Last active November 17, 2021 20:28
String Permutations - Tail Recursion - Algorithms to generate all possible permutations of a given string. Why aren't "curried string trees" a thing? I tried my best to stick with tail-recursion, but Python didn't like it.
# This was my idea before starting to code:
#[c, a, t]
#[a, t]
#[t, a]
#[(c, [(a, [(t, [])]), (t, [(a, [])])]), (a, [(c, [(t, [])]), (t, [(c, [])])]),...]
#[[cat, cta], [act, atc],...]
#[cat, cta, act, atc]
# Runtime: O(2^n)
# create a list of nested tuples and arrays (char, [tuples]) to represent curried strings
@syminical
syminical / heap_sort_tail_recursion.py
Last active November 12, 2021 06:47
Heap Sort in Python - Tail-recursion and state change :)
# Copyright (c) 2021 Alexandru Manaila. All Rights Reserved.
# 2021/11/10
# Python is not the best for this, but the syntax makes it worth it.
# Set state_logging to false if you would rather see tests instead of state changes.
# heap_sort, fix_heap_up, and fix_heap_down are tail-recursive.
# They reduce their parameters and re-call themselves until they can return an answer.
try_me = [1,3,2,5,4]
state_logging = True
@syminical
syminical / meeting_matchup.py
Last active April 1, 2021 01:09
Scheduling Matchup - I paused the video around 9 min and solved the problem. :) https://youtu.be/kbwk1Tw3OhE
# https://youtu.be/kbwk1Tw3OhE
# I paused the video around 9 min and solved the problem. :)
# Take a time tuple and return a 2-tuple of ints representing the length of the input meeting.
# e.g. ('10:00', '10:30') => (0, 30)
def meeting_len(meeting):
start = meeting[0].split(':')
end = meeting[1].split(':')
return (abs(int(end[0])-int(start[0])), abs(int(end[1])-int(start[1])))
@syminical
syminical / shorestPath2DMatrix.py
Created July 20, 2020 07:22
This method calculates the shortest distance in a 2D matrix. The input matrix is a string, and the rows are separated by semi-colons.
# Copyright (C) 2020 Alexandru Manaila
# Python3
def calculateDistance(cityMap):
#helpers
def addSpot(x, y, v):
#spot is valid for a path, and spot has not been visted or overlaping path is shorter.
if mapMatrix[y][x] == '_' and (distanceMatrix[y][x] == -1 or distanceMatrix[y][x] > v):
#New spot has to be checked.
pathStack.append((x, y))
@syminical
syminical / WeirdTextFormat.py
Last active July 20, 2020 07:26
WeirdTextFormat - This class handles encoding and decoding of text using the weird text format.
# Copyright (c) 2020 Alexandru Manaila. All Rights Reserved.
# 2020/3/12
import math
class AWeirdTextFormat:
"""
This class handles encoding and decoding of text
using the weird text format.
"""
@syminical
syminical / 410100_collect_5_fire_elementals.cs
Last active January 12, 2019 11:18
Aura Christmas Weather Event
//--- Aura Script-------------------------------------
// Collect fire elementals
//--- Description-------------------------------------------
// Allows people to make mass elementals
//----------------------------------------------------
public class Collect10FireElementalsQuestScript : QuestScript {
public override void Load() {