Skip to content

Instantly share code, notes, and snippets.

@Neverik
Neverik / Structured.kt
Created November 23, 2018 14:28
A puzzle solution (I will maybe refactor this)
import kotlinx.coroutines.*
import java.util.Random
import kotlin.system.exitProcess
// We have a worker who makes machines every 800ms as long as there is less than 5 of them
// Every machine produces a code using `produce` function every second. It saves this code to shared space. In case of an error, it ends working.
// We have a single manager that once a 2 seconds takes all produced codes and prints them all. After 5 times it ends all jobs (including machines and worker).
class Message(val id: String, val txt: String, var new: Boolean = true) {
override fun toString(): String {
@Neverik
Neverik / polynomial.js
Created June 15, 2018 14:35
A universal approximator that doesn't work properly yet.
const xs = [];
const ys = []
let poly = null;
const opt = tf.train.adam(0.001)
const iter = 1
function polynomial (i, o, n) {
this.i = i
this.o = o
this.n = n
ns = [1750, 1602, 3954, 4716]
ans = [(1, 1), (1, 1), (1, 1), (1, 1)]
def bc (a, b):
bs = 0
cs = 0
for i1, i2 in zip(a, b):
if i1 == i2:
bs += 1
elif i1 in b:
@Neverik
Neverik / phi.py
Created May 2, 2018 14:38
Perfect phi calculator - from a quick burst of inspiration.
phi = 1
precision = 0.5
while True:
n1 = phi + precision
n2 = phi - precision
diff1 = abs((n1 - 1 / n1) - 1)
diff2 = abs((n2 - 1 / n2) - 1)
if diff1 < diff2:
precision = diff1
phi = n1
@Neverik
Neverik / solver.py
Last active April 13, 2018 04:42
Rebus problem solver (repl.it/repls/SizzlingBisqueIntegers to run)
from itertools import permutations
from functools import reduce
import sys
si = ""
print("Rebus SolvR by Neverik. Copyright 2018.")
print("Enter text or 'exit' to escape.")
while True:
sinp = input("Enter: ")
for i in sinp:
@Neverik
Neverik / clock.py
Created January 20, 2018 15:10
Clock handle problem solution
#self-adjusting clock class
class Clock:
def __init__(self,h,m,s):
self.s = s
self.m = m + self.s/60
self.h = h + self.m/60
def angle_hm(self):
return abs(self.h - self.m)
def angle_ms(self):
return abs(self.m - self.s)