Skip to content

Instantly share code, notes, and snippets.

View vicneanschi's full-sized avatar

Valeri Vicneanschi vicneanschi

  • Montreal, Canada
View GitHub Profile
function processData(input) {
var lines = input.split('\n');
var tmp = lines[0].split(' ').map(x => parseInt(x));
var n = tmp[0];
var m = tmp[1];
var coins = lines[1].split(' ').map(x => parseInt(x)).slice(0, m);
// sorting coins to decrease number of calls
coins.sort();
//console.log(n, m, coins);
@vicneanschi
vicneanschi / rotate-matrix.js
Created March 15, 2016 23:32
Rotate the matrix anti-clockwise
/*
https://www.hackerrank.com/challenges/matrix-rotation-algo
You are given a 2D matrix, a, of dimension MxN and a positive integer R.
You have to rotate the matrix R times and print the resultant matrix.
Rotation should be in anti-clockwise direction.
*/
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
@vicneanschi
vicneanschi / CreateCARoot.cmd
Created March 7, 2016 17:44
Makecert in windows
rem http://www.jayway.com/2014/09/03/creating-self-signed-certificates-with-makecert-exe-for-development/
makecert.exe ^
-n "CN=CARoot" ^
-r ^
-pe ^
-a sha512 ^
-len 4096 ^
-cy authority ^
-sv CARoot.pvk ^
node --expose-gc --trace-gc --trace-gc-verbose --trace-gc-ignore-scavenger --max-old-space-size=1000 server.js
function primes(num){
var result = [2, 3];
for(var i = 5; i<= num; i+=2){
if ( result.every( x => i % x ) ) {
result.push(i);
}
}
return result;
}
@vicneanschi
vicneanschi / question.txt
Last active March 3, 2016 03:01
Exact Change
Design a cash register drawer function that accepts purchase price as the first argument, payment as the second argument, and cash-in-drawer (cid) as the third argument.
cid is a 2d array listing available currency.
Return the string "Insufficient Funds" if cash-in-drawer is less than the change due. Return the string "Closed" if cash-in-drawer is equal to the change due.
Otherwise, return change in coin and bills, sorted in highest to lowest order.
// Example cash-in-drawer array:
// [["PENNY", 1.01],
/*
A number is called a circular prime if it is prime and all of its rotations are primes.
For example the number 197 has two rotations: 971, and 719.
Both of them are prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below N?
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli '-ddd' ]
2 info using [email protected]
3 info using [email protected]
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readLocalPackageData
"use strict";
function Graph(){
this.vertices = {};
//graph.addVertex('vFrom', {'vTo1': 1, 'vTo2': 1});
this.addVertex = function(name, edges) {
this.vertices[name] = edges;
}
/**
* Created by VV on 2/3/2016.
*/
"use strict";
function PriorityQueue(){
this._nodes = [];
this.enqueue = function (priority, item){
this._nodes.push({priority: priority, item: item});