Skip to content

Instantly share code, notes, and snippets.

sieve :: [Int]
sieve = 2 : ([3,5..] >>= test sieve)
where
test p c = test' p c $ floor . sqrt . fromIntegral $ c
test' (p:ps) c lim --primes and candiate
| p > lim = [c]
| rem c p == 0 = []
| otherwise = test' ps c lim

Keybase proof

I hereby claim:

  • I am electrocutie on github.
  • I am electrocutie (https://keybase.io/electrocutie) on keybase.
  • I have a public key ASDKaTj1zKxT1O4hYIKcLIMtpD_dl4AYTbwsNPyE6MgmNgo

To claim this, I am signing this object:

@electroCutie
electroCutie / ListConsumer.hs
Last active September 7, 2018 13:01
A Monad for taking values from a list in a safe way
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.ListConsumer (
ListConsumer, takeN, peekN, dropN, takeAll, takeAny, runL, runFoldableL
) where
import Control.Applicative
import Control.Arrow
import Control.Monad
#include <stdint.h>
#include <stdio.h>
#include <printf.h>
#define _stride(_type) ({ \
_type* _t = (_type*) 0; \
(uint64_t) (_t+1); \
})
struct st {
@electroCutie
electroCutie / CompileArguments.hs
Created June 5, 2019 13:44
Getting the compile line for a spec
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PatternSynonyms #-}
module Main where
import Text.Printf
import Calibration.CalUnits
package cloud.literallya.util;
import java.util.Map;
import java.util.function.IntSupplier;
import java.util.function.LongSupplier;
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@electroCutie
electroCutie / SevenSegmentSolver.hs
Created October 1, 2019 07:11
Find magic numbers for a factorio decimal -> 7 segment display decoder
module Main where
import Control.Monad.Random.Lazy
import Data.List (find)
import Data.Maybe
import Debug.Trace
import Text.Printf
primes :: [Integer]
module plfa.part1.Induction where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_)
-- left identity: C op n ≡ n
//include "/sprintf.js";
//snippet "Object.freeze";
//snippet "Array.forEach";
(function(){
"use strict";
function getOrCall(o, attr){
package com.macvalves.util.concurrent;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import java.util.Collection;
import java.util.List;
import java.util.Spliterators;
import java.util.concurrent.CyclicBarrier;