Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# Huei Tan hueitan

Last active Jun 2, 2022
Journey to the Moon JavaScript Solution
View Journey-to-the-Moon.js
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 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++) {
Last active Aug 29, 2015
Number of digits of factorial - https://codefights.com/challenge/KW8NZKvNFZ4HdTdSZ
View digits_factorial.md
```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
}```
Last active Aug 29, 2015
Three points - https://codefights.com/feed/w38qWXEMh2TYGdJG5
View three_points.md
```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)```
Created May 10, 2015
spiral order (clockwise from top left) -
View spiral-order.md

It's from others.

```function spiralMatrix(matrix) {

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

Original answer

```function Taller (N,M) {

var output = [];
// check every element
for (i=0;i<N;i++) {

var temp = [];```
Last active Aug 29, 2015
trailing zero problem (superfactorial) - https://codefights.com/feed/ZKW6FzW8Rjj9wTLWo
View trailing_zero.md
```function superfactorialZeros(N) {
var result = 0;
for (i = 1; i <= N; i++) {
result += zeroes(i);
}

return result;
}```
Created May 5, 2015
stupid approach answer - prime factor - https://codefights.com/feed/wncb8W4K9uJnT2uG7
View gogo.md
```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;```
Created Apr 30, 2015
test
View test.md
```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```
Last active Aug 29, 2015
View ^6-^2.md

65 char

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

while(k=--n*n*n)
s -= k*k

```
Last active Aug 29, 2015
encrypt(prisoner) - https://codefights.com/feed/JkoWtd3vL6MQGZWPf
View encrypt.md
```function arr_encryption(msg) {
var message = msg.split(' ').join('.'),
output = '';

// add . if needed
for (k=0;k<message.length % 6;k++) {
message += '.';
}
```