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
open System.IO | |
let readLines (filePath:string) = | |
use sr = new StreamReader (filePath) | |
sr.ReadToEnd().Split([|"\n\n"|],System.StringSplitOptions.TrimEntries) | |
|> Seq.map (fun x -> x.Split [|'\n'|]) | |
|> Seq.map (Seq.map (int)) | |
|> Seq.map Seq.sum | |
|> Seq.sortDescending |
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
import numpy as np | |
from functools import reduce | |
def fizzbuzz(i, **kwargs): | |
polyvec = lambda order : np.concatenate(([1], np.zeros(order - 1), [-1])) | |
polybuilder = lambda f: lambda x : sum(f * np.array([np.exp(1j * x * k * 2 * np.pi / np.lcm.reduce([v for k, v in kwargs.items()])) for k in range(len(f) - 1, -1, -1)])) | |
p = polybuilder(reduce(lambda q, r : np.convolve(q, r), [polyvec(np.lcm.reduce([v for k, v in kwargs.items()]) // v) for v in [v for k, v in kwargs.items()]], [1])) | |
return reduce(lambda x, y : x + y, [k * bool(np.abs(polybuilder(polyvec(np.lcm.reduce([v for k, v in kwargs.items()]) // v))(i)) < 1e-7) for k, v in kwargs.items()], str(i) * bool(np.abs(p(i)) > 1e-7)) | |
print([fizzbuzz(i, fizz=3, buzz=5, baz=7, bar=11) for i in range(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
# These are the things we will use. Implicitly, we'll assume tensorflow is the keras backend | |
import keras | |
import keras.backend as K | |
import numpy as np | |
from keras.models import Sequential | |
from keras.layers import Dense | |
# This is necessary only because of some version incompatibility where the default | |
# argument to argmax is broken with some combination of Python 3.7, keras 2.1.3 (or 2.1.6), | |
# and tensorflow 1.12. So we'll just reimplement it until the demons of dependency hell |
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
import numpy as np | |
from functools import reduce | |
class Buzzer: | |
def __init__(self, **kwargs): | |
values = [v for k, v in kwargs.items()] | |
self.kwargs = kwargs | |
self.lcm = np.lcm.reduce(values) | |
self.eps = 1e-7 |
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
class Problem34 | |
{ | |
static int[] factorial = new int[10]; | |
public static void Solve() | |
{ | |
factorial[0] = 1; | |
int sum = 0; | |
// Use Halley's method to compute the solution 9!*x = 10^x - 1 | |
// Start where the gradient is shallow, to avoid overshooting into the solution near 0. | |
// This gives us about a 10% speed improvement over the integer multiple. |
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Numerics; | |
namespace ProjectEuler | |
{ | |
class Problem13 | |
{ |