Skip to content

Instantly share code, notes, and snippets.

@hueitan
hueitan / Journey-to-the-Moon.js
Last active June 2, 2022 01:01
Journey to the Moon JavaScript Solution
function processData(input) {
var temp = input.split('\n')
var [ N, I ] = temp.shift().split(' ').map( Number )
// generate graph
var graph = [] // store in an array of Set [ 0 : [ 0, 1 ], 1 : [ 3, 2 ] ] (to prevent duplicate)
var relationalMap = {} // use to remember the map { 0 : 0, 1 : 0, 2 : 1, 3 : 1 }
for(let i = 0; i < I;i++)
{
function length_of_factorial(N) {
    if (N < 2) return 1;
    sum = 0;
    for (i = 2; i <= N; i++) {
        sum += Math.log(i) / Math.log(10)
    }

    return Math.floor(sum) + 1
}
N = _fArgs[0]

P1 = N[0]
P2 = N[1]
P3 = N[2]

// area - check http://www.gottfriedville.net/mathtools/triarea.html
Area = Math.abs((P1[0]*(P2[1]-P3[1]) + P2[0]*(P3[1]-P1[1]) + P3[0]*(P1[1]-P2[1]))/2)
@hueitan
hueitan / spiral-order.md
Created May 10, 2015 10:30
spiral order (clockwise from top left) -

It's from others.

function spiralMatrix(matrix) {

  var i;
  var top = 0;
  var left = 0;
  var bottom = matrix.length;
 var right = matrix[0].length;
@hueitan
hueitan / taller.md
Last active August 29, 2015 14:20
circle standing, who is taller challenge - https://codefights.com/feed/wG7zrPuKNMb9ppua6

Original answer

function Taller (N,M) {

var output = [];
// check every element
for (i=0;i<N;i++) {
   
   var temp = [];
@hueitan
hueitan / trailing_zero.md
Last active August 29, 2015 14:20
trailing zero problem (superfactorial) - https://codefights.com/feed/ZKW6FzW8Rjj9wTLWo
function superfactorialZeros(N) {
    var result = 0;
    for (i = 1; i <= N; i++) {
        result += zeroes(i);
    }

    return result;
}
@hueitan
hueitan / gogo.md
Created May 5, 2015 02:32
stupid approach answer - prime factor - https://codefights.com/feed/wncb8W4K9uJnT2uG7
function PrimeOperations(X, Y) {
var x = getPrimeFactors(X),
    y = getPrimeFactors(Y),
    k = 0;
  
  for(i=0;x[i];i++) {
    for (j=0;y[j];j++) {
      if (x[i] == y[j]) {
 k += 2;
@hueitan
hueitan / test.md
Created April 30, 2015 10:23
test
o = ''
b = arguments[0]

for (k in b)
  o += '                                                                                                                                                                                                  d3d4d5  d7  e6e5e4    f2  h2h1g1  e1d1c1b1  a2  c2'.substr(b[k].charCodeAt() *2,2)

return o

65 char

n = arguments[0]
s = n*n*++n*n/4


  while(k=--n*n*n)
	s -= k*k
  
 
function arr_encryption(msg) {
  var message = msg.split(' ').join('.'),
      output = '';
      
  // add . if needed
  for (k=0;k<message.length % 6;k++) {
    message += '.';
  }