Skip to content

Instantly share code, notes, and snippets.

@nuit
nuit / phi.py
Last active August 29, 2015 14:03
Crivo de Eratóstenes, Função Totiente de Euler
from __future__ import division
def phi(i):
l=[]
n=1
multiples = set()
for p in range(2, i+1):
if p not in multiples:
multiples.update(range(p*p, i+1, p))
if i%p==0:
j=(p-1)/p
@nuit
nuit / xmdc.py
Created July 9, 2014 21:58
Algoritmo Estendido de Euclides
def xmdc(a,b):
if b==0:
return [1,0,a]
else:
x,y,d=xmdc(b, a%b)
return [y,x-(a//b)*y,d]
@nuit
nuit / mdc.py
Created July 9, 2014 18:56
Algoritmo de Euclides
def mdc(a,b):
while(b!=0):
c=a%b
a=b
b=c
print a
mdc(2024,748)
@nuit
nuit / scytale.py
Last active August 29, 2015 13:56
Bastão de Licurgo
d = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
input = raw_input('>> ')
texto = input.replace(' ','').upper()
if len(texto)>28:
sys.exit()
if len(texto)<2:
sys.exit()
else:
t = len(texto)
@nuit
nuit / 010.py
Last active August 29, 2015 13:55
Project Euler Solution
import time
import math
start = time.time()
def primo(n):
if n%2==0: return False
return not any(n%i==0 for i in range(3, int(math.sqrt(n))+1,2))
sum = 0
import urllib
import requests
from bs4 import BeautifulSoup
import re
import urllib2
import MySQLdb as mdb
import simplejson as json
import getpass
import time
@nuit
nuit / whois.py
Created October 20, 2013 04:36
whois.py
from bs4 import BeautifulSoup
import requests
import re
import socket
url=raw_input(">> ")
site = 'http://www.iana.org/whois?q='+url
r = requests.get(site)
soup = BeautifulSoup(r.text)