Skip to content

Instantly share code, notes, and snippets.

View BelegCuthalion's full-sized avatar
🏹
Wandering

Alireza BelegCuthalion

🏹
Wandering
  • Tehran
View GitHub Profile
def determinant(matrix):
n = len(matrix)
if (n == 1):
return matrix[0][0]
else:
sum = 0
for c in range(n):
sum += ((-1) ** c) * matrix[0][c] * \
determinant([matrix[x][:c]+matrix[x][c+1:] for x in range(1, n)])
return sum
def list2Int(l):
n = 0
for i in range(len(l)):
n += l[i] * (10 ** (len(l)-i-1))
return n
def next_smaller(n):
n = list(str(n))
n = [int(x) for x in n]
def snail(snail_map):
s = snail_map
n = len(s)
l = []
if n > 1:
for i in range(n):
l.append(s[0][i])
for i in range(1, n-1):
l.append(s[i][n-1])
from math import sqrt
def prime_factors(n):
s = ""
l = sorted(factorsList(n))
l.append(-1) # this addintional element helps the last element in l to appear in s
# but itself won't appear in s
d = l[0]
i = 0
for n in l:
@BelegCuthalion
BelegCuthalion / art.sh
Created March 31, 2021 09:58
Help an artwork to exist.
GET https://thisartworkdoesnotexist.com/ | feh - --zoom max -B black
@BelegCuthalion
BelegCuthalion / main.yml
Created December 3, 2020 23:13
CI for Latex
name: build-v-tags
on:
push:
tags:
- 'v*'
jobs:
latex-job:
runs-on: ubuntu-latest
name: Latex Job
@BelegCuthalion
BelegCuthalion / beyt.sh
Last active May 3, 2023 01:50
Farsi poetry to brighten up your day... of course not! Not over here. Try your luck with... French maybe.
#!/bin/bash
response=`curl -s "http://c.ganjoor.net/beyt-json.php"`
m1=`echo $response | jq -r ".m1"`
m2=`echo $response | jq -r ".m2"`
poet=`echo $response | jq -r ".poet"`
# fribidi still monkeys with the output tho
echo -e "$m1\n$m2\n$poet" | fribidi
@BelegCuthalion
BelegCuthalion / rostam.hs
Last active May 10, 2019 16:57
Rostam is preparing to confront rather _complex_ demon, with many eyes and heads. If he cut any of her n-eyed heads, she grows n-1 new heads: a k-eyed head for each k in {1,...,n-1}. The cunning warrior he is, Rostam ponders upon this task; How many heads he should sever? Does its order make any difference? Is it even possible in his mortal fini…
{-# LANGUAGE UnicodeSyntax #-}
type Writer a = (a, String)
type CutMethod = [Integer] → [Integer] → [Integer]
type CutDiary = (CutMethod, Writer [Integer])
return ∷ a → Writer a
return x = (x, "")
depthFirst ∷ CutMethod
@BelegCuthalion
BelegCuthalion / frank.sh
Created January 26, 2019 15:57
Not a Quine, but has one inside.
q=\' a='q=\\$q a=$q$a$q\; eval eval echo \$a'; eval eval echo $a