Skip to content

Instantly share code, notes, and snippets.

View andreuinyu's full-sized avatar

Andreu Punsola Soler andreuinyu

View GitHub Profile
@andreuinyu
andreuinyu / Clock_creator.pde
Last active August 29, 2015 14:05
This program allows you to generate n-hour clocks with the hand pointing at the f-th hour. I wrote this program to use the images to explain simple modular arithmetic visually.
void setup(){
size(350, 350);
background(255,255,255);
textSize(26);
}
void arrow(int x1, int y1, float x2, float y2) {
line(x1, y1, x2, y2);
pushMatrix();
translate(x2, y2);
float a = atan2(x1-x2, y2-y1);
@andreuinyu
andreuinyu / gist:d98c12f81c49e2df4e85
Created October 28, 2014 19:05
Animation of Hendrik Lenstra's Elliptic Curve Factorization checking the primality of an integer
n = 1997 #must be prime: defines the field Z/nZ
k = 720719 #the point (0, 1) is "multiplied" by k
coeff = 23 #coefficient of "x" in the elliptic curve
x, y = var('x y')
E = EllipticCurve(GF(n),[coeff,1])
llistapunts = []
frames = []
tamany = 40
marc = implicit_plot(x-y^3, (x, 0, n-1), (y, 0, n-1), color = 'white', gridlines = True)
tamanyextra = tamany + tamany//2
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
struct punt{
int x;
int y;
int z;
};
@andreuinyu
andreuinyu / Ackerman.cc
Last active January 18, 2016 20:42
Ackerman
#include <iostream>
using namespace std;
int ackerman(int a, int b){
if (a==0) return b+1;
else if (b==0) return ackerman(a-1, 1);
else return ackerman(a-1, ackerman(a, b-1));
}
int main(){
@andreuinyu
andreuinyu / Llei de Grup Modular.cc
Last active January 18, 2016 20:43
Llei de Grup Modular en C++
#include <iostream>
#include <vector>
using namespace std;
struct punt{
int x;
int y;
int z;
};
#include <iostream>
#include <vector>
using namespace std;
struct p{
int a;
int b;
};
p mam(int x, vector<int>& v){
k = 27720
llista = []
while (k > 0):
if (k % 2 == 1):
llista.append("suma")
llista.append("dobla")
k = k//2
print(llista)
from random import randrange
from math import sqrt
def arrelsmod(x, n):
q = n-1
e = 0
while (q % 2 == 0):
q //= 2
e += 1
while(True):
from math import sqrt
N = 1997
A = 59
B = 23
coords = []
for x in range(N):
temp = (pow(x, 3, N) + A*x + B) % N
while (temp < 0):
temp += N
for i in range(N):
#include <iostream>
#include <vector>
using namespace std;
int first_occurrence(int x, const vector<int>& v){
if (v.size()==0) return -1;
int inici = 0, final = v.size()-1;
while (inici <= final) {
int m = (inici + final)/2;
if (v[m] < x) inici = m + 1;