[ Launch: Tributary inlet ] 8705650 by hanbzu
gistup |
This example aims to demonstrate our inability to fully grasp [exponential functions][wikg]. As [Albert Bartlett][barl] once said, "The greatest shortcoming of the human race is our inability to understand the exponential function." This little D3 animation is based on a paper by Dr Bartlett.
Our action hero, a pixelated version of [Chris Martenson][chrs], stands on a platform inside an empty 4000 litre water tank. At the very bottom of the tank lies a magic drop of water. Invisible to the eye now, it doubles in size every 10 seconds.
Although the growth rate is constant, for a long time we see no change. But there's a well known limit, the capacity of the tank. Once he realises that water is rising exponentially, poor pixellated Chris has no time left to react.
Our brains are wired to predict future behaviour based on past behaviour (see [here][psyc]). But what happens when something growths exponentially? For a long time, the numbers are so little in relation to the scale that we hardly see the ch
<!DOCTYPE html> | |
<html> | |
<head> | |
<script class="jsbin" src="http://cdnjs.cloudflare.com/ajax/libs/raphael/1.5.2/raphael-min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
<!--[if IE]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<style> |
Data analysis with R -- It's better and better now | |
================================================== | |
A nice R resource, the “cookbook for R”: http://wiki.stdout.org/rcookbook/ | |
Installing | |
---------- | |
```{r installing} | |
# For Linux: Install package directly from CRAN accessible for all users |
// Pairs can be constructed easily using parentheses: | |
val pair: (Char, Int) = ('c', 1) | |
// In order to access the two elements of a pair, you can use the accessors `_1` and `_2`: | |
val theChar = pair._1 | |
val theInt = pair._2 | |
// Another way to deconstruct a pair is using pattern matching: | |
pair match { | |
case (theChar, theInt) => |
// Remove all whitespace from String | |
"This is a string".replaceAll("\\s+","") |
// A list of strings into a single string | |
val food = "rice" :: "cookies" :: "watermelon" :: Nil | |
food.foldLeft("")(_ + ", " + _) | |
// But we would have to remove the first two chars: | |
// ", rice, cookies, watermelon" | |
// Now with mkString | |
val fruits = "apple" :: "orange" :: "kiwi" :: Nil | |
fruits mkString ", " |
/** | |
* For each unique character in the list `chars`, it calculates the number of | |
* times it occurs. times(List('a', 'b', 'a')) should return List(('a', 2), ('b', 1)) | |
*/ | |
def howManyTimes(w: String): List[(Char, Int)] = { // w = "Wooord" | |
val grouped = w.groupBy(x => x.toLower) // Map(d -> d, w -> W, r -> r, o -> ooo) | |
val occ = grouped.mapValues(_.length) // Map(d -> 1, w -> 1, r -> 1, o -> 3) | |
occ.toList // List((d,1), (w,1), (r,1), (o,3)) | |
} |
// A simple function | |
function add(a, b) { | |
console.log(a + b); | |
} | |
// A first class function | |
// It can be passed along as a variable | |
var add = function (a, b) { | |
console.log(a + b); | |
}; |