Skip to content

Instantly share code, notes, and snippets.

@jassler
jassler / generateMonotonicPrs.py
Created April 5, 2023 08:41
Generate monotonic power relations. For an R implementation, see here: https://replit.com/@jassler/Create-Monotonic-Rankings
import time
import json
### SETTINGS ###
# number of elements
N = 4
# save cache dictionary?
# if True, file 'N=3.txt' is created ('3' is replaced by whatever N is)
SAVE_CACHE_TO_FILE = False
@jassler
jassler / max_heapify.py
Created March 10, 2023 13:54
A max_heapify implementation in Python. Main purpose here is to find the indexes that cause the most recursive call for a given array.
import readline
def max_heapify(A, s, recCall = 1) -> int:
left = 2*(s+1)-1
right = 2*(s+1)
if left < len(A) and A[left] > A[s]:
largest = left
else:
largest = s
@jassler
jassler / banzhaf_and_shapleyshubik.R
Created March 6, 2023 14:56
A small application to demonstrate the calculation steps for the Banzhaf Score and Shapley-Shubik Index sing the methods proposed by Kirsch, Werner, and Jessica Langner. "Power indices and minimal winning coalitions." Social Choice and Welfare 34.1 (2010): 33-46.
# A small application to demonstrate the calculation steps for the Banzhaf Score and Shapley-Shubik Index
# using the methods proposed by Kirsch, Werner, and Jessica Langner. "Power indices and minimal winning coalitions." Social Choice and Welfare 34.1 (2010): 33-46.
library(shiny)
library(sets)
library(partitions)
library(socialranking)
library(MASS)
@jassler
jassler / FindWeightsForMinimalWinningCoalitions.R
Created January 17, 2023 23:16
Weighted voting games in cooperative game theory describes a set of players with a certain voting power (also weight), as well as a quota that has to be surpassed in a vote for a coalition of players to be deemed a winning coalition.
######################################
# List of minimal winning coalitions #
######################################
mwcs <- list(c(1,2), c(1,3,4), c(1,3,5), c(1,4,5))
quota <- 6
onlyIntegerSolutions <- TRUE
######################################
# All the other stuff #
######################################
const { Telegraf } = require('telegraf')
var https = require('https');
https.get('https://lichess.org/api/puzzle/daily', res => {
var body = ''
res.on('data', chunk => body += chunk)
res.on('end', () => sendPuzzle(JSON.parse(body)))
})
function sendPuzzle(game) {
@jassler
jassler / sarsa_and_qlearning.py
Created February 10, 2022 23:02
Basic implementation of Q-Learning and SARSA to compare their path finding skills
from collections import defaultdict
import random
actions = ['N', 'E', 'S', 'W']
transition = {
'N': lambda s: (s[0] - 1, s[1]),
'S': lambda s: (s[0] + 1, s[1]),
'E': lambda s: (s[0], s[1] + 1),
'W': lambda s: (s[0], s[1] - 1)
}
@jassler
jassler / Unzippidy.cs
Last active October 19, 2021 18:31
Unzip first command line argument to Downloads folder on Windows
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Windows;
namespace Unzippidy
{
class Program
{