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
| var obj = function(s) { | |
| // private member | |
| v1 = "priv: " + s; | |
| // public member | |
| this.v2 = "pub: " + s; | |
| // private methods can access private members | |
| function m1() { |
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
| int width = 600; | |
| int height = 600; | |
| int total_points = 100000; | |
| int point_size = 1; | |
| float point_spacing = 1.0; | |
| boolean isPrime(int n) { | |
| if (n < 2) return false; | |
| else if (n == 2) return true; | |
| else if (n % 2 == 0) return false; |
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 math | |
| from collections import defaultdict | |
| def hierarchize(flatlist, func): | |
| output = defaultdict(list) | |
| for item in flatlist: | |
| output[func(item)].append(item) | |
| return output.values() | |
| def evens(n): |
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
| /* | |
| ================ | |
| Q_isnan | |
| Don't pass doubles to this | |
| ================ | |
| */ | |
| int Q_isnan( float x ) | |
| { | |
| floatint_t fi; |
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
| /* | |
| ** float q_rsqrt( float number ) | |
| */ | |
| float Q_rsqrt( float number ) | |
| { | |
| floatint_t t; | |
| float x2, y; | |
| const float threehalfs = 1.5F; | |
| x2 = number * 0.5F; |
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
| /* | |
| * Command table. | |
| */ | |
| const struct cmd_type cmd_table[] = { | |
| /* | |
| * Common movement commands. | |
| */ | |
| {"north", do_north, POS_STANDING, 0, LOG_NEVER, 1, 1, 0, 1}, | |
| {"east", do_east, POS_STANDING, 0, LOG_NEVER, 1, 1, 0, 1}, | |
| {"south", do_south, POS_STANDING, 0, LOG_NEVER, 1, 1, 0, 1}, |
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
| private static class WorldSnapShot | |
| { | |
| // Height of world | |
| float[][] world; | |
| // Height of water | |
| float[][] water; | |
| // Height of snow. | |
| float[][] snow; | |
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
| def check_word(word, letters): | |
| """ | |
| Check if a specific word can be created from the set of letters. | |
| """ | |
| for w in word: | |
| pos = letters.find(w) | |
| if pos == -1: | |
| return False | |
| letters = letters[:pos] + letters[pos+1:] | |
| return True |
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
| var events = []; | |
| var intervals = []; | |
| var max_id = 0; | |
| function setInterval(callback, period) { | |
| intervals.push(new Interval(callback, period)); | |
| return ++max_id; | |
| } | |
| function clearInterval(id) { |
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 itertools | |
| import fractions | |
| def roll(faces, dice, keep): | |
| results = {} | |
| denom = faces ** dice | |
| for roll in itertools.product(*[range(1,faces+1) for d in range(dice)]): | |
| r = sum(sorted(roll, reverse=True)[:keep]) | |
| if not results.has_key(r): results[r] = fractions.Fraction(1, denom) |