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
{-# LANGUAGE UnicodeSyntax,FlexibleInstances #-} | |
import Control.Monad (foldM) | |
-- |Extended Euclidean algorithm | |
-- Given A,B, finds integers X,Y that satisfy Bézout's identity: | |
-- A*X + B*Y = gcd(A,B) | |
egcd a b = aux a b 1 0 0 1 | |
where aux r 0 x y _ _ = (r,x,y) | |
aux r r' x y x' y' = aux r' r'' x' y' x'' y'' | |
where r'' = r `rem` r' |
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 (generators). | |
-define (YIELD (F), fun() -> F end). | |
-export ([fib/0]). | |
fib() -> | |
{0, ?YIELD(fib(1,1))}. | |
fib(A,B) -> | |
{A, ?YIELD(fib(B, A+B))}. |
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
palindromes base = concat $ zipWith (\bcofs -> (map sum . sequence . zipWith (\b -> map (*b)) bcofs)) gen coefs | |
where | |
aa x = x : aa (x*base) -- [1, 10, 100, 1000, ..] | |
a = repeat $ aa 1 -- [ [1, ..], [1, 10, ..], [1, 10, 100, ..], ..] | |
b = scanl (\(a:acc) x -> base*a:a:acc) [1] [1..] -- [ [1], [10,1], [100, 10, 1], ..] | |
c = [-1] : [0] : map (\xs -> 0:(map (*base) xs)) c -- [ [-1], [0], [0, -10], [0, 0], [0, 0, -100], ..] | |
gen = zipWith3 (zipWith3 (\x y z -> x+y+z)) a b c -- [ [1], [11], [101, 10], [1001, 110], [10001,1010,100], .. |
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
{-# LANGUAGE BangPatterns #-} | |
import System.Environment (getArgs) | |
import Data.List (foldl1', foldl') | |
import Data.Word (Word64) | |
palindromeCoeffBase :: Word64 -> [[Word64]] | |
palindromeCoeffBase b = oddCoeff 1 $ auxList | |
where oddCoeff n (x:xs) = (zipWith (\x y -> if x==y then x else x+y) x $ take n inc) : evenCoeff n xs | |
evenCoeff n (x:xs) = (zipWith (+) x $ take n inc) : oddCoeff (n+1) 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
#| | |
Konwertuje plik z opisem drzewa współpracowników FM Group[1] (plik *.csv; patrz: +datafile+) | |
do języka dot[2]. | |
Linki: | |
[1] http://www.perfumy.fm/inc/tree2.php | |
[2] http://www.graphviz.org/ | |
|# | |
(declaim (optimize (speed 3) (compilation-speed 0) (safety 0) (debug 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
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.Text as T | |
import qualified Data.Text.IO | |
import qualified Data.Attoparsec.Text as AT | |
import qualified Data.Attoparsec.Combinator as ATC | |
import Control.Monad | |
readValue :: AT.Parser T.Text | |
readValue = do |
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
-- http://www.reddit.com/r/compsci/comments/1mv7n2/can_anyone_please_help_me_crack_this_circuit/ | |
-- Hey /r/compsci | |
-- I am in the midst of doing an assigment that requires me to | |
-- make a circuit that has 7 inputs and outputs a 1 if the input | |
-- have at least or more than 4 ones. The requirements are that | |
-- I can only 4 AND gates and limitless XOR gates. Also I can | |
-- only have 2 input connected to a gate. | |
-- | |
-- I've been looking at this for 4 hours now and really can'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
-- Below is a small but complete MPI program. Process 1 sends the message "Hello World" | |
-- to process 0, which in turn receives the message and prints it to standard output. | |
-- All other processes, if there are any, do nothing. | |
-- -- http://hackage.haskell.org/package/haskell-mpi | |
module Main where | |
import Control.Parallel.MPI.Simple (mpiWorld, commWorld, unitTag, send, recv) | |
main :: IO () |
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
#include <cstdio> | |
#include <cstdlib> | |
int main() { | |
int ch; | |
int cha; | |
ch = getchar(); | |
if(ch == 0xEF) { | |
getchar(); // 0xBB | |
getchar(); // 0xBF |
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
[ 20%] Building CXX object CMakeFiles/daemon.dir/src/sqlite.cpp.o | |
In file included from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
In file included from /home/konrad/lachesis/cpp/src/sqlite.hpp:7: | |
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/memory:81: | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:137:9: error: static_assert failed "constructed with null function pointer deleter" | |
{ static_assert(!is_pointer<deleter_type>::value, | |
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:32:20: note: in instantiation of member function 'std::unique_ptr<sqlite3, int (*)(sqlite3 *)>::unique_ptr' requested here | |
LachesisSQLite3db::LachesisSQLite3db(const char *db_path) throw(sqlExecException) { | |
^ |