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 hashlib import sha256 | |
| digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | |
| def decode_base58(bc, length): | |
| n = 0 | |
| for char in bc: | |
| n = n * 58 + digits58.index(char) | |
| return n.to_bytes(length, 'big') | |
| def check_bc(bc): |
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
| struct Matrix { | |
| dat: [[f32; 3]; 3] | |
| } | |
| impl Matrix { | |
| pub fn mult_m(a: Matrix, b: Matrix) -> Matrix | |
| { | |
| let mut out = Matrix { | |
| dat: [[0., 0., 0.], | |
| [0., 0., 0.], |
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: |
NewerOlder