Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View cortezcristian's full-sized avatar

Cristian Cortez cortezcristian

View GitHub Profile
@cortezcristian
cortezcristian / solution1.js
Created July 10, 2020 18:44
Coding the Josephus Problem solution1.js
// My ugly first solution draft
const solution = (n) => {
// Ensure n is number
if (typeof n !== 'number') return 0;
// Ensure n is > 0
if (n < 1) return 0;
// This array represents the circle
const arr = [];
// Fill the array with 1 ones to begin
@cortezcristian
cortezcristian / solution3.js
Created July 10, 2020 18:34
Coding the Josephus Problem solution3.js
// Third solution binary based
const solution3 = (n) => {
// Convert to BIN
const binaryStr = Number(n).toString(2);
// Swapping digits
const newBinaryStr = (binaryStr + binaryStr[0]).replace(/./, '');
// Convert back to DEC
return parseInt(newBinaryStr, 2);
};
@cortezcristian
cortezcristian / solution2.js
Created July 10, 2020 18:31
Coding the Josephus Problem solution2.js
let nearestLowerPow2 = function (x) {
if (x == 0) return 0;
const arr = [1, 2, 4, 8, 16];
arr.forEach(function(n) {
x |= (x >> n);
});
return x - (x >> 1);
}
@cortezcristian
cortezcristian / Nearest_Lower_Square.csv
Created July 10, 2020 18:28
Coding the Josephus Problem Nearest Lower Square
Number Nearest Lower Square
1 1
2 2
3 2
4 4
5 4
@cortezcristian
cortezcristian / Nearest_Lower_Square.csv
Last active July 10, 2020 18:25
Coding the Josephus Problem
Number Nearest Lower Square
1 1
2 2
3 2
4 4
5 4

Get the info

const _ = require('lodash');
const fs = require('fs');
const agent = require('superagent');

const readJson = (path, cb) => {
  fs.readFile(require.resolve(path), (err, data) => {
    if (err)

grep -lir "custome" app/migrations/201712* app/migrations/20171207120858.js app/migrations/20171222212151.js app/migrations/20171227151229.js

@cortezcristian
cortezcristian / README.md
Created August 18, 2016 17:48
A1 Candidate Viewer

Issues, Bugs and Inconsistencies

1- Fix candidate case in labels, cases like "city" and "country" should be "City" and "Country"

2- Placeholders text. Fix inconsistencies like "Type candidate location" should be "Country" instead.

@cortezcristian
cortezcristian / README.md
Last active August 12, 2016 03:16
Phoenix and Elixir

My first impressions using Phoenix and Elixir.

Installation

In OS X simply run:

$ brew install elixir