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
// fib seq | |
// 1 1 2 3 5 8 13 21 ... | |
num fibonacci(num n) { | |
if (n == 1 || n == 2) { | |
return 1; | |
} else { | |
return fibonacci(n-1) + fibonacci(n-2); | |
} | |
} |
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
// Estimate PI using monte carlo simulation | |
// See http://www.davidrobles.net/blog/2014/06/22/estimating-pi-using-monte-carlo-simulations/ | |
import 'dart:math'; | |
Random rnd = new Random(); | |
// Return a random point within [-1, 1] coordinate plane | |
class UnitPoint { | |
double x; |
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
void main() { | |
var v = [ 1,2,3,4,5,6,7,8,9,10 ]; | |
print(v); | |
print(v.contains(5)); | |
print(v.where((x) => x % 2 == 0)); | |
print(v.any((x) => x > 10)); | |
print(v.map((x) => x * x)); | |
print(v.length); | |
} |
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 'dart:math'; | |
List values(int length) { | |
List v = []; | |
Random r = new Random(); | |
for (int i = 0; i < length; i++) { | |
v.add(r.nextInt(100)); | |
} | |
return v; | |
} |
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
// shows how to use cascade method calls in Dart | |
class Cat { | |
String color; | |
Cat(this.color); | |
meow() { print("meow"); } | |
yawn() { print("yawn"); } | |
show() { print("furry ${color} hair"); } | |
} |
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
// positional parameters by fatdragon2 | |
say({String from, | |
String msg : "good morning america", | |
String device, | |
String version : '7'}) | |
{ | |
var result = '$from says $msg'; | |
if (device != null) { | |
result = '$result with a $device ${version != null ? version : ""}'; |
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 pylab import * | |
def cface(ax, x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18): | |
# x1 = height of upper face | |
# x2 = overlap of lower face | |
# x3 = half of vertical size of face | |
# x4 = width of upper face | |
# x5 = width of lower face | |
# x6 = length of nose | |
# x7 = vertical position of mouth |