r/dailyprogrammer • u/Coder_d00d 1 3 • Jun 18 '14
[6/18/2014] Challenge #167 [Intermediate] Final Grades
[removed]
40
Upvotes
r/dailyprogrammer • u/Coder_d00d 1 3 • Jun 18 '14
[removed]
3
u/killedbythegrue Jun 18 '14 edited Jun 18 '14
Erlang,
I removed the spaces from the last names to make things easier on my self.
Output:
2
u/KillerCodeMonky Jun 18 '14 edited Jun 18 '14
PowerShell:
Usage:
Output:
3
u/Godspiral 3 3 Jun 18 '14 edited Jun 18 '14
in J,
g =. ;: each cutLF wd 'clippaste'
only 3 grades for zoolander
5
u/poeir Jun 18 '14 edited Jun 18 '14
Python solution with three possible outputs: HTML, Markdown, or console (using texttable). I wasn't able to figure out how to write a test for the decorator by itself, so I could use some help with that, even though the decorator is unnecessary in this case since it's only used once.
edit: In the previous version, it was specified to round up; now it specifies just round, so that's adjusted for
5
u/minikomi Jun 19 '14 edited Jun 19 '14
Racket.
Output:
7
u/skeeto -9 8 Jun 18 '14 edited Jun 18 '14
SQL, with a bit of Perl to massage the input. I'll be using SQLite's flavor of SQL to generate the report.
I created two tables with a many-to-one relationship to model the data.
students: lists all of the students without their scoresscores: lists all of the scores with a foreign key onstudentsFor simplicity, I'm assuming last names are unique so that I can use them as a primary key.
I also create a
totalsview on a [JOIN](http://en.wikipedia.org/wiki/Join_(SQL)) between these two tables. Joins are the bread and butter of relational databases. This view will look and feel just like a normal table, and it will always be up to date. Later on this will make queries involving averages much simpler because we can join with this view.I also create a table
gradesfor letter grades. I can join with this table in my report to get a letter grade column.Before I can make any use of the data, it must be converted into SQL INSERT statements. This Perl script will do that.
The output looks like this,
The tables are in place so now I can generate a report. This involves joining all of the tables above. A natural join means that when the column names match (
lastin this case) we can join wherever they hold equivalent values. To get a letter grade, I also join on thegradestable using<=and>operators to join on the correct grade letter.The output:
Unfortunately I'm still too much of a SQL newb to figure out how to list all of the scores in order in additional columns. There's probably some trick involving five left outer joins or something. I'm still working on that part.
This may seem a little bulky for such a small report, but it would scale up enormously well. After adding a few indexes in the right places, you could do all sorts of concurrent, fast queries in involving millions of students with thousands of scores each while safely making updates to the database at the same time.
1
u/poeir Jun 18 '14
I think there's an error in the problem description; it currently reads
However, the lower 3 percent of B would be [80, 81, 82], so 83% should be a B. That or it should be the lower 4 percent and either the lower 3 percent or lower 4 percent.
1
u/FTFYcent Jun 18 '14
Wait, do we need to handle malformed input ("Derek Zoolander" only has 3 grades) or is that a typo?
1
u/KillerCodeMonky Jun 18 '14
There is an error in the problem description:
The second example is not rounding up.
1
u/spfy Jun 18 '14
I cheated a little bit. The text file in the challenge was really frustrating, so I fixed it to suit my needs better. Like so:
It was pretty easy to get that text file into another Mongo database. My program that did that calculated the grade (rounding, etc). I won't include that, though.
Python 3 with MongoDB:
First few lines of output:
3
u/FerdErik Jun 18 '14 edited Jun 18 '14
Java 8 with lots of Streams, Lambdas, and RegEx.
Edit: Quickfix for names with spaces in them...
Output:
2
u/thestoicattack Jun 18 '14 edited Jun 18 '14
bash:
2
u/viciu88 Jun 18 '14 edited Jun 18 '14
My impementation in Java:
Input using regular expressions, Output using String formatting.
2
u/dreucifer Jun 18 '14 edited Jun 18 '14
Nice little python solution, nothing too fancy. Turned out quite readable. Edit: Whoops, forgot + and - grades. Edit2: Fixed.
and the output
2
u/salonabolic Jun 18 '14
C++. Didn't deal with double barreled last names - just removed the spaces!
2
u/lelarentaka Jun 18 '14 edited Jun 19 '14
Haven't seen Scala yet so I thought I'd give it a try. I'm not very good with pattern matching yet, so the letter grade part might by more verbose than it needed to be. I'm also still a beginner in regex.
Sample result. I got the formatting to be really nice by padding the names.
2
u/jnazario 2 0 Jun 20 '14
F#. did a tweak to the input to make it easier to split and parse using a regex. my exception handling leaves something to be desired.
output
2
u/darrellplank Jun 21 '14 edited Jun 21 '14
C#
Had me confused when the word "percentile" was used. In statistics, this means how many people you did better than so if you're in the 90'th percentile, you did better than 90% of the rest of the population. Here, percentile isn't really what is used but just a percentage of total grade.
1
u/Elite6809 1 1 Jun 18 '14 edited Jun 18 '14
The last record in the challenge input only has 3 grades; I'm going to assume this is a mistake and add 2 other results. Also, in the name inputs
Edwin Van ClefandJean Luc Picardhow should the program differentiate between the surnames and last names? I'll resolve that ambiguity by putting underscores in the names to join them for the input because otherwise it could be either.Anyway, here it is, in good old Ruby and some minor map-reduce abuse. It will right-align them all correctly using spaces.
Output: http://pastie.org/private/y4qrjlnngq6kupszwryd2w
1
u/Reverse_Skydiver 1 0 Jun 18 '14
My solution in Java. Deleted my previous comment as I changed the code to include + and - in the grades.
Output:
http://i.imgur.com/iaREi5V.png
1
u/Dutsj Jun 18 '14
Java 8. The style in which the entries were formatted was tougher than I thought, same with printing the output in a nicely formatted way.
Output:
1
u/kakaroto_BR Jun 18 '14
Solution in Java:
1
u/rcxdude Jun 18 '14 edited Jun 18 '14
Rust (rustc 0.11.0-pre (e55f64f 2014-06-09 01:11:58 -0700)):
Example output:
1
u/BryghtShadow Jun 18 '14
Python 3.4 and 2.7
The sample output is inconsistent, as caught by my testcase. Surely this is a typo?
Input:
Output:
1
u/dancole42 Jun 19 '14 edited Jun 19 '14
Python 2.7.6
I'm self-taught and new, so feedback is extremely appreciated.
ETA sample output and fixed the +/- cutoffs.
Output
1
u/fvandepitte 0 0 Jun 19 '14
C# later today i'll try to submit an C++ version
1
u/uprightHippie Jun 19 '14
Here is my submission in C#. This is the first time I'd ever used params, I was looking for a Regex that would collect any number of grades instead of just 5, so any comments there would be most appreciated.
Here is the main program:
Here is the Student Class:
Here is the output:
Thanks!
1
u/JMan_Z Jun 19 '14 edited Jun 19 '14
1
u/demon_ix 1 0 Jun 19 '14
Java 8. My student parsing is pretty horrible. Edit - Just noticed that because of my sort comparator, Casper the ghost appeared before Woz. Gah.
Outputs:
1
u/_M1nistry Jun 19 '14
C#. Didn't read the Output section properly/didn't plan. So it doesn't order by best-> worst. Not the nicest code but... it's 3am and /bothered. Requires a text file with the input in it at the directory named 'Students.txt'
1
u/[deleted] Jun 19 '14 edited Jun 19 '14
I know I'm probably annoying the shit out of you guys every time I post, but I am new to programming. Started with Java last September. I've been learning python over the past month. Please, please, PLEASE! point out any mistakes or bad practices in my code.
Python 2.7.7:
Inputted text file:
Output:
P.S. Those two name people like Bo Bob and van Clef really screwed me up! Hahaha.
1
u/99AFCC Jun 19 '14
Dangerous Python 2
Output:
1
u/MrP_123 Jun 19 '14
My answer in Java. Feedback is always welcome. I have to be honest, I partly used the methode of using a pattern to generate my students from another reply.
1
u/[deleted] Jun 19 '14
Late to the party. Python 2.7*
Here is the output:
1
u/gregbair Jun 19 '14
C#:
First, load the file into a string array and build a pattern for parsing the lines:
Iterate through the lines and build a Student object to hold all the info:
Then iterate through, outputting the different values:
The Student class has methods for determining the percentage and letter grade (expanded for clarity):
setFinalPercentage:
setLetterGrade (I'm sure there's an more elegant/easier way to do this):
GradesInOrder:
1
u/harrychin2 Jun 19 '14 edited Jun 20 '14
My C++ solution
I decided to call all of the relevant Student class methods in the constructor.
1
u/OnceAndForever Jun 20 '14
Lua 5.2
Usage:
Output:
I feel like there should be a more concise way of solving this using metatables and closures, but I don't really see how. Any tips would be appreciated!
1
u/joeyGibson Jun 20 '14
Here's my solution in Clojure. There is absolutely no error handling, so a proper input file is assumed.
Edit: To see a colorized version, view it at Github. It's much prettier in color.
And here's the output
1
u/Mezput Jun 20 '14
This is my first submission on DailyProgrammer. I made my solution in Java. However, as I am new to Java programming, all feedback is very welcomed.
My solution consists of two classes, CS101Class and Student. The first one is responsible for parsing an input file, managing a list of students and determining their grades. The Student class is simply responsible for storing/printing the information of a single student.
Solution
1
u/grendus Jun 20 '14 edited Jun 20 '14
Python 3.4.1. List comprehensions and lambda functions make manipulating data sets like this a breeze.
Sample output:
1
u/-AMD- Jun 21 '14
Python solution:
Assuming that class roster will be given in text file roster.txt in the same directory.
Assuming that class roster will be given in text file roster.txt in the same directory.
1
u/CodeMonkey01 Jun 21 '14
In Java:
Output:
1
u/amu05 Jun 21 '14 edited Jun 21 '14
C++, im a beginner so im sorry if my code stinks. Im just trying to practice here :)
1
u/flugamababoo Jun 21 '14 edited Jun 21 '14
Python 3.4:
output:
1
u/brugaltheelder Jun 21 '14 edited Jun 21 '14
Python. I replace the two name first and lasts with underscored names to make it easier on me. I'm trying to work on being more pythonic.
Output:
1
u/defregga Jun 24 '14
Solution in Python 2.7. Experience is about 30h spent on Python, ~160h overall; mostly C(++). Moved on from Easy #168 after revising my solution there. Feedback will be much appreciated.
Code:
Output:
1
u/[deleted] Jun 25 '14 edited Jun 25 '14
Solution in Python 2.7. Kept it very simple without functions or classes:
Here's the output:
1
u/mdlcm Jun 25 '14
I used R for this challenge.
Code:
Output
1
u/jeaton Jun 25 '14 edited Jun 25 '14
JavaScript:
Output -> http://i.imgur.com/n5lxDYI.png
1
u/kuzux 0 0 Jun 26 '14
Haskell:
1
u/eviIemons Jun 27 '14 edited Jun 27 '14
ruby
takes one file as argument and prints it (formatted) to the console
1
u/VerifiedMyEmail Jun 28 '14
Works as expected. Python 3.3
1
u/nalexander50 Jul 01 '14
Here is my solution in Python 3.3. It is not very format dependent, either! Any feedback is welcome as always.
Here is the Output.txt: http://pastebin.com/xZ4WPa6n
1
u/dp_account Jul 04 '14
Python3.4
Challenge Output:
1
u/im_not_afraid Jul 13 '14 edited Jul 13 '14
Haskell with Control.Error, Text.Printf and Text.Parsec
Output:
1
u/p44v9n Aug 01 '14
My scala solution. I added an entry to ensure percentages all lined up (presuming no one gets 100% but some may get <10%).
Comments and crits and suggestions welcome!
Lots of slicing and splitting and things that make me feel like I should learn regex.
After finishing this I read a stackoverflow answer which made me realise scala has lexicographic ordering so you can just do this at the end
1
u/[deleted] Aug 03 '14
Python 3.4
Output:
As you can see.
1
u/tally_in_da_houise Aug 13 '14
Late to the game Python 2.7 implementation:
Code: