Skip to content

Instantly share code, notes, and snippets.

@feltmax
feltmax / main.c
Created October 6, 2019 18:06
Floyd's cycle-finding algorithm in C/C++
int f(int n)
{
int p = 1, q = 1;
int s = 0, t = 0; // start : s, goal : t
while(1)
{
p = (p*10)%n;
q = (q*10)%n;
q = (q*10)%n;
if(p==q) break;
@feltmax
feltmax / main.py
Last active October 6, 2019 18:05
get variable name list in python3
var_name = lambda val : [k for k, v in globals().items() if id(v) == id(val)]
a = 1
s = var_name(a)[0]
@feltmax
feltmax / convert.py
Created October 6, 2019 17:45
ttf2png (convert ttf font files to png images)
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Tamflex
# Released under the MIT license
# https://opensource.org/licenses/mit-license.php
# reference:
# http://stackoverflow.com/questions/4458696/finding-out-what-characters-a-font-supports
@feltmax
feltmax / figure.py
Last active October 24, 2019 01:15
wrapper library for matplotlib
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# matplotlib wrapper
# Copyright (c) 2019 Tamflex
# Released under the MIT license
# https://opensource.org/licenses/mit-license.php
__all__ = ["Figure"]
@feltmax
feltmax / graph.cpp
Last active July 6, 2019 16:26
graph class
template<typename T> struct Edge
{
int src, dst; T w;
Edge() {};
Edge(int src, int dst): src(src), dst(dst) {w=1;}
Edge(int src, int dst, T w): src(src), dst(dst), w(w){}
bool operator<(const Edge &e)const{return w != e.w ? w > e.w : (src != e.src ? src < e.src : dst < e.dst);}
bool operator==(const Edge &e){return src == e.src && dst == e.dst;}
};
@feltmax
feltmax / point.cpp
Last active April 17, 2016 06:16
computer geometry
class P
{
public:
double x,y;
P(){};P(double x,double y):x(x),y(y){};
P &operator+=(const P&q){x+=q.x;y+=q.y;return *this;}
P &operator-=(const P&q){x-=q.x;y-=q.y;return *this;}
P operator+(const P&q){P t;t.x=x+q.x;t.y=y+q.y;return t;}
P operator-(const P&q){P t;t.x=x-q.x;t.y=y-q.y;return t;}
template<typename T> P &operator*=(T d){x*=d;y*=d;return *this;}
@feltmax
feltmax / modulo.cpp
Last active April 17, 2016 06:03
modulo calculator
template <long long modulo>
class Modulo
{
private:
long long pow(long long q)
{
long long a=1;
long long y=x;
for(;q!=0;q>>=1)
{