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
from functools import reduce | |
def get_diff_of_maxs(xs): | |
""" | |
>>> get_diff_of_maxs([]) | |
Traceback (most recent call last): | |
... | |
IndexError: list index out of range | |
>>> get_diff_of_maxs([1]) | |
Traceback (most recent call last): |
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
[1 of 1] Compiling Main ( test.hs, test.o ) | |
test.hs:8:36: | |
No instance for (Num (a0 -> Double)) arising from a use of `y' | |
Possible fix: add an instance declaration for (Num (a0 -> Double)) | |
In the first argument of `(*)', namely `(y x)' | |
In the expression: (y x) * 0.001 | |
In the first argument of `sum', namely | |
`[(y x) * 0.001 | | |
x <- [(fromIntegral l) + 0.0005, (fromIntegral l) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Ant where | |
import Data.List | |
group' :: [Int] -> [[Int]] | |
group' [] = [] | |
group' xs = foldr (\x acc -> if (head . head) acc == x then (x : (head acc)) : tail acc else [x]:acc) [[last xs]] (init xs) | |
concatMap' :: (a -> [b]) -> [a] -> [b] | |
concatMap' f xs = (concat . map f) xs |
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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func main() { | |
var T int | |
fmt.Scanf("%d", &T) |
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 Starforce where | |
import Data.Bits | |
import Data.List | |
answers :: Int -> [Int] | |
answers = \bitnum -> concat $ map (bit_permutation bitnum) $ reverse [1..bitnum] | |
bit_permutation :: Int -> Int -> [Int] | |
bit_permutation bitnum onebit |
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
GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer-gmp ... linking ... done. | |
Loading package base ... linking ... done. | |
Prelude> :l json.hs | |
[1 of 1] Compiling Parsing ( json.hs, interpreted ) | |
json.hs:11:10: Warning: | |
‘Parser’ is an instance of Monad but not Applicative - this will become an error in GHC 7.10, under the Applicative-Monad Proposal. |
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 Parsing where | |
import Data.Char | |
import Control.Monad | |
infixr 5 +++ | |
newtype Parser a = P (String -> [(a,String)]) |
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
-- subset generator | |
-- ./Test | |
-- 3 | |
-- [[1,2,3],[2,3],[1,3],[3],[1,2],[2],[1],[]] | |
-- ./Test | |
-- 4 | |
-- [[1,2,3,4],[2,3,4],[1,3,4],[3,4],[1,2,4],[2,4],[1,4],[4],[1,2,3],[2,3],[1,3],[3],[1,2],[2],[1],[]] | |
module Main where | |
subMain :: Int -> [Int] -> [[Int]] |
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
import argparse | |
import sys | |
# Sieve of Eratosthenes | |
# Code by David Eppstein, UC Irvine, 28 Feb 2002 | |
# http://code.activestate.com/recipes/117119/ | |
def gen_primes(): | |
""" Generate an infinite sequence of prime numbers. | |
""" |