This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Parallel | |
import Control.Parallel.Strategies | |
import Data.List | |
import qualified Data.IntSet as Set | |
divisors :: (Integral t) => t -> [t] | |
divisors n = nub $ divs ++ inv_divs | |
where divs = [d | d <- [1..((floor . sqrt . fromIntegral) n)], n `mod` d == 0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import System | |
import Data.List | |
import Primes | |
primes :: [Integer] | |
primes = filter (prime) [2..] | |
concatenations :: Show a => [a] -> [Integer] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.Map as Map | |
p :: (Ord a, Num t, Num a) => a -> a -> Map (a, a) t -> Map (a, a) t | |
p k n m = | |
if member (k, n) m then | |
m | |
else if k > n then | |
insert (k, n) 0 m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
sequence.hs | |
Generates the funky 1, 11, 21, 1211, ... sequence. | |
-} | |
import Data.List | |
next_in_sequence s = foldl1 (++) $ map (\x -> [length x, head x]) $ group s | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The smallest number expressible as the sum of a prime square, | |
-- prime cube, and prime fourth power is 28. In fact, there are | |
-- exactly four numbers below fifty that can be expressed in | |
-- such a way: | |
-- | |
-- 28 = 2^(2) + 2^(3) + 2^(4) 33 = 3^(2) + 2^(3) + 2^(4) 49 = | |
-- 5^(2) + 2^(3) + 2^(4) 47 = 2^(2) + 3^(3) + 2^(4) | |
-- | |
-- How many numbers below fifty million can be expressed as the | |
-- sum of a prime square, prime cube, and prime fourth power? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parFilter :: (a -> Bool) -> [a] -> [a] | |
parFilter _ [] = [] | |
parFilter f (x:xs) = | |
let px = f x | |
pxs = parFilter f xs | |
in par px $ par pxs $ case px of True -> x : pxs | |
False -> pxs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The hyperexponentiation or tetration of a number a by a positive integer | |
-- b, denoted by a↑↑b or ^(b)a, is recursively defined by: | |
-- | |
-- a↑↑1 = a, a↑↑(k+1) = a^((a↑↑k)). | |
-- | |
-- Thus we have e.g. 3↑↑2 = 3^(3) = 27, hence 3↑↑3 = 3^(27) = 7625597484987 | |
-- and 3↑↑4 is roughly 10^(3.6383346400240996*10^12). | |
-- | |
-- Find the last 8 digits of 1777↑↑1855. | |
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modulus = 14 ^ 8 | |
(.^^.) :: Integer -> Integer -> Integer | |
a .^^. 1 = a | |
a .^^. (k + 1) = powMod modulus a (a .^^. k) | |
main :: IO () | |
main = do mapM_ print [2731 .^^. n | n <- [1..15]] | |
-- Has the following output: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'pp' | |
@core = {} | |
@hello_world = <<__END_HELLO_WORLD__ | |
> v | |
v ,,,,,"Hello"< | |
>48*, v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
# | |
# alphabetagaga.rb | |
# | |
# Takes a text file as input, with terms on lines sorted by some mysterious | |
# alphabet. Returns a string representing the ordering of the alphabet by | |
# which the file was sorted. | |
# | |
# max thom stahl <max@villainousindustri.es> | |
# github.com/mstahl |
OlderNewer