Forum Topic: Programming Challenge #2

(452 views • 12 replies)

This topic is 1 page long.

<< < > >>
None

authorblues

Reply To Post Reply & Quote

Posted at: 9/3/07 12:37 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

heres how its gonna work, guys. there is only one choice for the language here: C++. No ANSI-C, no C#, no Java, no fucking Haskell. C++. your programs are going to accept input from the standard IO, and are going to output to the standard IO. i will then take your source code, compile it using g++, and do a pipelined input and output, such as:

g++ -c yoursource.cpp
g++ -o yourprogram yoursource.o
yourprogram < myinputfile.inp > anoutputfile.oup

if your output does not match my output EXACTLY, it is wrong. i am doing this in the same way that any programming competition judge would do it. you will not know what test cases are in my input file, and if your program is wrong, you will recieve nothing more from me than "wrong answer".

you will post your source code in its entirety to pastebin, or a similar site. i will take that source, copy it into a text file, and run it. do not post the link to your source in this thread, send it to me via PM. i will then post in THIS thread that attempt #N by X was accepted/rejected.

presentational errors will not be forgiven. if i ask for an output of "Hello World" and your program gives me "Hello world", it is wrong. without further ado, here comes...

Programming Challenge #2: sieve cycle

the sieve of eratosthenes is a common method of creating a naive list of prime numbers. a list is made of numbers is counted through, and an entry that is a multiple of a previous entry is discounted as a composite number.

you will be given two numbers, and it is your job to output these numbers, followed by the number of primes found between them, inclusively (meaning, including the endpoints). example input and output files can be found below.

if there are M primes between A and B, then an input of:
A B

will return
A B M

http://pastebin.ca/raw/680078
http://pastebin.ca/raw/680079

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 9/3/07 12:39 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

i really shouldnt be giving hints, but...
ASSUME NOTHING that isnt explicitly stated.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 9/3/07 01:06 PM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,418

But I don't LIKE C++! D:

Though I suppose it's a fresh experiance using it. It's not as bad as AS.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

elbekko

Reply To Post Reply & Quote

Posted at: 9/3/07 01:40 PM

elbekko EVIL LEVEL 16

Sign-Up: 07/23/04

Posts: 6,587

Hrmm, if I had the time to think this through, I'd give it a shot :D

"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

None

AcDiK-DR4G0N

Reply To Post Reply & Quote

Posted at: 9/3/07 01:46 PM

AcDiK-DR4G0N DARK LEVEL 19

Sign-Up: 01/31/06

Posts: 1,697

I'll give this a shot when I get home.


None

Ross

Reply To Post Reply & Quote

Posted at: 9/3/07 10:23 PM

Ross LIGHT LEVEL 13

Sign-Up: 12/15/99

Posts: 186

"Sieve of Eratosthenes" - now THERE'S a term I never thought I'd hear again. That was the focus of one of the first AP CompSci labs I made, for the class I taught. Did you see it in class, too?

Ross Snyder - PHP Juggler
If you find a problem on the website, send me a PM.


None

authorblues

Reply To Post Reply & Quote

Posted at: 9/3/07 11:08 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

At 9/3/07 10:23 PM, Ross wrote: "Sieve of Eratosthenes" - now THERE'S a term I never thought I'd hear again. That was the focus of one of the first AP CompSci labs I made, for the class I taught. Did you see it in class, too?

no. i mean, theyve mentioned it in classes before, but my main familiarity with it was when i was doing some numerical experiments on my own, and i was graphing the prime numbers polarly, and i used it to create a naive list of prime numbers.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 9/3/07 11:19 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

no takers, huh? i hope to see some submissions by tomorrow night. im kinda sad no one has written the 12 lines this program takes (seriously, really fucking easy)

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

whatthedeuce

Reply To Post Reply & Quote

Posted at: 9/4/07 02:08 AM

whatthedeuce NEUTRAL LEVEL 02

Sign-Up: 06/04/05

Posts: 491

At 9/3/07 11:19 PM, authorblues wrote: no takers, huh? i hope to see some submissions by tomorrow night. im kinda sad no one has written the 12 lines this program takes (seriously, really fucking easy)

Honestly, if you want to get more submissions, you should probably not restrict it to just c++. Challenges like this are a fun way to try out new languages and techniques. Personally, I would have submitted a solution if it weren't for the language restriction. It's just a few lines of code in Haskell (I've implemented the sieve of Eratosthenes in Haskell before, and it's very compact). I'm not very familiar with Haskell, and I like to code little things like this to get used to it. Because Haskell is such a radically different language, you can often think about the problem in a different way and come up with neat solutions.

It's really up to you if you want to add so many restrictions and be so strict, but that isn't a great way to have a fun challenge that people want to participate in.


None

authorblues

Reply To Post Reply & Quote

Posted at: 9/4/07 09:13 AM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

At 9/4/07 02:08 AM, whatthedeuce wrote: It's really up to you if you want to add so many restrictions and be so strict, but that isn't a great way to have a fun challenge that people want to participate in.

the restriction is because of my lack of other compilers, and unfamiliarity with pipelining input and output in any language other than c++. i dont have a problem letting people do it however they want, but i will have no way to use my test cases to give them a fair judgement.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

greenkube

Reply To Post Reply & Quote

Posted at: 9/4/07 11:46 AM

greenkube NEUTRAL LEVEL 12

Sign-Up: 10/24/05

Posts: 562

At 9/3/07 11:19 PM, authorblues wrote: no takers, huh? i hope to see some submissions by tomorrow night. im kinda sad no one has written the 12 lines this program takes (seriously, really fucking easy)

This might be why no one is participating. Just an assumption though.

BBS Signature

None

StrixVariaXIX

Reply To Post Reply & Quote

Posted at: 9/4/07 05:01 PM

StrixVariaXIX EVIL LEVEL 30

Sign-Up: 11/18/03

Posts: 152

So do you want us to use cin/cout or fstreams?

And if we're doing fstream, you want to specify the filename in the command line? If that's what we're doing, you can forget about me entering. If you want to use cin/cout (perhaps a good idea, since a lot of people are already being lazy), you can find my code at the pastbin linked below. I didn't bother looping.

http://pastebin.com/f463cd640


None

DarkRedemption

Reply To Post Reply & Quote

Posted at: 9/6/07 01:04 AM

DarkRedemption DARK LEVEL 05

Sign-Up: 07/21/07

Posts: 233

Aw, curses, had you said Java I would've been all over this one. D:

Ah well, at least I learned that that funny little method I made up a few years ago actually isn't original by a long shot...and has a pretty nice name, too.

:And he doesn't kid, this isn't exceptionally hard. I think.


All times are Eastern Standard Time (GMT -5) | Current Time: 08:33 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!