Skip to content

Instantly share code, notes, and snippets.

@dlozeve
dlozeve / strength.py
Last active December 9, 2017 13:10
Find the number N_max from the interval [60000, 1000000] that has the highest strength among all numbers in the interval
#!/usr/bin/env python3
from functools import reduce
from multiprocessing import Pool
from operator import itemgetter
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1)
@dlozeve
dlozeve / cellularautomata.hs
Last active February 15, 2018 18:05
Cellular automata
#!/usr/bin/env stack
-- stack script --resolver lts-10.5
{-# LANGUAGE DeriveFunctor #-}
import Data.List
import Control.Comonad
import System.Random
import System.Environment
data Zipper a = Zipper [a] a [a]
@dlozeve
dlozeve / i3_config
Created January 13, 2019 13:20
i3 config
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This script is a simple wrapper which prefixes each i3status line with custom
# information. It is a python reimplementation of:
# http://code.stapelberg.de/git/i3status/tree/contrib/wrapper.pl
#
# To use it, ensure your ~/.i3status.conf contains this line:
# output_format = "i3bar"
# in the 'general' section.
#!/bin/bash
TPdevice=$( xinput | sed -nre '/Touchpad/s/.*id=([0-9]+).*/\1/p' )
state=$( xinput list-props "$TPdevice" | grep "Device Enabled" | grep -o "[01]$" )
if [ "$state" -eq '1' ];then
xinput --disable "$TPdevice"
else
xinput --enable "$TPdevice"
fi
range←{-1-(⍳⍵)÷(⍵÷2)} ⍝ between ¯1 and 1
grid←(range ∘.{⍺+0j1×⍵} range)
f←{⍺+⍵*2}
iter←{⍵ (f⍣⍺) 0} ⍝ ⍺ is the number of iterations
mandelbrot←{2 > | ⍺ iter 2 × grid ⍵} ⍝ ⍺ is still the number of iterations, ⍵ is the resolution of the grid
@dlozeve
dlozeve / eigvals.txt
Last active March 20, 2019 16:38
Eigenvalues of random matrices from the Ginibre ensemble
Eigenvalues of a 2000×2000 random matrix from the Ginibre ensemble
┌────────────────────────────────────────┐
1.5 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢀⡄⣠⣤⢤⣧⣄⡤⡠⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⣐⢔⡾⣿⠳⡽⣯⢿⢷⡯⡿⣹⡽⣿⣽⢾⣰⣠⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠠⣰⡺⣽⣷⢏⣶⢽⣻⣻⣫⣿⡯⣿⢟⡿⣿⢿⣟⣯⣺⢷⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⣀⣿⣻⡟⣷⣷⡕⣛⢯⢾⣾⠯⢾⣿⡷⣝⣯⡯⣷⣋⢟⣿⣟⣿⢳⣀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⢿⡯⣿⣷⡵⣷⣪⣿⣷⣫⢯⡾⡽⣿⡜⣿⡷⣕⡿⣟⣿⣻⣳⡿⣽⣋⡆⠀⠀⠀⠀⠀⠀│
│⠤⠤⠤⠤⠤⠤⢼⣿⣿⣿⢽⣯⡯⢿⣾⢽⡿⣽⢽⣽⡿⢷⡿⢿⣵⣿⣽⣿⢮⢿⣯⣧⣿⠥⠤⠤⠤⠤⠤⠤│
@dlozeve
dlozeve / gaussianprocess.jl
Created March 21, 2019 16:13
Gaussian Process Sampling
using LinearAlgebra
using Distributions
using Plots
plotly()
m(x) = 0.25*x^2
k(x,y) = exp(-0.5 * (x-y)^2)
xmin = -5
xmax = 5
using ProgressMeter
using Plots
plotly(size=(500,500))
function updatesandpile!(d, i, j)
n = get(d, (i,j), 0)
if n >= 4
d[(i-1,j)] = get(d, (i-1,j), 0) + 1
d[(i+1,j)] = get(d, (i+1,j), 0) + 1
d[(i,j-1)] = get(d, (i,j-1), 0) + 1
#!/usr/bin/awk -f
BEGIN {
FS = "\t";
}
$2 ~ "^" ARGV[2] "$" {
count++;
if (count > 10)
exit;