Skip to content

Instantly share code, notes, and snippets.

@thejoshwolfe
Created August 2, 2016 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejoshwolfe/8582c60aa6916d7f2e574c1580931feb to your computer and use it in GitHub Desktop.
Save thejoshwolfe/8582c60aa6916d7f2e574c1580931feb to your computer and use it in GitHub Desktop.
...................................................................................................#
...............................................................................................#####
..........................................................................................##########
.....................................................................................###############
................................................................................####################
..........................................................................##########################
......................................................................##############################
.................................................................###################################
...........................................................#########################################
.......................................................#############################################
..................................................##################################################
............................................########################################################
.......................................#############################################################
...................................#################################################################
.............................#######################################################################
.........................###########################################################################
...................#################################################################################
..............######################################################################################
..........##########################################################################################
.....###############################################################################################
####################################################################################################
var choices = [];
var itemCount = 100;
var triangleArea = itemCount * (itemCount + 1) / 2;
for (var i = 0; i < 1000000; i += 1) {
var y = Math.random() * triangleArea;
var index = Math.floor((Math.sqrt(8 * y + 1) - 1) / 2);
//var index = Math.floor(Math.sqrt(Math.random() * itemCount));
if (choices[index]) {
choices[index] += 1;
} else {
choices[index] = 1;
}
}
var height = 20;
var maxValue = 0;
choices.forEach(function(v) {
if (v > maxValue) maxValue = v;
});
var outputString = "";
for (var y = height; y >= 0; y--) {
for (var index = 0; index < itemCount; index++) {
if (choices[index] / maxValue * height >= y) {
outputString += "#";
} else {
outputString += ".";
}
}
outputString += "\n";
}
console.log(outputString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment