Skip to content

Instantly share code, notes, and snippets.

View afeistel's full-sized avatar
🟣
ourple

Alisa Feistel afeistel

🟣
ourple
View GitHub Profile
### Keybase proof
I hereby claim:
* I am afeistel on github.
* I am feistel (https://keybase.io/feistel) on keybase.
* I have a public key ASDA9WBN3Jy0tp8agq5Vg_dmheP3O9gBEgPIHYLAwI-4mgo
To claim this, I am signing this object:
@afeistel
afeistel / sample.rs
Last active January 1, 2024 21:35
I used this to debug ruchei's performance
use std::{
sync::atomic::{AtomicBool, Ordering},
thread,
time::Duration,
};
static SAMPLE: AtomicBool = AtomicBool::new(false);
fn set_sample(sample: bool) {
SAMPLE.store(sample, Ordering::Release)
#include <stdio.h>// Usage: find k (<=n) roots of polynomial f such that deg f=n; Input: n c_0 c_1 ... c_n | c_i: double
#include <math.h>// Output: roots:k x:x_1 f:f(x_1) x:x_2 f:f(x_2) ... x:x_k f:f(x_k) | x, f: double | roots are ordered
#include <float.h>// non-descenging. Note that roots can be repeated due to divisibility of f by (x-root)^k where k > 1!
#define P(o)if(B o T){for(u i=2048;i;--i){d m=(b+t)/2;*((d*[]){&b,&t})[0 o a(n,c,m)]=m;}return b;}// (c) afeistel 2020~5
typedef double d;typedef unsigned short u;d a(u n,d*c,d x){d r=0;for(u i=n;i;--i)r=(r+c[i])*x;return r+c[0];}d s(u n,d*c
,d b,d t){d B=a(n,c,b);d T=a(n,c,t);P(<=)P(>=)return NAN;}u h(u n,d*c,d*g,u*r){while(n&&!c[n])g[--n]=NAN;if(n==0)return-
0;for(u i=1;i<=n;++i)c[i]*=i;h(n-1,c+1,g+1,r);for(u i=1;i<=n;++i)c[i]/=i;g[0]=-DBL_MAX;u j=0;for(u i=0;i<*r+1;++i){d t=i
<*r?g[i+1]:DBL_MAX;d B=a(n,c,g[i]);d T=a(n,c,t);if(B<=0&&0<=T||B>=0&&0>=T)g[j++]=s(n,c,g[i],t);}for(u i=j;i<n;++i)g[i]=-
NAN;*r=j;return 0;}int main(){u n;scanf("%hd",&n);d c[n+
@afeistel
afeistel / DuckGame synchronization.md
Last active January 6, 2020 19:14
That's shortened result of tens of hours of pain

1. Basics

Nothing updates on its own if you don't make it do so.

2. StateBinding

e.g. you have field "Switch" (public bool Switch)
then you add public readonly StateBinding SwitchBinding = new StateBinding(nameof(Switch)) (almost equivalent to public readonly StateBinding SwitchBinding = new StateBinding("Switch"))
any time Switch changes locally, signal is sent to change it on every connected PC

3. SB limitations

you cannot just sync everything. it lags
you cannot just sync everything. some types are unserializable by default
you cannot just sync everything. oversync sometimes leads to less sync\