Instantly share code, notes, and snippets.

# Nil-Zil

• Sort options
Created Jan 20, 2018
View set.hs
 head1 :: [a] -> a head1 [] = error "empty List" head1 (x:xs) = x head2 :: [a] -> Maybe a head2 [] = Nothing head2 (x:xs) = Just x filter' :: (a -> Bool) -> [a] -> [a] filter' _ [] = []
Created Jan 20, 2018
Iterating and recursing implementation of factorial.
View factorial.hs
 factRecur :: Int -> Int factRecur 0 = 1 factRecur n = n * factRecur (n - 1) factIter :: Int -> Int -> Int factIter 0 m = m factIter n m = factIter (n - 1) n * m
Last active Jan 20, 2018
 add :: (Int, Int) -> Int -- function with 2 parameters add (x, y) = x + y add2 :: Int -> (Int -> Int) -- Curry add2 x y = x + y -- return partially applied functions addone = add2 1 addlambda :: Int -> Int -> Int addlambda = \x y -> x + y
Created Jan 19, 2018
View factorial.py
 #!/usr/bin/env python3 # created at Jun 3, 2017 01:19 by Nil-Zil class Factorial(object): def factorial_recur(self, n): if n is 1: return 1 else:
Created Jan 19, 2018
View leap_frog.py
 #!/usr/bin/env python # created at Jan 18, 2017 22:06 by Nil-Zil """ Leap frog algorithm. """ import matplotlib.pyplot as plt import numpy as np time = 10
Created Jan 19, 2018
View sort_lists.py
 #!/usr/bin/env python3 # created at Jun 23, 2017 21:04 by Nil-Zil """ Sort list d, e, f by the elements in a, b, c. """ from operator import itemgetter import numpy as np
Created Jan 4, 2018
View tree.py
 from typing import * class Tree(dict): """ A tree implementation using python's autovivification feature. """ def __init__(self, data: Optional[Any] = {}): """
Created Aug 22, 2017
View curve_fit.py
 import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt def func(x, a, b, c): return a * np.exp(-b * x) + c x_data = np.linspace(0, 10, 20) y_data = [1.005530886735986, 0.36271009697000134, 0.10282751652440644, 0.03638464925638259, 0.0177328764419975, 0.007038622747455951, -0.011725650107022643, 0.017847156954980542, -0.0006555003543666825, 0.021014391787336193, -
Created Aug 6, 2017
magnetic field of a solenoid
View magnetic field of a solenoid.nb
 plist = Table[{(4 i - 26)/6, -(-1)^i}, {i, 1, 12}]; r[{xi_, yi_}] := Sqrt[(x - xi)^2 + (y - yi)^2]; DensityPlot[ 2 Sqrt[((Plus @@ Map[#[[2]] (x - #[[1]])/r[#]^2 &, plist])^2 + (Plus @@ Map[-#[[2]] (y - #[[2]])/r[#]^2 &, plist])^2)] + Cos[18.8 Plus @@ Map[#[[2]]/r[#] &, plist]] + 1, {x, -6, 6}, {y, -3, 3}, Mesh -> False, Frame -> False, PlotRange -> {0, 10}, PlotPoints -> {275, 138}, AspectRatio -> 1/2]
Created Jul 25, 2017
.gitignore
View .gitignore
 # macOS # General *.DS_Store .AppleDouble .LSOverride # Icon must end with two \r Icon
You can’t perform that action at this time.