Skip to content

Instantly share code, notes, and snippets.

@Gorcenski
Gorcenski / LinkSharer.fs
Last active December 27, 2022 17:41
Code for my Azure Function to syndicate links across multiple services
namespace LinkSharer
open System
open System.Collections.Generic
open System.IO
open Microsoft.AspNetCore.Mvc
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Extensions.Http
open Microsoft.AspNetCore.Http
open Newtonsoft.Json
@Gorcenski
Gorcenski / day01.fsx
Last active December 5, 2022 15:08
Advent of Code 2022 Day 1
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
@Gorcenski
Gorcenski / shortbuzz.py
Created February 12, 2020 23:54
Four line extensible fizzbuzz because I'm a bad person
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)])
@Gorcenski
Gorcenski / fizzbuzz_keras.py
Last active June 12, 2019 14:05
FizzBuzz with keras, because why not
# 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
@Gorcenski
Gorcenski / fizzbuzz.py
Last active May 23, 2022 23:55
The most obnoxious solution to FizzBuzz I can imagine.
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
@Gorcenski
Gorcenski / Problem34.cs
Last active December 20, 2015 15:44
PE #34 intelligent brute-force
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.
@Gorcenski
Gorcenski / Problem13.cs
Last active December 11, 2015 03:56
PE13, homebrew off-the-cuff BigInt implementation with lookahead
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
namespace ProjectEuler
{
class Problem13
{