Skip to content

Instantly share code, notes, and snippets.

@betaveros
betaveros / obfuscatedprimes.hs
Last active December 17, 2015 17:49
An "efficient" prime generator with the Sieve of Eratosthenes in Haskell, as close to point-free (= unreadable) as I could make it.
import Control.Applicative (liftA2, liftA3)
import qualified Data.Map as M (empty, lookup, insertWith, delete)
import Data.Function (fix)
import Control.Monad (join)
primes = fix (flip (flip liftA2 head) tail . (liftA2 (liftA3 liftA2 (flip flip
. M.lookup)) (liftA2 ($) ((.) . (.) (liftA3 maybe) . (.) . (:)) . ((. flip
(.) . liftA2 (M.insertWith (++)) (join (*)) (replicate 1)) . flip (.)))
(((. flip (.) . liftA2 (.) (foldl . ((. flip flip) . flip flip (replicate
1) . flip liftA2 . (.) (M.insertWith (++)) . (+))) M.delete) . (flip (.))
. (.) (.) ) ))) [2..] M.empty
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CurrencyExchange { // I'm not an actionListener!
String[] differentCurrency = {"US Dollars","Japanese YEN","Chinese YUAN", "Korean WON"};
JFrame frame;
JPanel contentPane;
JLabel label, result;
@betaveros
betaveros / rotated.hs
Created June 1, 2013 03:36
find equations like (a + b + c = d) which are still true after 180-degree rotation
import Control.Applicative
import Data.Maybe
-- Calculator digit rotation
cRotateDigit 0 = Just 0
cRotateDigit 1 = Just 1
cRotateDigit 2 = Just 2
cRotateDigit 5 = Just 5
cRotateDigit 6 = Just 9
cRotateDigit 8 = Just 8
cRotateDigit 9 = Just 6
hello
hello
hello
hello
hello
hello

Keybase proof

I hereby claim:

  • I am betaveros on github.
  • I am betaveros (https://keybase.io/betaveros) on keybase.
  • I have a public key whose fingerprint is 9B4D 8695 1809 7390 1AC8 107E 58B4 4740 9AB4 540F

To claim this, I am signing this object:

(lambda main: main(0, 'https://opensource.org/licenses/MIT', ''.join(filter(str.isalpha, __import__('random').choice(open('/usr/share/dict/words').readlines()).upper())), set(), '|======\n| |\n| {3} {0} {5}\n| {2}{1}{4}\n| {6} {7}\n| {8} {9}\n|', list('OT-\\-//\\||'), 10, main))(lambda _, license, chosen_word, guesses, scaffold, man, guesses_left, main_: main_(map(guesses.add, filter(str.isalpha, raw_input('%s(%s guesses left)\n%s\n%s:' % (','.join(sorted(guesses)), guesses_left, scaffold.format(*(man[:10-guesses_left] + [' '] * guesses_left)), ' '.join(letter if letter in guesses else '_' for letter in chosen_word))).upper())), license, chosen_word, guesses, scaffold, man, max((10 - len(guesses - set(chosen_word))), 0), main_) if not all(letter in guesses for letter in chosen_word) and guesses_left else __import__('sys').stdout.write('You ' + ['lose!\n' + scaffold.format(*man), 'win!'][bool(guesses_left)] + '\nWord was ' + chosen_word + '\n'))
@betaveros
betaveros / .vimrc
Created May 21, 2016 00:58
the .vimrc MIT used at ICPC WF 2016; half of it was probably unnecessary, but it's probably not worth it to figure out which half
set nocp ai bs=2 cul hls ic is lbr list ls=2 mouse=a nu ru sc scs smd so=3 sw=4 ts=4
set lcs=tab:»\ ,trail:␣
filetype plugin indent on
syntax on
map <Space> i<Space><Esc>
map gA m'ggVG"+y''
@betaveros
betaveros / c.hs
Last active November 25, 2016 03:19
combinatorics!
import Control.Monad
import Data.List
-- Haskell comments look like this, lines that start with two hyphens.
{- You can also write range comments like this. -}
-- We did not write the type annotations (lines with ::) during class, and in
-- fact if you delete them Haskell will supply (more general) type signatures.
-- You can see what type Haskell thinks the things we've defined are by running
from __future__ import division, print_function
def partial_differences(xs):
return [x2 - x1 for (x1, x2) in zip(xs, xs[1:])]
def index_of_max(xs):
return max(enumerate(xs), key=lambda pair: pair[1])[0]
# given a list of floats, compute a tempo and a timestamp
def tempo(xs, max_beats):
@betaveros
betaveros / fn_minus.xml
Created January 9, 2017 15:45
Karabiner XML for mapping fn+- (fn-hyphen) to a legitimate minus sign, cobbled together from sone online sources I forget
<?xml version="1.0"?>
<root>
<item>
<name>Change fn+- to (minus sign)</name>
<appendix>You need to enable Unicode Hex Input and U.S. input sources.</appendix>
<identifier>private.fn_minus</identifier>
<autogen>__KeyToKey__
KeyCode::MINUS, ModifierFlag::FN,
<!-- change input source to Unicode -->