Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / U32.hs
Last active December 5, 2017 02:51
BF DSL code
{-# 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 December 2, 2017 02:44
ASCII85 encoder in BrainF*ck
>>>>>>>>>>>,<<,<<,<<,<<,<[-]+>>[-]+<[<<<]>[>>[-]+<[<<<<<]>[>
>[-]+<[<<<<<<<]>[>>[-]+<[<<<<<<<<<]>[>>[-]+<[<<<<<<<<<<<]>[<
<<<<<<<<<[-]<]]]]]>[>>>>>>>>>>>[-]>>[-]>>[-]>>[-]>>[-]++++++
+++++++++++++++++++++++++++[<<<<<<<<<<<<<<<<<<->>->>->>->>->
>>>>>>>>>-]<<<<<<<<<<<<<<<<<<[>>>>>>>>>>+<<<<<<<<<<-]>>[>>>>
>>>>>>>>>>>>[-]+++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++[<<<<<<<<+>[-]+<[<<<
<<<<<<<<<<]>[>+>[-]+<[<<<<<<<<<<<<<<<]>[>+>[-]+<[<<<<<<<<<<<
<<<<<<]>[>+>[-]+<[<<<<<<<<<<<<<<<<<<<]>[<<<<<<<<<<<<<<<<<<<]
]]]>>>>>>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<<-]>>[>>>>>>>>>>>>>>
@erantapaa
erantapaa / rubiks-cube.hs
Last active July 9, 2022 19:32
Rubik's Cube Daily Programmer Challenges
{-# 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 December 3, 2019 02:29
Daily Programmer 2017-09-22 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 September 11, 2017 06:09
minichess board positions
/*
* "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 August 18, 2017 03:25
Daily Programmer 326
// 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 August 6, 2017 01:58
Bootstrapping a Haskell environment using Stack
  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 outside a project directory and get packages installed.
@erantapaa
erantapaa / arrow.hs
Created August 4, 2017 16:36
Arrow Maze solutions in Haskell
--
-- 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 August 1, 2017 01:56
Hard Poker Odds problem solution
{-# 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 July 31, 2017 19:57
hcalendar - print a calendar for a year
#!/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