Command:
$ brew install ghc cabal-install
Result:
==> Downloading https://homebrew.bintray.com/bottles/ghc-8.0.1_3.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring ghc-8.0.1_3.sierra.bottle.tar.gz
==> Using the sandbox
==> /usr/local/Cellar/ghc/8.0.1_3/bin/ghc-pkg recache
🍺 /usr/local/Cellar/ghc/8.0.1_3: 5,775 files, 1G
==> Downloading https://homebrew.bintray.com/bottles/cabal-install-1.24.0.1.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring cabal-install-1.24.0.1.sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/cabal-install/1.24.0.1: 7 files, 27.7M
Monday, December 5, 2016
Sunday, December 4, 2016
Python: Returning Polynomial Function
Command:
$ cat makePoly.py
Result:
# ax + b
def makePoly(arr):
def fn(x):
return sum(c*x**p for p,c in enumerate(arr))
return fn
my_func = makePoly([6, 2])
print my_func(3) #return 12
Command:
$ python makePoly.py
Result:
12
Python: Pi and Natural Logarithm
Command:
$ cat pi_and_natural_logarithm.py
Result:
import math
print 'Pi: %.30f' % math.pi
print 'e: %.30f' % math.e
Command:
$ python pi_and_natural_logarithm.py
Result:
Pi: 3.141592653589793115997963468544
e: 2.718281828459045090795598298428
$ cat pi_and_natural_logarithm.py
Result:
import math
print 'Pi: %.30f' % math.pi
print 'e: %.30f' % math.e
Command:
$ python pi_and_natural_logarithm.py
Result:
Pi: 3.141592653589793115997963468544
e: 2.718281828459045090795598298428
Saturday, December 3, 2016
Python: Farey Sequence: The Farey sequences of orders 8
Command:
$ cat farey.py
Result:
def farey( n, asc=True ):
if asc:
a, b, c, d = 0, 1, 1 , n
else:
a, b, c, d = 1, 1, n-1, n
print "%d/%d" % (a,b)
while (asc and c <= n) or (not asc and a > 0):
k = int((n + b)/d)
a, b, c, d = c, d, k*c - a, k*d - b
print "%d/%d" % (a,b)
farey(8)
Command:
$ python farey.py
Result:
0/1
1/8
1/7
1/6
1/5
1/4
2/7
1/3
3/8
2/5
3/7
1/2
4/7
3/5
5/8
2/3
5/7
3/4
4/5
5/6
6/7
7/8
1/1
$ cat farey.py
Result:
def farey( n, asc=True ):
if asc:
a, b, c, d = 0, 1, 1 , n
else:
a, b, c, d = 1, 1, n-1, n
print "%d/%d" % (a,b)
while (asc and c <= n) or (not asc and a > 0):
k = int((n + b)/d)
a, b, c, d = c, d, k*c - a, k*d - b
print "%d/%d" % (a,b)
farey(8)
Command:
$ python farey.py
Result:
0/1
1/8
1/7
1/6
1/5
1/4
2/7
1/3
3/8
2/5
3/7
1/2
4/7
3/5
5/8
2/3
5/7
3/4
4/5
5/6
6/7
7/8
1/1
Subscribe to:
Posts (Atom)