Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / U32.hs
Last active Dec 5, 2017
BF DSL code
View U32.hs
{-# LANGUAGE FlexibleContexts #-}
module U32 where
import BF
import Control.Monad
data U32 = U32 (Pair,Pair,Pair,Pair)
deriving (Read, Show)
@erantapaa
erantapaa / ascii85-decoder.bf
Last active Dec 2, 2017
ASCII85 encoder in BrainF*ck
View ascii85-decoder.bf
>>>>>>>>>>>,<<,<<,<<,<<,<[-]+>>[-]+<[<<<]>[>>[-]+<[<<<<<]>[>
>[-]+<[<<<<<<<]>[>>[-]+<[<<<<<<<<<]>[>>[-]+<[<<<<<<<<<<<]>[<
<<<<<<<<<[-]<]]]]]>[>>>>>>>>>>>[-]>>[-]>>[-]>>[-]>>[-]++++++
+++++++++++++++++++++++++++[<<<<<<<<<<<<<<<<<<->>->>->>->>->
>>>>>>>>>-]<<<<<<<<<<<<<<<<<<[>>>>>>>>>>+<<<<<<<<<<-]>>[>>>>
>>>>>>>>>>>>[-]+++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++[<<<<<<<<+>[-]+<[<<<
<<<<<<<<<<]>[>+>[-]+<[<<<<<<<<<<<<<<<]>[>+>[-]+<[<<<<<<<<<<<
<<<<<<]>[>+>[-]+<[<<<<<<<<<<<<<<<<<<<]>[<<<<<<<<<<<<<<<<<<<]
]]]>>>>>>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<<-]>>[>>>>>>>>>>>>>>
@erantapaa
erantapaa / rubiks-cube.hs
Last active Oct 18, 2017
Rubik's Cube Daily Programmer Challenges
View rubiks-cube.hs
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE ViewPatterns #-}
import Control.Monad
import Data.Array.IO
import Data.List.Split (chunksOf)
type Point = (Int,Int,Int)
-- basic rotations
@erantapaa
erantapaa / bonus 1 solution
Last active Dec 3, 2019
Daily Programmer 2017-09-22 Solution
View bonus 1 solution
iniital board:
1 3 2 5 4 2 2 3
1 12345678 .....6.. 12345678 12345678 ....5... 12345678 1....... 12345678 3
4 12345678 .2...... 1....... 12345678 12345678 12345678 12345678 12345678 2
3 .2...... 12345678 12345678 12345678 .....6.. 12345678 ..3..... 12345678 5
3 12345678 12345678 12345678 12345678 12345678 .......8 12345678 12345678 2
2 12345678 12345678 .....6.. 12345678 12345678 ..3..... ......7. 12345678 3
2 12345678 12345678 ....5... 12345678 12345678 12345678 12345678 12345678 1
4 12345678 12345678 12345678 12345678 12345678 12345678 12345678 ..3..... 3
3 12345678 12345678 12345678 12345678 ..3..... 12345678 12345678 12345678 3
@erantapaa
erantapaa / 3x3_counts.c
Last active Sep 11, 2017
minichess board positions
View 3x3_counts.c
/*
* "3x3c.c" - source file of the 3x3 chess solver, version 1.0.0
*
* Copyright (c) 2004-2011 Kirill Kryukov
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
@erantapaa
erantapaa / jsolve.js
Created Aug 18, 2017
Daily Programmer 326
View jsolve.js
// Code to solve Daily Programmer problem 326 - Multifaceted Alphabet Blocks
var fs = require("fs")
var contents = fs.readFileSync('real_words.txt').toString();
var all_words = contents.split(/\s+/)
nwords = all_words.length
console.log("nwords:", nwords)
// return a histogram of an array of words
@erantapaa
erantapaa / BOOTSTRAPPING HASKELL.md
Last active Aug 6, 2017
Bootstrapping a Haskell environment using Stack
View BOOTSTRAPPING HASKELL.md
  1. Download stack
  2. Decide on an resolver, e.g. lts-8.24
  3. Set the resolver in ~/.stack/global-project/stack.yaml
  4. In a work directory:
  • Run: stack get cabal
  • Add a stack.yaml file to the pull sources
  • Run: stack install. The cabal executable should be installed in ~/.local/bin.
  1. Grab the cabal.config for the resolver: curl https://www.stackage.org/lts-8.24/cabal.config
  2. Use the build-everything-cabal script below to generate a everything.cabal file with all the packages listed in the build-depends: field. Place the cabal file in ~/.stack/global-project. Now you can use stack install <package> outside a project directory and get packages installed.
@erantapaa
erantapaa / arrow.hs
Created Aug 4, 2017
Arrow Maze solutions in Haskell
View arrow.hs
--
-- Solution to "Arrow Maze" Daily Programmer Problem:
-- https://www.reddit.com/r/dailyprogrammer/comments/6rb98p/20170803_challenge_325_intermediate_arrow_maze/
--
-- Use the fgl library constructing a graph whose nodes are (cell, arrow).
-- An edge represents a move from a cell to an adjacent cell.
--
import Data.Graph.Inductive
import Data.Graph.Inductive.Query
import Data.Graph.Inductive.PatriciaTree
@erantapaa
erantapaa / holdem.hs
Created Aug 1, 2017
Hard Poker Odds problem solution
View holdem.hs
{-# LANGUAGE MultiWayIf #-}
-- Solution to: https://www.reddit.com/r/dailyprogrammer/comments/6eublu/20170602_challenge_317_hard_poker_odds/
import Data.Function
import Data.List
import Data.Ord
import Data.Char
import Data.Maybe
import Control.Monad
@erantapaa
erantapaa / hcalendar.hs
Created Jul 31, 2017
hcalendar - print a calendar for a year
View hcalendar.hs
#!/usr/bin/env stack
-- stack --resolver lts-8.23 runghc
-- may need to install --package time --package split
-- A Haskell solution to the calendar printing problem.
-- See CppCon 2015: Eric Niebler "Ranges for the Standard Library"
-- https://www.youtube.com/watch?v=mFUXNMfaciE
module Main where