r/dailyprogrammer • u/Coder_d00d 1 3 • Jun 23 '14
[6/23/2014] Challenge #168 [Easy] Final Grades - Test Data
Description:
Last week we had [[6/18/2014] Challenge #167 [Intermediate] Final Grades] (http://www.reddit.com/r/dailyprogrammer/comments/28gq9b/6182014_challenge_167_intermediate_final_grades/)
For this challenge I generated data using excel. It was a bit time consuming but for the limited data set it was not too bad. But what if we needed 100 students? Or 1000? Or even 10000?
Sometimes it is useful to use programs to generate test data to test programs. For today's challenge your task is to generate the test data for that challenge.
Input:
- n -- representing how many random student records to generate
Let us assume N will always be a positive number and I will let you decide what upper bound if any you want to set.
I would recommend running your solution on 1, 10, 100, 1000, 10000. Maybe post a sampling of 10 to show what you can generate.
Output:
Should be a listing either via console out or a text file or other of your choice that is the test data. To remind you what a record looks like:
- (first name) , (last name) (score 1) (score 2) (score 3) (score 4) (score 5)
For example of a student roster see the [Intermediate] (http://www.reddit.com/r/dailyprogrammer/comments/28gq9b/6182014_challenge_167_intermediate_final_grades/) challenge's input
Data:
To generate this data you will need to find a way to generate random first and last names and 5 scores (between 0 to 100)
Optional:
Check your output and look for duplicate first and last names generated and remove the duplicates. It is up to you to decide how to do this.
Example would be if you generated "John , Smith" two times you would want to take action.
Also keep in mind the larger N values could more likely create duplicates. Consider a "give up" logic where you attempt to be unique but at some point have to accept that there will be some duplicates.
3
u/Coder_d00d 1 3 Jun 23 '14
C
10
u/dancole42 Jun 23 '14
For the student names I made a Language class that generates super simple languages from basic phonology rules.
Python 2.7
Still very new and self-taught. Since I'm self-taught I probably miss a lot of convention and I'm always looking for better ways to do things.
Sample Output
4
u/snarf2888 Jun 23 '14
C. Used the API at http://api.randomuser.me to generate random student names. Used rand() for their scores. I made it generate a random grade between 50 and 100 for more realistic scores.
Compile with:
Sample output:
Code:
1
u/sole_wolf Dec 03 '14 edited Dec 03 '14
Kind of really late but here's my RandomAPI source code for the problem. just search for "Reddit Challenge #168" by "Keith" on the site if you want the source and lists yourself.
Generates output that looks like this if called in CSV format
first,last,score_1,score_2,score_3,score_4,score_5 Carla,Carr,86,94,72,46,20 Sally,Daniels,26,22,90,54,25 Rafael,Kelley,93,77,48,85,66 Julie,Moore,11,74,15,25,67 Bobby,Ortiz,84,96,38,43,92 Tyler,Reed,80,67,51,19,73 Jean,Green,95,17,92,36,18 Lonnie,White,55,13,20,48,84 Irma,Peters,100,35,15,32,43 Zoe,Hernandez,19,84,67,19,43
Edit: fixed url
3
u/lelarentaka Jun 23 '14 edited Jun 23 '14
The bottleneck seems to be network IO (obviously), as it downloads the list of names everytime. After that, generating even 100,000 rows is very fast.
Sample output
4
u/Godspiral 3 3 Jun 23 '14
my original solution ommitted commas, so this generator does as well:
in J
g=: <"1 ;: ((":@:,.@i.) ('F',.[ ,. ' ' ,. 'L' ,. [ ,. ' ' ,. ]) [:": 40 + [: ? 60 $~ 5,~ ])10
2
u/demon_ix 1 0 Jun 23 '14 edited Jun 23 '14
Java. Probably inefficient as fuck, due to the randoms and the duplicate name checks, plus at really large amounts it's going to stall due to lack of original names (80k last names and about 5.5k firsts). I used the name lists found here.
As always, suggestions of ways to improve are welcome.
Sample output with 20 students and 5 grades each:
Edit: Up to 1m students, it ran find in seconds. At 10m it hung. Surprised me, since it should only be able to generate ~440k unique names. Guess I have a bug in there.
Re-edit: Scrap that. Should be 440m, not 440k. It shouldn't really hang at 10m, since at most, the probability of landing on a taken name should be around 1/44 ~ 2%. Maybe it's a memory thing?
2
u/dailyRubyProgrammer Jun 23 '14
My solution in Ruby. Please comment and suggest!
I offloaded the randomizing to randomuser.me and just massaged the JSON, so I'm not sure if it's that valid... I'm sure there will be duplicate collisions at some point around, but not sure when since I don't know the source pool for the API. It was a good workout though! Definitely feeling more comfortable with maps and enumerables.
forgot the output!
2
u/parrotjay Jun 24 '14
final_grades_generator.rb
I'm pretty new to both ruby and coding in general, so any suggestions or criticism would be useful. In particular, there were over 5000 names in my names list, and i'm wondering if, with that size, there's a better way to pick a random name than sticking them all in an array. Thanks in advance!!
and sample output:
2
u/dmv1975 Jun 25 '14
Python 2.7
I downloaded lists of boys and girls and last names from u.s. census data and manipulated the garbage out of them to create lists that I could pick from randomly. I know there must be better ways to get rid of the extra crap you don't need, but I haven't learned it yet. I got the lists of names from here:
https://www.census.gov/genealogy/www/data/1990surnames/names_files.html
You know what would be really neat? If I learned how to scrape the names from the website without downloading the files and opening them from my hard drive. That would be the bomb. Anyway, I alternated between girl and boy names and made a list 10K names long, then wrote it to output.txt.
And here is a sample output of the first 20 lines of output.txt:
1
u/[deleted] Jun 23 '14 edited Jun 23 '14
So, once again, I'm new to programming, and especially new to the Python programming language. Please critique and give me suggestions on what I could do better.
For the names, I found a US Census document from 1990 that contained most first and last names from that year's census. I reformatted those documents for this problem. Here they are if you want them: last names first names
Output with an input of 10:
1
u/-AMD- Jun 23 '14
My Python 2.7 solution. Got first and last names from files at http://www.census.gov/ site, formatted to fit my problem.
1
u/grendus Jun 23 '14 edited Jun 23 '14
Python 3.4. You can pass in as many lists as you want, it will use the final list for last names and choose randomly among the prior lists for first names. This could be used to weight names (so common names show up more often than uncommon names) or just to pass in multiple disjoint lists.
output:
1
u/spfy Jun 23 '14
Python3. Pretty simple solution, but I think it's nice. Didn't do the optional part, though.
Here's a sample of 10. I created two really short text files to do this:
1
u/poeir Jun 23 '14 edited Jun 23 '14
This takes two command line arguments, one of a file of first names (a good source is this list of top 100 baby names for each gender), one of a file of last names (a good source is this list of most common surnames). First scores are normally distributed for a seed score, then the following scores are moved a random (normally-distributed) amount. This is done to simulate that it's rare for grades to jump either direction. It supports a lot of command-line parameters.
1
u/GlassAndOneHalf Jun 23 '14 edited Jun 24 '14
Here's my solution using Scala 2.11 complete with the optional task. Any feedback, positive or negative, would be greatly appreciated!
Here is the result of running the program with an input of 20:
1
u/BryghtShadow Jun 23 '14 edited Jun 23 '14
Python 3.4
Output with N = 10:
Edit: I misunderstood the challenge. Previous code allowed for duplicate names. Of course this is bad without student ID.
1
u/defregga Jun 23 '14 edited Jun 23 '14
First time contributor. Solution in Python 2.7 and feedback will be greatly appreciated. Background: did a few C for Dummies books before "Learn Python The Hard Way" and the "Google Python Class". I am bad at commenting my code, couldn't come up with any sensible functions or classes for this one and felt like I didn't remember anything from the 2 aforementioned Python tutorials. :(
Here's a sample output of 10 entries:
Here's the source code:
1
u/jjj5311 Jun 23 '14
Python 2.7
Sample Output
1
u/RustyPeach Jun 23 '14 edited Jun 23 '14
My submission in swift, formatting is probably off on this comment though
EDIT: I dont know how to format code so here it is on github : https://github.com/RustyRadio/-6-23-2014--Challenge--168--Easy--Final-Grades---Test-Data/blob/master/MyPlayground.playground/section-1.swift
1
u/Deathbyceiling Jun 23 '14
My solution in Javascript. Still kinda new at this but here goes (sorry OP I took your names :P):
Output:
1
u/cooper6581 Jun 24 '14 edited Jun 24 '14
Java: Data for the names came from that 1990 census data
1
u/jnazario 2 0 Jun 24 '14 edited Jun 24 '14
F#
oh and once compiled, here is the output:
1
u/Reverse_Skydiver 1 0 Jun 24 '14
A simple solution in Java that outputs 500 unique students.
Sample:
1
u/Frigguggi 0 1 Jun 24 '14 edited Jun 24 '14
Java. My actual code contains much longer hard-coded lists of names, but reddit got mad when I tried to put it all in, so this is abbreviated. With the full lists, it works well with n = 10000, though it got stuck when I tried 100000:
Output:
1
u/99AFCC Jun 24 '14
Dirty python 2.7
1
u/Okawi Jun 24 '14
Submission in Java
Output example :
1
u/Meshiest Jun 24 '14
Got my name lists from a census website, then generated grades so they could get better/worse over time.
It takes a second to run because it has to download the list of names each time
Ruby (Takes ARGV for number of students)
Sample Output
1
u/mortenaa Jun 24 '14 edited Jun 24 '14
My solution is my first try at programming in Dart. Got the name lists from here: https://www.census.gov/genealogy/www/data/1990surnames/names_files.html
Decided to make the random name generator an iterator, which might not have been a good idea, but makes it possible to use a simple for loop in the main function.
Also, instead of drawing names at random from the lists, I shuffle them, and iterate from the start. Then reshuffle when I reach the end.
Takes the n argument on the command line.
Example output:
1
u/nyrol Jun 24 '14 edited Jun 24 '14
My submission in Swift. I used the same census files as everyone else.
Sample:
1
u/uilt Jun 24 '14
A little late, but I'm learning Julia right now so here's the Julia version (with my own name generator!). Don't know if anybody else here is interested in Julia, though.
Julia 0.3.0
Sample output
command: ./studentrecords.jl -n 13
1
u/[deleted] Jun 24 '14 edited Jun 25 '14
I found a mention of this Subreddit in stackoverflow and just had to join. I'm mainly a Pythonista (not an expert mind you) but looking to learn other languages as well. My handle was generated by the construct_random_name function below too. Anyway, here it is in Python 2.7:
For the Optional challenge, I created the construct_unique_results function which only produces unique names. Feedback welcome!
Here's the output:
1
u/coneillcodes Jun 25 '14
First submission, something I just threw together at the end of work. names aren't pretty.
1
u/joeyGibson Jun 25 '14
Here's my solution in Clojure. I used files of names (last names, male first names, and female first names) that I got from the US Social Security Administration. I also used some cool infinite, lazy sequences. Pretty-printed source and the resource files can be found at https://github.com/joeygibson/dailyprogrammer
And here's the output:
1
u/Komorebi Jun 25 '14
My submission in Python 2.7.
New to Python, coming from C and Java background. Trying to learn things the "Pythonic" way. Any comments appreciated. Thanks.
Sample Output:
1
u/mdlcm Jun 25 '14
I used R to write the program. Instead of generating full names, I used first name and last name initials to simplify the task as my first attempt. I also allow two decimal digits for the scores.
Once the function is run, below is the sample input
Sample output
This is a very crude results in a matrix format. We can beautify it by storing the "data.sample" as a data frame and renaming the variables.
For example:
Then, the sample output would be
1
u/towbes Jun 25 '14 edited Jun 25 '14
Ruby (I'm a noob I don't know what version, 2.1 maybe?)
I come from a C++ / Java background so some of my style might be non ruby-esque, i tried to ruby where I could though. I did not put the duplicate check in. Code currently just outputs to console. I generated the names off namegenerator.com, then wrote a quick script to split them into separate files firstNames and lastNames, properly formatted so I could just copy paste to an array for this program.
And sample output:
1
u/ThalesX Jun 25 '14
My submission in Python 2.7... I kinda cheated though:
Sample output:
1
u/thinksInCode Jun 26 '14
My first attempt at a Groovy script. Grabs random names from randomuser.me.
1
u/TiZ_EX1 Jun 26 '14
Vala. I feel like I did things kind of weird, and probably could have designed everything better. Compile with gee and gio. Comments and criticisms, please and thank you. :)
My first.txt and last.txt are just names of Tales series' lead males and lead females.
1
u/SHEePYTaGGeRNeP Jun 26 '14
C# http://pastebin.com/VQ7b5uUN
First time doing a challenge :)
Let me know if I did something wrong.
1
u/FatShack Jun 26 '14
Super amateur programmer here, trying to re-gain a little bit of skills. Python 2.7.
1
u/Daige Jun 26 '14
Lua 5.2
It takes a whole dictionary (from an earlier challenge) for generating names from, so my names are only slightly strange.
Only been learning Lua as I go this week to play with the Love game engine so any tips on Lua would be greatly appreciated.
The output didn't like large strings so first and last name are on seperate lines.
Sample output
1
u/mm865 Jun 26 '14 edited Jun 27 '14
Python 2.7 solution, takes 255 seconds to do 1 million on my system (to give that some context, Antinode_'s Java solution did it in 98 seconds on my system) Python really is just pseudo-code...
EDIT: formatting
1
u/marcelliru Jun 26 '14 edited Jun 26 '14
Using racket. Non-existing names are formed using simple letter combinations. I enjoy every comment and criticism! I am a beginner in programming, on my own.
Output:
1
u/[deleted] Jun 27 '14 edited Mar 08 '24
Reddit Wants to Get Paid for Helping to Teach Big A.I. Systems The internet site has long been a forum for discussion on a huge variety of topics, and companies like Google and OpenAI have been using it in their A.I. projects. "The Reddit corpus of data is really valuable," Steve Huffman, founder and chief executive of Reddit, said in an interview. "But we don’t need to give all of that value to some of the largest companies in the world for free."
1
u/kuzux 0 0 Jun 28 '14
Wrote in Haskell, uses randomuser.me to generate names
Sample Output:
1
u/dp_account Jul 01 '14
Python3. I used a Markov Chain to generate random names, which I trained from http://www.quietaffiliate.com/Files/CSV_Database_of_First_Names.csv. I used the same database for first and last names, but it would be easy to make a separate Markov Chain based on a list of last names.
Sample Output:
1
u/nalexander50 Jul 01 '14
Here is my solution in Python 3.3. I used randomuser.me to generate the names. This was a lot of fun because this is my first time ever making calls to an API and actually programming with JSON objects. I have written JSON objects for some projects, but never used them in a project. So here is my code. Feedback is always appreciated.
And here is the output: http://pastebin.com/D3HQnPAJ
And here is the output after running my script from [6/18/2014] Challenge #167 [Intermediate] Final Grades just for giggles: http://pastebin.com/vpPy8u3F
The students aren't very good, haha!
1
u/mvolling Jul 01 '14 edited Jul 01 '14
This is my first time commenting on this subreddit.
This program was done in C++. It was my first time using templates, classes, and overloads and as this was a learning exercise for me, some of the functions aren't used. Please give feedback on what you feel I did wrong.
I got the names lists from https://www.census.gov/genealogy/www/data/1990surnames/names_files.html
Code
Sample of the output
edit: Removed #include <istream> as it wasn't doing anything. It was leftover from a previous test.
1
u/janibus75 Jul 04 '14
I made a little script in VBA. I went the easiest way possible with pre-generated names (in the same file) and with hard-coded cells to put the results in. It works, though :)
Before generating and filling in the names / grades the script deletes the content of the formerly filled cells.
I can provide the file if someone is interested.
1
u/[deleted] Jul 21 '14
C# Here is the main code.
I used visual studio 2013 express to create it.
I didn't list the xaml for the window but it was essentially 1 large text box for the data output, 1 small textbox to specify how many lines you needed, and the generate button.
The code above is what happens when generate is clicked. What basically happens is it picks a random prefix, a random first name, a random last name, then 5 random scores of 0-99.
After that it adds them all to a string variable and then appends them to the large textbox named output.
I went for simple, quick, "get it done" with this challenge. I didn't account for input validation to make sure the user puts in a number. I didn't account for the possibility of the user asking for a number beyond the scope of an int. And I didn't do any real error handling. This was thrown together to get the minimal of the requirements for the challenge since I'm using these to sort of refresh my memory.
Ms. Rikku, Crestbreath, 27, 55, 41, 47, 14
Sir.Rikku, Lightcloud, 10, 82, 75, 10, 55
Ms. Joe, Lightningeyes, 0, 2, 84, 18, 15
Sir.Barret, Crestbreath, 12, 16, 65, 37, 38
Ms. Barret, Lightcloud, 17, 87, 84, 26, 26
Dr. Zell, Fistpunch, 17, 7, 13, 41, 90
Mr. Rikku, Lightcloud, 71, 43, 68, 92, 62
Mr. Barret, Fistpunch, 17, 43, 34, 98, 82
Sir.Rikku, Crestbreath, 6, 47, 92, 68, 82
Dr. Squall, Lockheart, 89, 17, 1, 8, 4
1
u/Davess1 Jul 23 '14
Clojure
1
u/[deleted] Aug 24 '14
Python 2.7:
Output:
1
u/kurtlocker Sep 16 '14
JavaScript. Found this sub and am falling in love. Obviously this is late; just trying to do as many easy challenges as I can. This one uses the mentioned api.randomuser.me library with some vanilla JavaScript to parse the returned JSON, print random scores between 50-100 and recursively call the function based on how many students you want.