This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fractions import Fraction as Fr | |
| def bernoulli(n): | |
| A = [0] * (n+1) | |
| for m in range(n+1): | |
| A[m] = Fr(1, m+1) | |
| for j in range(m, 0, -1): | |
| A[j-1] = j*(A[j-1] - A[j]) | |
| return A[0] # (which is Bn) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| número euler calculado limite de (1+1/n)^n com n se aproximando ao | |
| infinito calculando os 200 primeiros dígitos, através da | |
| biblioteca decimal | |
| ''' | |
| from decimal import Decimal, getcontext | |
| def euler(precisao): | |
| prec_n = precisao |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| listnumbers = range(1,500) | |
| for i in listnumbers: | |
| sum = 0 | |
| value = 1 | |
| while value <= i-1: | |
| sum+=value**(i-1) | |
| value+=1 | |
| if ((sum%i)+1)%i == 0: | |
| print("%d é primo pela conjectura de Agoh-Giuga!"%(i)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def factors(n): | |
| return [i for i in range(1, n//2 + 1) if not n%i] + [n] | |
| print(factors(45)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def eratosthenes2(n): | |
| multiples = set() | |
| for i in range(2, n+1): | |
| if i not in multiples: | |
| yield i | |
| multiples.update(range(i*i, n+1, i)) | |
| print(list(eratosthenes2(100))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::fmt; | |
| const SIZE: usize = 8; | |
| const MOVES: [(i32, i32); 8] = [(2,1), (1,2), (-1,2), (-2,1), (-2,-1), (-1,-2), (1,-2), (2,-1)]; | |
| #[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord)] | |
| struct Point { | |
| x: i32, | |
| y: i32 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const N: usize = 8; | |
| fn try(mut board: &mut [[bool; N]; N], row: usize, mut count: &mut i64) { | |
| if row == N { | |
| *count += 1; | |
| for r in board.iter() { | |
| println!("{}", r.iter().map(|&x| if x {"x"} else {"."}.to_string()).collect::<Vec<String>>().join(" ")) | |
| } | |
| println!(""); | |
| return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def isqrt(n): | |
| if n < 0: | |
| raise ValueError | |
| elif n < 2: | |
| return n | |
| else: | |
| a = 1 << ((1 + n.bit_length()) >> 1) | |
| while True: | |
| b = (a + n // a) >> 1 | |
| if b >= a: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Bcrypt hashing class | |
| * | |
| * @author Thiago Belem <[email protected]> | |
| * @link https://gist.github.com/3438461 | |
| */ | |
| class Bcrypt { |