This file contains hidden or 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
| from math import e, pi, sqrt | |
| def get_xvalues(a,b,N): | |
| dist = 1.0*b - 1.0*a | |
| dx = dist/N | |
| half = dx/2.0 | |
| R = [(a + dx * n + half) for n in range(N)] | |
| return R, dx | |
| def integrate(a,b,f,N=100): |
This file contains hidden or 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
| from matplotlib import pyplot as plt | |
| import numpy as np | |
| p = 81 | |
| q = 219 | |
| def f(x): | |
| return x**(p-1)*(1-x)**(q-1) | |
| X = np.linspace(0,1,1000) |
This file contains hidden or 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
| from random import choice as ch | |
| R = range(1,366) | |
| # report doubles, triples for a single run | |
| def analyze(L): | |
| L.sort() | |
| rD = dict() | |
| i = 0 | |
| while i < len(L) - 1: # up to penultimate item | |
| v = L[i] |
This file contains hidden or 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
| from random import choice as ch | |
| R = range(1,366) | |
| # report doubles, triples for a single run | |
| def analyze(L): | |
| L.sort() | |
| rD = dict() | |
| i = 0 | |
| while i < len(L) - 2: # up to penultimate item | |
| v = L[i] |
This file contains hidden or 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
| func merge(a1: [Int], _ a2: [Int]) -> [Int] { | |
| // a1 and a2 are sorted already | |
| var ret: [Int] = [] | |
| var i: Int = 0 | |
| var j: Int = 0 | |
| while i < a1.count || j < a2.count { | |
| if j == a2.count { | |
| if i == a1.count - 1 { | |
| ret.append(a1[i]) | |
| } |
This file contains hidden or 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
| import os, subprocess, time | |
| for i in range(100): | |
| print(str(i+1)) | |
| cmd = 'open -a "MyApp"' | |
| p = subprocess.Popen(cmd, shell=True) | |
| pid,ecode = os.waitpid(p.pid, 0) | |
| if ecode != 0: | |
| print "error" | |
| break |
This file contains hidden or 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
| import Foundation | |
| func t() { | |
| let a: [Int32] = [1,2,3,4,5] | |
| let n = Int32(a.count) | |
| Swift.print("Swift: a = \(a)") | |
| let ptr = UnsafeMutablePointer<Int32>(a) | |
| f1(ptr, n) | |
| f2(ptr, n) | |
| f1(ptr, n) |
This file contains hidden or 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 <stdio.h> | |
| #include <math.h> | |
| void f1(int *ptr, int n) { | |
| printf("f1\n"); | |
| for (int i = 0; i < n; i++) { | |
| printf("%d ", ptr[i]); | |
| } | |
| printf("\n"); | |
| } |
This file contains hidden or 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
| import Foundation | |
| func encrypt() { | |
| let msg = "My messageXXXXXX" | |
| let key = "my secret pwXXXX" | |
| var keyBuffer = [UInt8]( | |
| count: 16, | |
| repeatedValue: 0) | |
This file contains hidden or 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
| import Encryptor | |
| func applicationDidFinishLaunching(aNotification: NSNotification) { | |
| // Insert code here to initialize your application | |
| let key = Key("mypassphrase") | |
| key.stretch() | |
| let e = Encryptor(key) | |
| print("\(e)") | |
| } |