Skip to content

Instantly share code, notes, and snippets.

View izanbf1803's full-sized avatar

Izan Beltran izanbf1803

View GitHub Profile
@izanbf1803
izanbf1803 / Repeating decimals to fraction.py
Last active September 12, 2017 21:27
Convert repeating decimals to fractions.
import sys
def err(section):
print("ERROR [{section}]: Bad input (not a number)".format(section=section))
sys.exit(1)
def stoi(s):
return int("".join(("0" + s)))
def int_repeat(n, k):
@izanbf1803
izanbf1803 / tron_bot.cpp
Created September 12, 2017 21:32
codingame.com tron bot
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <array>
#include <algorithm>
#include <cmath>
using namespace std;
@izanbf1803
izanbf1803 / nqueens.cpp
Created October 4, 2017 16:42
N-Queens solution counter.
// Use N <= 30 (good luck to calculate that)
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
// bits values for bit arrays:
// 1 = free
// 0 = used
@izanbf1803
izanbf1803 / kruskal.cpp
Created October 14, 2017 17:34
kruskal's MST algorithm
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct DisjointSet {
vector<int> parent;
vector<int> size;
};
@izanbf1803
izanbf1803 / valid_triangles.py
Created November 12, 2017 20:22
Generate valid triangles (convex) given list of points.
import itertools, math
def dist(a, b):
# 2d distance
dx = a[0] - b[0]
dy = a[1] - b[1]
return math.sqrt(dx*dx + dy*dy)
def valid_triangle(t):
# Check if triangle is valid (area > 0)
@izanbf1803
izanbf1803 / factorial_digit_count.cc
Created November 19, 2017 12:16
Get number of digits in factorial result without compute it.
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
ld factorial_digit_count(ld n)
{
// log(ab) = log(a) + log(b)
@izanbf1803
izanbf1803 / LaTeX_template.tex
Last active November 25, 2017 00:05
LaTeX template (spanish, math).
\documentclass{article}
\usepackage[spanish]{babel}
\selectlanguage{spanish}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{0pt}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{cancel}
\begin{document}
@izanbf1803
izanbf1803 / .gitignore
Last active January 4, 2018 22:32
.gitignore for C++ competitive programming.
# Ignore all but files for competitive programming
*
!.gitignore
!*.cc
!*.txt
!*.cpp
!*/
!Makefile
@izanbf1803
izanbf1803 / server_time.js
Last active May 30, 2018 10:05
Get time from server.
let get_server_time = () => {
let req = new XMLHttpRequest();
req.open("GET", document.location, false);
req.send(null);
let date = new Date(req.getResponseHeader("Date"));
return date.getTime();
}
@izanbf1803
izanbf1803 / perfect_primes.c
Created June 11, 2018 20:29
Find all perfect primes in range.
#include <stdio.h>
#include <string.h>
#define N 1000000000000000000ULL
short is_prime(unsigned long long n)
{
unsigned long long i;
if (n < 2) return 0;
if (n == 2) return 1;