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
//: # Harmonic Oscillator Schrödinger Equation | |
//: | |
//: Numerically Solve for Shrödinger's Equation using the | |
//: Numerov algorithm. This example inspired by Quantum | |
//: Physics for Dummies, Steven Holzner, John Wiley & Sons, Inc. 2013. | |
//: | |
//: Had to increase the delta (step size) and reduce the maximum allowed | |
//: error to make it run in a reasonable amount of time in the playground. | |
//: (This obviously could be solved by switching to [more] compiled code.) | |
//: |
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
//: # Harmonic Oscillator Schrödinger Equation | |
//: ## Version 2 | |
//: | |
//: Numerically Solve for Shrödinger's Equation using the | |
//: [Numerov method](https://en.wikipedia.org/wiki/Numerov%27s_method). | |
//: This example inspired by Quantum | |
//: Physics for Dummies, Steven Holzner, Wiley 2013. | |
//: | |
//: This version is thousands of times faster and more | |
//: accurate than my more direct port of the original. It starts with |
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
var i = 0 | |
while (i < 10) { | |
print(i) | |
i += 1 | |
} |
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 <iostream> | |
#include <vector> | |
#include <functional> | |
namespace rf { | |
template <typename T, typename Compare = std::less<T>> | |
std::vector<T> merge_sort(const std::vector<T>& input, | |
const Compare& compare = Compare()) | |
{ |
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
class Array | |
def merge_sort | |
c = self.count | |
return self if c <= 1 | |
mid = c/2 | |
left = self[0,mid].merge_sort | |
right = self[mid, mid+1].merge_sort | |
output = [] | |
l = 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
- (void)viewDidAppear:(BOOL)animated | |
{ | |
[super viewDidAppear:animated]; | |
[self move]; | |
} | |
- (void)move | |
{ | |
static BOOL flipFlop; |
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
struct MultiArray<Element> { | |
private var data: [Element] // the actual data | |
private var counts: [Int] // the size of each dimension | |
private var offsets: [Int] // multipliers for accessing each dimension quickly | |
private func computeIndex(indices: [Int]) -> Int { | |
precondition(indices.count == counts.count) | |
for (index, count) in zip(indices, counts) { | |
precondition(index >= 0 && index < count) |
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
//: # Generic frequencies for SequenceType | |
//: | |
//: Based on a tweet from Airspeed Velocity @airspeedswift | |
//: describing a custom subscript operation that takes | |
//: an initial value if the key is not found. | |
import Foundation | |
extension Dictionary { | |
subscript(key: Key, or initial: Value) -> Value { |
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
// | |
// Ring.swift | |
// | |
// Copyright (c) 2014 Pelfunc, Inc. All rights reserved. | |
// | |
/// Allow iteration of Ring<T> in LIFO order | |
public struct RingGenerator<T> : GeneratorType { | |
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
import UIKit | |
protocol Tapper: class { | |
func install() | |
func foo() | |
} | |
extension Tapper where Self: UIViewController { | |
func install() { | |
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "foo")) |