Skip to content

Instantly share code, notes, and snippets.

View izanbf1803's full-sized avatar

Izan Beltran izanbf1803

View GitHub Profile
@izanbf1803
izanbf1803 / IterativeSegmentTree.cc
Last active September 6, 2018 11:31
Compact and fast Iterative Segment Tree basic implementation.
// Reference: http://codeforces.com/blog/entry/18051
template <typename T>
struct SegmentTree {
int n;
T* t;
T zero_val;
inline T operation(T a, T b)
{
return max(a, b);
@izanbf1803
izanbf1803 / Button.h
Created July 1, 2018 19:56
Arduino Button class.
#include <arduino.h>
class Button
{
public:
Button(int pin);
void setup() const;
inline int clicked() const { return _clicked; };
void update();
private:
@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;
@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 / .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 / 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 / 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 / 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 / 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 / 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