Skip to content

Instantly share code, notes, and snippets.

@jakab922
jakab922 / knight_pos.hs
Last active February 5, 2016 14:40
The in_n function is important which calculates the reachable squares reachable in n steps on the chessboard(quite inefficient though)
import Data.List (nub)
class Monad m => MonadPlus m where
mzero :: m a
mplus :: m a -> m a -> m a
instance MonadPlus [] where
mzero = []
mplus = (++)
""" The problem was solved on 1 core in 543m35.913s.
The best score was: 3354674163673461017691780032809373762464467910656
The best dice was: up: 6, down: 3, top: 1, bottom: 6, left: 8, right: 7
The dice started with 1 on top and 3 on up
The route associated with the score and the dice is:
[(1, 1), (2, 1), (2, 2), (3, 2), (3, 3), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (1, 10), (1, 11), ( 2, 11), (3, 11), (4, 11), (5, 11), (6, 11), (7, 11), (8, 11), (9, 11), (9, 10), (9, 9), (9, 8), (9, 7), (9, 6), (9, 5), (8, 5), (8, 4), (7, 4), (6, 4), (6, 5), (6, 6), (6, 7), (7, 7), (7, 8), (7, 9), (6, 9), (5, 9), (4, 9), (4, 8), (4, 7), (4, 6), (3, 6), (3, 5), (4, 5), (5, 5), (5, 4), (4, 4), (4, 3), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (9, 3), (10, 3), (10, 2), (10, 1), (11, 1), (11, 2), (11, 3), (11, 4), (10, 4), (10, 5), (11, 5), (11, 6), (11, 7), (11, 8), (11, 9), (11, 10), (11, 11), (11, 12), (12, 12)]
"""
from itertools import product
from random import shuffle
from collections import defaultdict
from copy import deepcopy
daphne = defaultdict(set)
rdaphne = {}
maxx = defaultdict(set)
rmaxx = {}
mindy = defaultdict(set)
rmindy = {}
from collections import defaultdict
from copy import deepcopy
from functools import partial
def pre_solve(key_funcs, N):
kfl = len(key_funcs)
players = [defaultdict(set) for _ in xrange(kfl)]
rplayers = [{} for _ in xrange(kfl)]
import Control.Monad.State
import System.Random
import Data.List
import System.Environment
rollDie :: State StdGen Int
rollDie = state $ randomR (1, 6) -- randomR (1, 6) :: StdGen -> (Int, StdGen)
rollNDice :: Int -> State StdGen [Int]
rollNDice x | x < 1 = return []
-- A spinoff of the Vcard.hs example from http://book.realworldhaskell.org/read/programming-with-monads.html
import Control.Monad
data Context = Home | Mobile | Business
deriving (Eq, Show)
type Phone = String
type Phones = [Phone]
albulena = [(Home, "+35-1234")]
{-# LANGUAGE ViewPatterns #-}
import qualified Data.Sequence as S
import System.Environment
import Control.Monad
data List a = Nil | Cons a (List a)
mylast :: S.Seq a -> Maybe a
mylast (S.viewr -> xs S.:> x) = Just x
import qualified Data.Map as M
import System.Random
import System.Environment
import Control.Monad
insert :: Int -> M.Map Int Int -> [Int] -> M.Map Int Int
insert n m randoms
| n < 1 = m
| otherwise = insert (n - 1) new_map new_randoms
from random import randint as ri
from sys import argv
d = {}
n = int(argv[1])
for i in xrange(n):
d[i] = ri(1, 100)
Resolving dependencies...
Configuring aeson-0.11.1.3...
Building aeson-0.11.1.3...
Failed to install aeson-0.11.1.3
Build log ( /home/dani/.cabal/logs/aeson-0.11.1.3.log ):
Configuring aeson-0.11.1.3...
Building aeson-0.11.1.3...
Preprocessing library aeson-0.11.1.3...
[ 1 of 16] Compiling Data.Aeson.Functions ( Data/Aeson/Functions.hs, dist/build/Data/Aeson/Functions.o )
[ 2 of 16] Compiling Data.Aeson.Internal.Time ( Data/Aeson/Internal/Time.hs, dist/build/Data/Aeson/Internal/Time.o )