Skip to content

Instantly share code, notes, and snippets.

View danbst's full-sized avatar

Danylo Hlynskyi danbst

  • Ivano-Frankivsk, Ukraine
View GitHub Profile
@danbst
danbst / README.md
Last active November 13, 2024 15:46
Matrix multiplication in logarithmic space. Incoming matrices are logs of their values, result values are logs of real values. The benefit is that multiplication is not used

Matrix multiplication without multiplication

The basic idea is to transform dot product into log form:

log(a.b) = log(a1*b1 + a2*b2 + ... + an*bn) 
  = log(exp(log a1+log b1) + exp(log a2+log b2) + ... + exp(log an+log bn))

and then apply something like Horner's method, but for exp-s, so result looks like (I'll simplify log a1 to la1, log a2 to la2, ...):

{
"meta": { "theme": "elegant" },
"basics": {
"name": "Danylo Hlynskyi",
"label": "Software engineer / DevOps / Educator",
"image": "",
"email": "[email protected]",
"phone": "+380983978707",
"url": "https://github.com/danbst",
"summary": "Programmer, engineer with rich production experience: .NET GUI, game server, game client and web application backend.\n\nAlso looking for ways to improve computer science education!",
@danbst
danbst / failed_SMART.txt
Created January 23, 2022 12:36
Example of SMART (S.M.A.R.T.) test for failing device
[nixos@nixos:~]$ sudo smartctl -a /dev/sdb
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.10.62] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Model Family: Toshiba 3.5" DT01ACA... Desktop HDD
Device Model: TOSHIBA DT01ACA200
Serial Number: 84QBH18TS
LU WWN Device Id: 5 000039 ffad3500c
Firmware Version: MX4OABB0

Мінімальна кількість купюр

Тут мені підігнали простеньку задачку. Звучить вона так:

Ну допустимо у мене є монетки двушки (2грн) і п'ятішки (5грн). І з них треба зібрати певну суму грн, допустимо, 123 грн. Яка найменша кількість монеток потрібна щоб набрати цю суму?

Ну і потім задачка просить вирішити не тільки для 123 грн, а й для всіх 8 <= N <= 1000000

Математики люблять такі задачки

@danbst
danbst / all_cars.json
Last active October 3, 2021 06:56
Attempt to implement BeamNG.drive in python turtle
{"test1": [[[-50.0, 0, 0], [-50.0, 83.0, 1.0], [-50.0, 85.0, 32.0], [-50.0, 51.0, 35.0], [-38.167938931297705, 47.0, 131.0], [-38.167938931297705, 52.0, 131.0], [-28.571428571428573, 57.0, 175.0], [-29.239766081871345, 51.0, 171.0], [-37.31343283582089, 45.0, 134.0], [-28.901734104046245, 50.0, 173.0], [-25.641025641025642, 50.0, 195.0], [-25.380710659898476, -9.0, 197.0], [-34.96503496503497, -14.0, 143.0], [-50.0, -10.0, 43.0], [-50.0, -56.0, 43.0], [-50.0, -49.0, -2.0], [-50.0, -17.0, -4.0], [-50.0, -13.0, 20.0], [-50.0, 42.0, 22.0], [-50.0, 44.0, -5.0], [-50.0, 82.0, -0.0]], [[50.0, 0, 0], [50.0, 83.0, 1.0], [50.0, 85.0, 32.0], [50.0, 51.0, 35.0], [38.167938931297705, 47.0, 131.0], [38.167938931297705, 52.0, 131.0], [28.571428571428573, 57.0, 175.0], [29.239766081871345, 51.0, 171.0], [37.31343283582089, 45.0, 134.0], [28.901734104046245, 50.0, 173.0], [25.641025641025642, 50.0, 195.0], [25.380710659898476, -9.0, 197.0], [34.96503496503497, -14.0, 143.0], [50.0, -10.0, 43.0], [50.0, -56.0, 43.0], [50.0, -
@danbst
danbst / turtle3d_grid.py
Created October 1, 2021 20:07
Python turtle 3d soft render (+WASD movement and camera rotation)
"""
Черепашка вміє в 3D
Управління:
- стрілочки -- поворот
- WASD -- рух
"""
import turtle
import math
@danbst
danbst / bf.py
Created April 21, 2021 11:29
BRAINFCK (for python 3.9)
code = """V*mgE00000000000000000jU506+i$0COY&002h-WB_CVgaBj#g92IrWCCOZgaBFrWC>&kWC(--S^{JR
QvfLnV*mgE00000000000000000RI306+i$0CN@q003nGS^;DLS^{JRWCLUbgaKLuWC2qEDF)gFQ*>c;
Wlre;0001E0{{R300000000000{{R30ssI2LjV8(a~c2u0DJ**2z&u<1Y`kc0ek>o0DJ;`0AB%Q08;=d
0#0%P0000f0@?#%a&p=QX>Md?cqs$g1aoC<W^w`m0043W0001~0CEKY008<4Vsc?=Ze}iUdD;kHUukY>
bYEWs0001U1ONa4009sIdJa=`VRU6KUtei%X>?y-DFRM%0RR91DFoUGUtexvZDn6y+6rG^ZEs|CY-L|x
+6-S`adlyAZeeX@Ute+u0001T1poj5as>bY0CEKY0043Z0001T000000ssI2a{>SW00;qc00000V*&sG
000000000000IC200jU507C!(0CVyH004XeWC3deawdELY5;ryY5^GlWC9leWCIoed;n?yd;n?zJOFOU
d;w$xYXWjid;n?yd;n?z831Gg7yx7g765zzY5;ryY5_a|ZlZhvWCd#ia)5jQ1ORFQWCAw;0svnDbOL+;
Y5;=)d;n?zYXWlad;n?ypaWzEp#cE^Zf<-5WCv>ka;SU&1ORFQWCAz<0svnDd;n?zWCm*ha_(dXd;nho
Zbp0oWC&{la?ErDbOn3>Y5;ryY5^Glg8^g-WC~;pjROGyZX$dEWDIKpa_)2nbO(a~WCj@kg8^g%765zz
@danbst
danbst / trainer.py
Created February 22, 2021 13:46
Trainer for powers of 2, inverse powers of two and indexof in Python
import time
import random
from datetime import datetime
from pprint import pprint
import pickle
import math
class PowerTwo:
"""
Trainer for powers of two
@danbst
danbst / alphabetize.py
Last active November 4, 2021 20:32
Пачка програм
"""
Алфавіт-квіз, автор Al Sweigart [email protected], переклав Данило (danbst)
"""
import random, time
QUESTION_SIZE = 5
QUIZ_DURATION = 30
abc = {}
@danbst
danbst / maze.py
Created November 20, 2020 00:34
Maze generation using Randomized Prim's algorithm
def maze(width=10, height=10):
def sides(field, x, y):
sides_ = []
if x > 0:
sides_.append((-1,0))
if x < len(field[y]) - 1:
sides_.append((1,0))
if y > 0:
sides_.append((0,-1))
if y < len(field) - 1: