Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Ten Lines or Less!

case sensitive

  • Please log in to reply
26 replies to this topic

#13 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 August 2009 - 09:52 AM

Well well, then I need to up the ante, eh? Alright, here's the next 10 Lines challenge:

The Challenge:

Create a program that takes in a variable amount of user input, on the command line. It should take in at least two arguments, the first being a file name, and the rest being numbers. The amount of numbers define the number of dimensions in an n-dimensional dynamic array, and each number signifies how big that dynamically allocated array is to be. Each bottom array should then be filled with random numbers. As an example, if the user inputs this:
progname myfile.txt 10 4 7 3 2
The program should dynamically create a 5-dimensional array, sized as so: myArray[10][4][7][3][2]. Each area numbers could be put into, they should, with random numbers between 1 and 100.

Afterward, you must output this to a text file defined by the file name, each dimension, in some sort of organized manner. You may decide how this output looks, so long as there is a definite way to differentiate to the user which array is which.

For example, to be really easy, let's say the input is "progname 2 filename.txt 5 5", then the output could look like this:
{
  27 92 71 44 1
  13 11 75 29 80
  34 62 89 14 82
  7 97 43 72 56
}
{
  etc....
The catch? Well, I'll let you off easy this time.

... of course, it still has to be 10 lines or less!
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#14 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 22 August 2009 - 10:16 AM

Is creating an in memory array actually a requirement? I would think the input and output would be the only true requirements.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#15 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 August 2009 - 10:17 AM

Not quite cross platform:

:P


Here, this should build no warnings on -pedantic C89, C94, or C99. Enjoy:
#include <stdio.h>
int main(int argc, char** argv) {
    if (argc == 5 && argv[2][1] == '\0' && argv[3][1] == '\0' && argv[4][1] == '\0') {
        int iii = 0, test = argv[1][0];
        for (iii = 0; iii < 3; ++iii) if (*argv[iii + 2] > 64 && *argv[iii + 2] < 91) *argv[iii + 2] = *argv[iii + 2] + 32;
        for (iii = 0; test != '\0'; ++iii, test = argv[1][iii]) {
            if (test > 64 && test < 91) test = test + 32;
            if (test == argv[2][0] || test == argv[3][0] || test == argv[4][0])  printf("Found %c at %i\n", (char) test, iii);}
    } else printf("Incorrect input.\nPlease format your input like this: \"string\" a b c\n");
    return 0;}

And... "cross-platform" doesn't necessarily mean "all-platforms". That's "platform independent". :)
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#16 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 August 2009 - 10:18 AM

@ WP: Yes, the input/output is the only real requirement.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#17 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 22 August 2009 - 11:22 AM

Instead of creating a new post/reply to this thread, we should create a sub-category of the general programming section labeled "Challenges". Each time you create a new on you can just create a new thread. This way, anyone can participate in any of the challenges without having to read through the entire thread. What say ye?
  • 0

#18 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 August 2009 - 11:29 AM

Hey, I'm all for that. It would help if other people made challenges too, and weren't just limited to the "10 Lines" challenges I made up here. Could be quite entertaining, I'd enjoy it. :)
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#19 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 22 August 2009 - 11:39 AM

I think this counts as 10 lines by the rules.

#include <fstream>
#include <string>
std::string recurse(int current, int argc, char* argv[])
{
std::string result;
if (current<argc) for (int iii=0;iii<atoi(argv[current-1]);iii++) result=result+"{\n"+recurse(current+1,argc,argv)+"\n}\n";
else if (current=argc) for (int iii=0;iii<atoi(argv[current-1]);iii++) result=result+" "+itoa(1+rand()%100,argv[1],10);
return result;
}

int main(int argc, char* argv[])
{
std::ofstream output(argv[1],std::ios::out);
output<<recurse(3,argc,argv);
}


Mind you, I think the above code is PURE garbage...
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#20 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 22 August 2009 - 11:44 AM

Hey, I'm all for that. It would help if other people made challenges too, and weren't just limited to the "10 Lines" challenges I made up here. Could be quite entertaining, I'd enjoy it. :)


It'll have to go through mod vote. I'll post that and see what happens.
  • 0

#21 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 August 2009 - 11:50 AM

@ WP: Hate to break it to you man, because it was good. atoi, itoa, and rand (and also srand()) all require you to #include <cstdlib>.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#22 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 22 August 2009 - 12:04 PM

Actually, MinGW did NOT require me to do that. The code posted compiles and runs.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#23 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 22 August 2009 - 12:07 PM

Breaks on my machine, and I'm using g++. Well aiight, if it builds for you then we're all good. :)
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#24 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 22 August 2009 - 12:10 PM

Mind you, with the profound lack of error-checking, it's pure garbage :)
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Also tagged with one or more of these keywords: case sensitive

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download