Skip to content

Instantly share code, notes, and snippets.

View andreuinyu's full-sized avatar

Andreu Punsola Soler andreuinyu

View GitHub Profile
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):
@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
k = 27720
llista = []
while (k > 0):
if (k % 2 == 1):
llista.append("suma")
llista.append("dobla")
k = k//2
print(llista)
@andreuinyu
andreuinyu / Butler.py
Last active September 19, 2016 13:06
# -*- coding: utf-8 -*-
import os, platform
from tkinter import *
from tkinter import filedialog, messagebox
from os import walk
from tkinter import ttk
from time import sleep
global pathconfig
@andreuinyu
andreuinyu / BMP180.ino
Last active February 24, 2016 21:31
Arduino code to use with the BMP180 pressure and temperature sensor. SCL -> A5. SDA -> A4. Code worked out from the official datasheet: http://www.mouser.com/ds/2/783/BST-BMP180-DS000-12~1-786481.pdf
#include <Wire.h>
#define BMP180_I2C_Adress 0x77 //Usually 0x77
int p0 = 1013.25; //Pressure at sea level; used to calculate altitude
int i = 2; //Pressure precision setting: 0, 1, 2 or 3 (3 is broken right now. will fix.)
int AC1;
int AC2;
int AC3;
unsigned int AC4;
#include <Wire.h>
#include <VirtualWire.h>
#define BMP180_I2C_Adress 0x77 //Usually 0x77
//SCL at A4
//SDA at A5
int DataInPin = 4; //XY-MK-5V
int DataOutPin = 5; //XY-FST
int LEDsPin = 10; //LEDs strip
x, y = var('x y')
T = 7.5
P = []
for A in [-10,..,10]:
for B in [-10,..,10]:
P.append(implicit_plot(y^2==x^3+A*x+B, (x, -T, T), (y, -T, T)))
animate(P)
@andreuinyu
andreuinyu / ruleta.m
Created October 5, 2016 13:44
Ruleta
function [ bankrolls ] = ruleta(bankrollI, stakeI,apostes)
%bankrollI: diners amb els que comences a jugar
%stakeI: valor de l'aposta mínima
%apostes: número d'apostes a fer
close all
bankrolls = [bankrollI];
stake = stakeI;
for i = 1:apostes
bankrollI = bankrollI - stake;
bankrolls = [bankrolls bankrollI];
@andreuinyu
andreuinyu / DELTAHOURS.gs
Created January 14, 2017 10:47
Google Spreadsheet function that takes two strings in the format "January 1, 1970 at 00:00AM" and returns the time difference rounded into hours
function DELTAHOURS(date1, date2) {
//Takes two strings in the format "January 1, 1970 at 00:00AM" and returns the time delta in hours
var starthour = new Date();
var endhour = new Date();
//Month
switch (date1.slice(0, date1.indexOf(" "))){
case "January":
starthour.setMonth(0);
@andreuinyu
andreuinyu / reverser.py
Created January 31, 2017 18:00
t.me/reverser_bot
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
def start(bot, update):
update.message.reply_text('This bot reverses every message you send')
def help(bot, update):
update.message.reply_text('Need help? Fuck yourself')