>Write a method to shuffle a deck of cards. It must be a perfect shuffle - in other words, each 52! permutations of the deck has to be equally likely. Assume that you are given a random number generator which is perfect.
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
| const exchange = ({ money, bottle, cap, drinked }) => { | |
| if(money === 0 && bottle < 2 && cap < 4) return drinked; | |
| const newDrink = parseInt(money/2) + parseInt(bottle/2) + parseInt(cap/4); | |
| return exchange({ | |
| money: money % 2, | |
| cap: cap % 4 + newDrink, | |
| bottle: bottle % 2 + newDrink, | |
| drinked: drinked + newDrink, | |
| }); |
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
| 'use strict'; | |
| var test = [10,4,3,5,6,2,8]; | |
| const swap = function(a, b) { | |
| if(this[a] > this[b]) this[a] = [this[b], this[b] = this[a]][0]; | |
| } | |
| const bubbleSort = a => { | |
| a.forEach((x, index) => { |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Document</title> | |
| <meta content="initial-scale=1.0, width=device-width" name="viewport"> | |
| </head> | |
| <body> | |
| <pre id="lines" data-lining> | |
| print("Hello, WWDC!") |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Document</title> | |
| <script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script> | |
| </head> | |
| <body> | |
| <textarea id="content" cols="30" rows="10"></textarea> | |
| <button id="upload">上传</button> |
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 crop package | |
| import crop from 'crop-image'; | |
| // input file onChange callback | |
| this.upload = e => { | |
| const files = e.target.files; | |
| if (files && files[0]) { | |
| const image = new Image(); | |
| image.onload = () => { |
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
| #!/bin/bash | |
| safe_link(){ | |
| local src="$1" | |
| local dest="$HOME/`basename $src`" | |
| [ ! -e "$dest" ] && ln -sf "$src" "$dest" | |
| } | |
| DOTFILES="/Users/x/Dropbox/dotfile/dotfiles" |
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
| const findServer = require('./find_server'); | |
| findServer({ | |
| pingKey: 'your pingkey in config.js', | |
| port: '3001', | |
| path: '/ping', | |
| cb: ip => { | |
| console.log(ip); | |
| }, | |
| }); |
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
| { | |
| "Working Directory" : "\/Users\/vanilla", | |
| "Prompt Before Closing 2" : 0, | |
| "Selected Text Color" : { | |
| "Red Component" : 0.8379544019699097, | |
| "Color Space" : "Calibrated", | |
| "Blue Component" : 0.8379434943199158, | |
| "Alpha Component" : 1, | |
| "Green Component" : 0.837929368019104 | |
| }, |
