Skip to content

Instantly share code, notes, and snippets.

Avatar

Oleg Tsybulskyi alogic0

View GitHub Profile
@alogic0
alogic0 / Astro.hs
Created Jan 27, 2015
Constants and formulae for IntroAstro on Coursera
View Astro.hs
import Data.Ratio
mS=19891*10^26 % 1 --in kg Sun mass
mE=597219*10^19 % 1 --in kg Earth mass
rE=6371000 % 1 --in m Earth radius
tE=3652564 % 10000 --in days Earth siderial year
mM=73477*10^18 % 1 --in kg Moon mass
rM=1737500 % 1 --in m Moon radius
aU=149597870691 % 1 --in m distance to Sun
gN=6673 % (10^14) --in m3/(kg*s2) gravitational constant G
@alogic0
alogic0 / less.hs
Last active Aug 29, 2015
For ghci, pager of defined names in Haskell modules like *less*
View less.hs
-- author [Roman Cheplyaka](http://www.reddit.com/r/haskell/comments/2y2f1p/pager_in_ghci_like_less/cp5w8a9)
import System.Process
import System.Posix.IO
import System.Posix.Types
import Data.IORef
import Data.List (intersperse)
import System.IO.Unsafe
{-# NOINLINE pid_ref #-}
pid_ref :: IORef (ProcessHandle, Fd)
@alogic0
alogic0 / Pong.elm
Last active Aug 29, 2015
Pong game for 1 player, run on http://elm-lang.org/try
View Pong.elm
-- See this document for more information on making Pong:
-- http://elm-lang.org/blog/Pong.elm
-- Compile this code on http://elm-lang.org/try
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Keyboard
import Mouse
import Text
@alogic0
alogic0 / tickets.hs
Last active Aug 29, 2015
tickets cost
View tickets.hs
lst = [206.51]
++ replicate 5 135.93
++ replicate 15 160.4
++ replicate 2 190.25
++ [1586.42]
debt = sum lst
-- m
m = [-3000]
@alogic0
alogic0 / fib999.hs
Last active Aug 29, 2015
Fibonacci numbers in chunks of decimal part of division 1 by 9999...899...
View fib999.hs
num48 = 999999999999999999999998999999999999999999999999
strNum24 = replicate 47 '0' ++ show (10 ^ (58*48) `div` num48)
chunks _ [] = []
chunks n xs = let (h, t) = splitAt n xs in h : chunks n t
result24 = putStr $ unlines $ map (unwords . chunks 24) $ chunks 48 strNum24
--------
fibs :: [Integer]
fibs = 0:1: zipWith (+) fibs (tail fibs)
@alogic0
alogic0 / Nptel_ass2_test_hspec.hs
Created Aug 19, 2015
NPTEL Haskell 2015, HSpec test for Assignment 2
View Nptel_ass2_test_hspec.hs
module Nptel_ass2_test_hspec where
import Nptel_ass2
import Test.Hspec
main :: IO ()
main = hspec $ do
describe "Assignment 2" $ do
describe "ramanujan" $ do
it "Test Case 1" $ do
@alogic0
alogic0 / Nptel_ass2_test_hunit.hs
Last active Aug 29, 2015
NPTEL Haskell 2015, HUnit test for Assignment 2
View Nptel_ass2_test_hunit.hs
module Nptel_ass2_test_hunit
where
import Test.HUnit
import Test.Hspec
import Test.Hspec.Contrib.HUnit
-- Name of your file with the assignment
-- without trailing .hs
import Nptel_ass2
@alogic0
alogic0 / Families.hs
Last active Oct 4, 2015
Changing fmaily-names diversity over generations
View Families.hs
module Families where
import System.Random
import Control.Monad
import Data.List
numPop = 20
num = numPop `div` 2
type Generation = [Pair]
data Pair = Pair {husband::Person, wife::Person, idFamily::Int}
@alogic0
alogic0 / hmatrix-building-win7.md
Last active Dec 14, 2015
How to build hmatrix, Haskell package, on Win7
View hmatrix-building-win7.md
@alogic0
alogic0 / building-hermit-win7.md
Last active Dec 27, 2015
Building hermit on windows 7 with ghc 7.10.2, unsuccessful
View building-hermit-win7.md
git clone https://github.com/ku-fpg/hermit
cd hermit
git checkout 'f0d7b767487'
cabal install --only-dep
cabal configure
cabal build
cabal install