Skip to content

Instantly share code, notes, and snippets.

View deniskyashif's full-sized avatar

Denis Kyashif deniskyashif

View GitHub Profile
(function() {
'use strict';
Function.prototype.inherits = function(Parent) {
this.prototype = new Parent();
this.prototype.constructor = this;
};
var Person = function (name) {
this.name = name;
x * 2^y = x << y
x / 2^y = x >> y
x % y = x & (y-1)
@deniskyashif
deniskyashif / RSelect.cs
Created July 26, 2015 07:31
randomized selection in C#
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];
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;
/* 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?
/*
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
{
/*
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.
*/
// Find the maximum total from top to bottom of the triangle below:
using System;
class Program
{
static void Main()
{
var triangle = new int[][]
{
@deniskyashif
deniskyashif / Global.Application_Start.cs
Last active January 30, 2020 19:54
Integrate OpenGraph and TwitterCard with Sitefinity
protected void Application_Start(object sender, EventArgs e)
{
Bootstrapper.Initialized += this.BootstrapperInitializedHook;
}
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;
}