Skip to content

Instantly share code, notes, and snippets.

View logalleon's full-sized avatar
🍄

Logan S. logalleon

🍄
View GitHub Profile
@logalleon
logalleon / json-to-csv.js
Last active August 29, 2015 14:24
JSON to CSV
/*
* Logan H. Sobczak 6/24/15
* Converts arbitrary JSON to CSV
*
* node json-to-csv.js [file1.json, file2.json, ... ]
* outputs to ./csv/file1.csv, ./csv/file2.csv . . .
*/
var fs = require('fs'),
files = process.argv.slice(2);
@logalleon
logalleon / 28.cpp
Last active August 29, 2015 14:24
Project Euler 28
#include <iostream>
using namespace::std;
// Calculates the sum of the diagonals of number spiral size s x s.
int spiralDiagonalSum(int s) {
// The size of the spiral
int start = s*s;
// Starting array offset
int offset = s-1;
@logalleon
logalleon / 8.cpp
Last active August 29, 2015 14:24
Project Euler 8
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace::std;
// Finds the maximum product of n sequential digits in an s-sized series.
long long findSeriesProduct(int a[], int s, int n, int i){
// Base case
if (n + i > s) return 0;
@logalleon
logalleon / 14.cpp
Created July 14, 2015 02:48
Project Euler 14
#include <iostream>
#include <algorithm>
using namespace::std;
int chainLength(unsigned long long x){
int len = 1;
while (x > 1){
if (x % 2) x = 3*x + 1;
else x /= 2;
enum DwarfStatus {
NO_JOB,
NO_DESTINATION,
SLEEPING,
ACTIVE
}
function fn (status: DwarfStatus): void {
switch (status) {
case DwarfStatus.ACTIVE:
/* ... do things */
}
}
function fn (status: DwarfStatus): void {
switch (status) {
case DwarfStatus.ACTIVE:
break;
case DwarfStatus.NO_DESTINATION:
break;
case DwarfStatus.NO_JOB:
break;
}
}
function fn (status: DwarfStatus): void {
switch (status) {
case DwarfStatus.ACTIVE:
break;
case DwarfStatus.NO_DESTINATION:
break;
case DwarfStatus.NO_JOB:
break;
default:
_never(status);
const renderMap: RenderMap = {
[DwarfStatus.NO_DESTINATION]: { char: 'ø' }
}
renderMap[DwarfStatus.NO_JOB] = { char: 'n' };
var DwarfStatus;
(function (DwarfStatus) {
DwarfStatus[DwarfStatus["NO_JOB"] = 0] = "NO_JOB";
DwarfStatus[DwarfStatus["NO_DESTINATION"] = 1] = "NO_DESTINATION";
DwarfStatus[DwarfStatus["SLEEPING"] = 2] = "SLEEPING";
DwarfStatus[DwarfStatus["ACTIVE"] = 3] = "ACTIVE";
})(DwarfStatus || (DwarfStatus = {}));