So I just encountered a very interesting problem, and came up with a likewise very interesting solution. Recently, my family has made the switch from everyone getting gifts for everyone for Christmas to each person getting gifts for a single person assigned to them. I volunteered to make a JavaScript auto-assigner that will randomly assign one person to each of us and then privately email each of us with the person that we have been assigned.
(Finished in only 589 lines of code, not including another 420 lines of test code!)
*** View this blog with HTTP instead of HTTPS to see the code formatted nicely. ***
Showing posts with label array. Show all posts
Showing posts with label array. Show all posts
Monday, November 20, 2017
Christmas Assigner Problem
Labels:
algorithm,
array,
assigner,
calculator,
Christmas,
computation,
efficiency,
email,
exchange,
for,
gift,
HTML,
JavaScript,
loop,
object,
script,
SMTP,
SMTP2Go,
some
Monday, January 28, 2013
Character Arrays in C++
This tutorial will show you how to use char (character) arrays in c++. In case you don't know, in the coding world there are strings of text, e.g.:
"Hello world!"
and these strings can be divided into arrays of characters:
'H' + 'e' + 'l' + 'l' + 'o' + ' ' + 'w' + 'o' + 'r' + 'l' + 'd' + '!'
Each character within a string, file, network packet, or etc. can easily be accessed individually if you use a character array:
charArray[0] == 'H'
charArray[1] == 'e'
etc...
In this tutorial, we will be making a program that will read an input file (which is expected to be a series of phone numbers separated by commas), go through each character in the file and make some changes, and then output the result to another file.
"Hello world!"
and these strings can be divided into arrays of characters:
'H' + 'e' + 'l' + 'l' + 'o' + ' ' + 'w' + 'o' + 'r' + 'l' + 'd' + '!'
Each character within a string, file, network packet, or etc. can easily be accessed individually if you use a character array:
charArray[0] == 'H'
charArray[1] == 'e'
etc...
In this tutorial, we will be making a program that will read an input file (which is expected to be a series of phone numbers separated by commas), go through each character in the file and make some changes, and then output the result to another file.
Thursday, September 27, 2012
Averaging Multidimensional Data for D3 Part 2
In my previous tutorial, I showed you conceptually how to average the data such that the 3 pieces of data in each row are averaged together and only 1 bar and text is shown per row for each average. This time I'm actually going to backtrack to the code I was using in the tutorial before that so that I can show you another way of averaging the data.
What we're going to average this time are not the 3 pieces of data per row (we're going to leave those alone this time); instead, we're going to average all of the elements each with a unique "Site Type" and "Media Type" value together.
What we're going to average this time are not the 3 pieces of data per row (we're going to leave those alone this time); instead, we're going to average all of the elements each with a unique "Site Type" and "Media Type" value together.
Saturday, September 15, 2012
Averaging Multidimensional Data for D3
Building from the example in my previous tutorial, I am only going to slightly modify a few aspects of the graph. My goal for this tutorial is to show how to code the graph differently such that the 3 pieces of data per row are averaged together into 1 piece of data per row.
Saturday, September 1, 2012
Using Multi-Column Data with D3 Part 2
Okay, so after reading my previous tutorial we are now capable of loading in a CSV file with multi-column data and completely reconstructing it.
That's great! but... what about being able to categorize, filter, (somewhat) transition, and color the representation of that data? That's what this tutorial is all about! :)
That's great! but... what about being able to categorize, filter, (somewhat) transition, and color the representation of that data? That's what this tutorial is all about! :)
Labels:
array,
attribute,
categorize,
column,
CSV,
D3,
data,
filter,
JavaScript,
multi,
numeric,
transition,
values
Friday, August 17, 2012
Using Multi-Column Data with D3 Part 1
In my previous tutorial, I showed how to import data from a CSV file or a text file. However, oftentimes the type of data that you need to use has multiple columns, like so:
rather than being in a single column format, like this:
One common reason for having multi-column data is if all of the data can be split into categories and you need to visually show which category each piece of data is in, through colors, spacing, positioning, highlighting, font size, or etc.
In this tutorial, I'm just going to show you how to fully reconstruct the data by accessing it in memory, as it's not entirely the simplest thing for a beginner to do. Once we're able to access individual pieces of data, we'll be able to create multi-column/multi-category graphs, filter out certain categories of data, color them, etc.
Column 1 Title, Column 2 Title, Column 3 Title
1, 2, 3
4, 5, 6
rather than being in a single column format, like this:
1
2
3
4
5
6
One common reason for having multi-column data is if all of the data can be split into categories and you need to visually show which category each piece of data is in, through colors, spacing, positioning, highlighting, font size, or etc.
In this tutorial, I'm just going to show you how to fully reconstruct the data by accessing it in memory, as it's not entirely the simplest thing for a beginner to do. Once we're able to access individual pieces of data, we'll be able to create multi-column/multi-category graphs, filter out certain categories of data, color them, etc.
Labels:
array,
associative,
categorize,
column,
CSV,
D3,
data,
filter,
JavaScript,
multi,
multidimensional,
numeric,
values
Friday, May 25, 2012
Interacting with a MySQL Database Table in PHP
Now that you can create HTML forms and receive HTTP POST data and properly set up a table in a MySQL database, you are ready for the next step: interacting with this MySQL database through the use of an HTML form. All that's left for you to know and do is run MySQL queries from PHP code. Here's the script we're going to be looking at in this tutorial:
Subscribe to:
Posts (Atom)