This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Numerics; | |
namespace Sandbox | |
{ | |
class MO338802 | |
{ | |
public static void Main() |
This file contains 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
func eratosthenesSieve(to n: Int) -> [Int] { | |
guard 2 <= n else { return [] } | |
var composites = Array(repeating: false, count: n + 1) | |
var primes: [Int] = [] | |
let d = Double(n) | |
let upperBound = Int((d / _log(d)) * (1.0 + 1.2762/_log(d))) | |
primes.reserveCapacity(upperBound) | |
let squareRootN = Int(d.squareRoot()) |
This file contains 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
#!/usr/bin/python3 | |
import math | |
def phi(n): | |
# Naïve prime factorisation | |
ps = set() | |
m = n | |
while m % 2 == 0: |
This file contains 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 sage.rings.polynomial.real_roots import * | |
x = polygen(ZZ) | |
def conv_p(p, n): | |
if n == 0: | |
return x | |
else: | |
return p(conv_p(p, n-1)) | |
for n in range(1, 21): print add(map(lambda (a,b): b, real_roots(conv_p(x^3-2*x-1, n)))) |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using BigInteger = System.Numerics.BigInteger; | |
namespace Sandbox | |
{ | |
// https://math.stackexchange.com/questions/2642142/complex-number-abc-conjecture | |
// https://stackoverflow.com/questions/2269810/whats-a-nice-method-to-factor-gaussian-integers |
This file contains 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
#!/usr/bin/python3 | |
def flatten(index_map): | |
flat = [0] * len(index_map) | |
for key in index_map.keys(): | |
flat[index_map[key]] = key | |
return flat | |
def emit_solution(x, partial_solution): |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Numerics; | |
using System.Text; | |
namespace Sandbox | |
{ | |
public class Rational | |
{ | |
public Rational(BigInteger num, BigInteger denom) |
This file contains 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
#!/usr/bin/python3 | |
from functools import lru_cache | |
class Partition: | |
def __init__(self, maxPart, tail=None): | |
self.part = maxPart | |
self.tail = tail | |
if tail is None: |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Sandbox { | |
// NB This is not really "production-quality" code | |
class Program { | |
static void Main(string[] args) { | |
for (int m = 2; m < 7; m++) { | |
for (int n = 2; n <= m; n++) { |
This file contains 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
import java.math.BigInteger; | |
import java.util.*; | |
public class QuoridorCounter { | |
public static void main(String[] args) { | |
List<String> rows = new ArrayList<String>(); | |
char[] chs = new char[8]; | |
for (int i = 0; i < 6561 /* 3^8 */; i++) { | |
int r = i; | |
for (int j = 0; j < 8; j++) { |