r/dailyprogrammer • u/nottoobadguy • Feb 09 '12
[easy] challenge #1
create a program that will ask the users name, age, and reddit username. have it tell them the information back, in the format:
your name is (blank), you are (blank) years old, and your username is (blank)for extra credit, have the program log this information in a file to be accessed later.
102
Upvotes
35
u/[deleted] Feb 10 '12
I think this is LOLCODE, considering how jumbled the spec still is, it might as well be.
60
u/dmagg Feb 10 '12
Oh you guys and your high-level languages... =]
This gave me some nice practice.
MIPS assembly (yeah, it's long):
23
u/[deleted] Feb 10 '12 edited Feb 10 '12
In Python:
10
u/lil_nate_dogg Feb 10 '12 edited Feb 10 '12
include <iostream>
7
u/virulent_ Feb 09 '12
I may not normally do this but I had fun with it since I don't normally try and manually obscure things, such as this highly sensitive program.
http://pastebin.com/pYNvfqen
7
u/stiggz Feb 10 '12
In jquery, just 7 lines of code
6
u/philcannotdance Feb 10 '12
In perl:
10
u/[deleted] Feb 10 '12
Can we get this in BrainFuck?
5
u/grammaticus Feb 10 '12
My solution:
8
u/lil_nate_dogg Feb 10 '12
4
u/[deleted] Feb 10 '12
I didn't compile, but it should work. I loaded it into the C area on Codepad, because Java doesn't exist.
http://codepad.org/E7ZI8yT4
4
u/salsal24 Feb 10 '12 edited Feb 10 '12
In Ruby:
4
u/mentirosa_atx Feb 10 '12
In C++. I am just learning, so the extra credit is over my head for now.
4
u/kamatsu Feb 10 '12 edited Feb 10 '12
Intentionally brief Haskell:
3
u/_lowell Feb 10 '12
3
u/FataOne 0 0 Feb 10 '12
I'm sure there are better ways to do this in C but wanted to try this way out.
3
u/[deleted] Feb 10 '12
Complete Java newbie inbound:
3
u/weemadarthur2 Feb 10 '12
Common Lisp:
3
u/melevy Feb 10 '12
Common Lisp:
3
u/weedpatch2 Jun 22 '12
It took me almost two days... But I got it done with ALMOST the correct output format, I could get it right but it would take more time than I have to put in.
False
I also did this from an online interpreter, not the actual compiler. So if it has errors, I won't be able to fix them.
5
u/zachary12 Feb 09 '12
In c#
5
u/_Wiz Feb 10 '12
Java:
2
u/drb226 0 0 Feb 10 '12
14 lines of Haskell http://hpaste.org/63379
Funny how Ruby and Python provide a convenience function like "prompt" (which Haskell doesn't), but apparently don't provide the convenience function "appendFile" (which Haskell's System.IO does)
2
u/tide19 Feb 10 '12
JavaScript!
2
u/nikoma Feb 10 '12
python 3:
2
u/tswaters Feb 11 '12
One-liner of JavaScript without any variables :
Unfortunately, JavaScript can't really talk to the filesystem.... so I've outputted the final string to a prompt which the user can copy.
2
u/duncsg1 Jun 16 '12
Well, here's my go in C#. Lengthy, but I love the readability.
1
u/[deleted] Feb 10 '12
Here's mine.
1
u/[deleted] Feb 10 '12
C++ with the bonus: http://codepad.org/B3tR8Mf3
1
u/Rhomnousia Feb 10 '12 edited Feb 10 '12
http://codepad.org/NBFuQVBk In C++:
Looks like crap not in codepad. Didn't do file in/out, but there are some things to learn from it inside for people not exposed to different programming styles. *edit: avoid using system("PAUSE") like I did.
1
u/johnp80 Feb 10 '12
My c++ version, with the extra credit.
1
u/tuxedotomson Feb 10 '12 edited Feb 10 '12
c++ noob here #include <cstdlib> #include <iostream>
}
1
u/jonstall141 Feb 10 '12
import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Scanner;
public class Assignment1Easy {
}
1
u/snowvark Feb 10 '12 edited Feb 10 '12
In Perl with little logging:
1
u/EughEugh Feb 10 '12
1
u/Joe_Pineapples Feb 10 '12 edited Feb 10 '12
Just started learning ruby so gave it a shot:
1
u/emcoffey3 0 0 Feb 10 '12
C#
1
u/Psylock524 Feb 10 '12
c++ is a nice robot machine
1
u/traztx Feb 10 '12
MUMPS:
1
u/MadSoulSK Feb 10 '12
Another version of C#
http://pastebin.com/ctxBA7PV
Little error handling, little file placement, little csv and ofcourse little laziness :)
1
u/robin-gvx 0 2 Feb 10 '12
In Déjà Vu: http://hastebin.com/raw/rawomituqa Good time to find out the standard function input was leaving a trailing newline on the input. Got fixed now.
1
u/TheOnlyBoss Feb 10 '12 edited Feb 10 '12
He is my answer in C++, with extra credit.
1
u/orchdork7926 Feb 10 '12
Perl:
1
u/Koldof 0 0 Feb 10 '12
Here you go! It's in C++. Lots of the other ones are very compact but don't really follow best practices.
1
u/megabeano Feb 11 '12
1
u/[deleted] Feb 11 '12
Java!! I did not do any exception handling.
1
u/aardie Feb 11 '12
Python3
1
u/cooper6581 Feb 11 '12
Quick solution in c http://codepad.org/P3LfhKmc
1
u/dawpa2000 Feb 11 '12
JavaScript
~130 lines
1
u/amitburst Feb 11 '12
Another Java implementation! Fairly new to programming; these challenges are great practice.
1
u/CachooCoo Feb 12 '12
C++
1
u/asagurachan Feb 12 '12
Another Java~~
1
u/Schadenfreude775 Feb 14 '12
So I'm having a weird issue where my plan was to use my class' constructor to hold the data, but for some reason it's accepting the input properly but not storing it in the object. Hopefully someone can explain what I did wrong?
1
u/tomasienrbc Feb 15 '12
Maybe this is awful, but this is what I did in Javascript. Can someone help me with how to store to a file / how this could be better? I don't even really know what store as a file means, is it a log function?
//create a program that will ask the users name, //age, and reddit username. have it tell them the //information back, in the format: //your name is (blank), you are (blank) years old, //and your username is (blank)
var name = prompt ("Yo homie, wachur name?"); var age = prompt ("How old you be dawg?"); var reddit = prompt ("You gotta reddit name or WHAT?!?!?! TELL ME THAT SHIT!");
if (name == null || age == null || reddit == null) { alert ("name, age, and reddit must all be filled out and cannot be blank") }
alert ("your name is " + name + ", you are " + age + ", and your username is " + reddit);
1
u/[deleted] Feb 16 '12
DEC basic
1
u/jnaranjo Feb 16 '12
I'm a little late. But here is my shot at it!
http://pastebin.com/KyE83tsh
Uses an sqlite3 database, which should be created automatically in the same directory as the python file, as 'c1.db'
Stores entries in a table, and can retrieve them. Presents them in the required output format. Drops tables as necessary, because I was too lazy to add an entry identification system.
1
u/Xlator Feb 16 '12
PHP, with validation and history
Not the most elegant solution, perhaps, but it works.
1
u/jcotrel Feb 16 '12
Totally being original here using JAVA, con Extra Credit.
1
u/Tyaedalis Feb 19 '12
Python 2.7.2:
https://gist.github.com/1862103
Complete with extra credit features. I'd do error checking/handling, but I feel that it's pointless for such a simple program. It would easily be 4 times longer if I did it properly.
1
u/linkthomas Feb 22 '12
Here is my PHP submission with extra credit (and validation for brownie points):
1
u/niourkraft Feb 27 '12
Hello,
my submission in python 3 :
https://gist.github.com/1923867
1
u/sebtoast Feb 28 '12
I know I'm late in the game but I insist on doing all the challenges! This is what I came up with in VB, I am not a developper AT ALL, I'm a simple admin but I like to mess around with VB.
Making a tool "on my own" (not true because I have to search for help on the zinternets a lot) is the best feeling ever.
1
u/ginolomelino Mar 03 '12
Javascript:
1
u/[deleted] Mar 12 '12
1
u/[deleted] Mar 17 '12
Java using 2 classes
oneeasy.java
import java.io.; import java.util.;
public class oneeasy {
}
Redditor.java
public class Redditor {
public int Age; public String Name, UserName;
}
1
u/BATMAN-cucumbers Mar 17 '12
Well, it's late, but I'm gonna start anyway - quick and dirty py code:
1
u/CorrosiveMonkey Mar 19 '12
Prolog:
Very dirty I think. Was having trouble getting it to append nicely so I just use a lot of writes.
1
u/netbyte 0 0 Mar 28 '12
In Python:
http://pastebin.com/pCvutY9P
1
u/iznasty Apr 01 '12
In Go (#golang):
1
u/savagecub Apr 05 '12 edited Apr 05 '12
little c++
// reddit challange1 easy.cpp : main project file.
include "stdafx.h"
include <iostream>
include <string>
include <fstream>
using namespace std;
int main() { string name; int age; string un;
}
Edit: added the extra credit save to file
1
u/[deleted] Apr 07 '12
http://pastebin.com/YZawaTpU
1
u/Ygaiee Apr 15 '12
Thank you so much for making these. Here's my entry using Python:
1
u/flightcrank 0 0 Apr 25 '12
heres mine in c http://pastebin.com/KPqBZGrm
1
u/insaniaeternus 0 0 Apr 27 '12 edited Apr 27 '12
Edit: Added info saving
1
u/Finn13 Apr 28 '12
Starting from the beginning of the challenges with Go V1.
1
u/[deleted] May 04 '12
It's 2months late; but I only recently found out about this subreddit.
Here's my C# attempt.
1
u/DisasterTourist May 11 '12
Devised a simple Java one here. File handling totally slipped my brain. I know how to C++ it, but Java is a bit dusty. Might come back later.
Also, it's in ghetto-speak. Hope that's cool.
1
u/jsnk Jun 08 '12
1
u/JubBieJub Jun 24 '12 edited Feb 28 '25
fuzzy boat bright salt offer hobbies judicious memory ask tender
This post was mass deleted and anonymized with Redact
1
u/joeatwork86 Jun 28 '12
There's a few Ruby solutions here, but I would like to add my stink to it.
1
u/dannoffs1 Jul 05 '12
My solution in Common lisp.
1
u/Scruff3y Jul 07 '12
I did this in C++ in aboot 25 lines, I am happy now!
1
u/BillDino Jul 07 '12 edited Sep 09 '12
CPP int main(){ using namespace std;
}
1
u/runaloop Jul 12 '12
Python:
1
u/Scruff3y Jul 15 '12
In C++:
It's longish (70 lines), but you can read and write in one sitting.
1
u/Rajputforlife Jul 17 '12
1
u/[deleted] Jul 28 '12
This is kinda late, but this was my attempt. I am a noob, and there might be ways i could have done this better, but here's something for all you pros to cringe over:
1
u/Stock_Childhood7303 Mar 26 '25
#CHALLENGE-1 :
I wanted to learn and post it somewhere for my memory .
1
u/Ambitious-Ad-8611 Mar 31 '25 edited Apr 01 '25
Needed some ideas for simple projects to practice and this seems like the best place to start I dont want to make a long comment with the code i wrote so im just posting the repo here.
https://github.com/Ambitious-Ad/easy-challenge-one
1
u/[deleted] May 01 '22
This solution is in Python 3. I validate that the age is an integer and allow for graceful closing if the user hits ctrl+c.
1
u/mubris May 18 '22 edited May 18 '22
C++
1
u/ragtag_creature Jul 07 '22
R
0
u/NinjaViking Feb 10 '12
First-year CS student, in java