Skip to content

Instantly share code, notes, and snippets.

View hleumas's full-sized avatar

Samuel Hapák hleumas

View GitHub Profile
@hleumas
hleumas / dice.md
Last active September 11, 2017 22:41

Dice

Solution to this problem: https://twitter.com/nntaleb/status/907204053079400448

Solution

The dice will be rolled no more than 3 times. Smallest even number is 2 and 2x3=6, which is the desired sum.

Now, the problem statement says that we roll the dice only until we get the sum of 6 or more. Yet, nothing would change, if we rolled the dice exactly for 3 times, but ignored all rolls after we reach 6.

Now, naive solution would be to generate all triplets from numbers 2, 4, 6 and determine how many of them achieved sum >=6 after first, second, or third item. It's the very same thing Nassim Nicholas Taleb has done here: https://twitter.com/nntaleb/status/907211482743668737

@hleumas
hleumas / stores.js
Created July 31, 2015 21:08
Compose stores
import {fromJS} from 'immutable'
import userActions from './userActions'
const userInitialState = fromJS({
logged: false
})
function userStore(state = userInitialState, action, payload) {
switch (action) {
case userActions.loggedIn:
return state.set('logged', true)