Skip to content

Instantly share code, notes, and snippets.

View recursivecurry's full-sized avatar

Jongsoo Lee recursivecurry

View GitHub Profile
@recursivecurry
recursivecurry / ifp__ex_3_3_12.hs
Created February 11, 2014 04:02
introduction to functional programming - ex 3.3.12
module Score where
import Data.List
cow :: [Char] -> [Char] -> Int
cow sol input = length [1 | (x, y) <- zip sol input, x==y]
bull :: [Char] -> [Char] -> Int
bull sol input = length sol - length (sol \\ input)
@recursivecurry
recursivecurry / gist:10443028
Created April 11, 2014 05:58
simple prime number array generator
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.
"""
-- 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]]
@recursivecurry
recursivecurry / json.hs
Created January 3, 2015 15:56
json parser (partial implemented)
module Parsing where
import Data.Char
import Control.Monad
infixr 5 +++
newtype Parser a = P (String -> [(a,String)])
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.
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
@recursivecurry
recursivecurry / b.go
Created April 28, 2015 15:05
google codejam round1a b - go and rust
package main
import (
"fmt"
"math"
)
func main() {
var T int
fmt.Scanf("%d", &T)
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
@recursivecurry
recursivecurry / think.functionally.ch1.ipynb
Created May 11, 2015 11:29
Thinking functionally with haskell Ch. 1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[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)