This file contains 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
(function() { | |
'use strict'; | |
Function.prototype.inherits = function(Parent) { | |
this.prototype = new Parent(); | |
this.prototype.constructor = this; | |
}; | |
var Person = function (name) { | |
this.name = name; |
This file contains 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
x * 2^y = x << y | |
x / 2^y = x >> y | |
x % y = x & (y-1) |
This file contains 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
using System; | |
using System.Collections.Generic; | |
public class RSelect<T> where T : IComparable { | |
private Random rnd = new Random(); | |
public T Select(IList<T> collection, int left, int right, int k) { | |
if((right - left) <= 1) | |
return collection[right]; | |
This file contains 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
using System; | |
class Program | |
{ | |
private const ulong N = 600851475143; | |
static void Main() | |
{ | |
bool[] composites = new bool[(ulong)Math.Sqrt(N)]; | |
ulong length = (ulong)composites.Length; |
This file contains 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
/* The following iterative sequence is defined for the set of positive integers: | |
n → n/2 (n is even) n → 3n + 1 (n is odd) | |
Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 | |
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. | |
Which starting number, under one million, produces the longest chain? |
This file contains 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
/* | |
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. | |
How many such routes are there through a 20×20 grid? | |
*/ | |
using System; | |
class Program | |
{ |
This file contains 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
/* | |
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 | |
letters used in total. | |
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? | |
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 | |
(one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage. | |
*/ |
This file contains 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
// Find the maximum total from top to bottom of the triangle below: | |
using System; | |
class Program | |
{ | |
static void Main() | |
{ | |
var triangle = new int[][] | |
{ |
This file contains 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 validator = $('#form').kendoValidator({ | |
messages: { | |
text: 'Field must contain at most 20 symbols.', | |
grid: 'The grid must contain at least two rows.' | |
}, | |
rules: { | |
text: function(item) { | |
if (item.is('[name=text]')) { | |
return item.val().length < 20; | |
} |
This file contains 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
/* | |
The problem: define functions range, map, reverse and foreach, obeying the restrictions below, such that the following program works properly. | |
It prints the squares of numbers from 1 to 10, in reverse order. | |
You must not use arrays. The square bracket characters, [ and ], are forbidden, as well as new Array. | |
You must not use objects. The curly braces, { and }, and the dot character (.) are forbidden. You may use curly braces for code blocks, but not for creating JavaScript objects. | |
Should go without saying, these functions must be generic and do what their name implies. They must not be hard-coded for the particular 1..10 example. | |
*/ |
OlderNewer