Programming Practice

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
BlueMonkey5
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 86
Joined: Fri Feb 20, 2009 12:54 am

Re: Programming Practice

Post by BlueMonkey5 »

yea, youre totally right... i'm getting too nit-picky. i'm just gonna get them both and check them both out. whichever one sticks, we'll see.
Ewan
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 62
Joined: Mon Mar 23, 2009 11:46 am

Re: Programming Practice

Post by Ewan »

BlueMonkey5 wrote:LOL... nice. yea that sounds really cool. it's actually a big comfort hearing that you failed the first two times (as twisted as that sounds), because I failed two times at programming too! so wow, that actually does inspire me some and gives me hope that i can give it another whack. thanks!

But here's a good question if anyone knows- is darkbasic similar to C++? so basically, if i start off learning darkbasic, will it be an easy switch to learn C++? if it is, it would be worth while to do that and then make the switch. if they are similar, alongside being useful, learning darkbasic would also be practice when switching to C++. it would be like learning something to help getting started with that. but if they're totally different, i would just start off with C, and maybe play around with darkbasic on the side to see what it's all about.
You should probably watch this: http://www.youtube.com/watch?v=zAgpsks2 ... 98&index=0 and the next two ;)
They pull out the truncheon, that's when the trouble starts.

'Cause when you've got a badge, the laws don't apply.
User avatar
BlueMonkey5
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 86
Joined: Fri Feb 20, 2009 12:54 am

Re: Programming Practice

Post by BlueMonkey5 »

cool, thanks :D
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: Programming Practice

Post by Arce »

Make an executable output it's own source.

Good luck. ^.^
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Programming Practice

Post by dandymcgee »

Arce wrote:Make an executable output it's own source.

Good luck. ^.^
Omg. :shock:
Quines are EVIL!
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: Programming Practice

Post by M_D_K »

Arce wrote:Make an executable output it's own source.

Good luck. ^.^
I was talking to avansc about that one time(I was going to submit it here as a challenge)
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
Ewan
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 62
Joined: Mon Mar 23, 2009 11:46 am

Re: Programming Practice

Post by Ewan »

M_D_K wrote:OK I have one for yout all. Now it seems alot of programmers(experienced ones too) have problems figuring this one out.

OK so here it is
Click here to see the hidden message (It might contain spoilers)
Print the numbers from 1 to 100 if the number is a multiple of 3 print foo, if it is a multiple of 5 print bar, if its both print foobar. BTW you'll be printing foo,bar,etc instead of the number

Seems easy but I know people who have been scratching their respective heads on this. When I heard of it I figured it out in like 10 seconds ;)

EDIT: You don't have to make it recursive but bonus points if you do.
Good Luck.
Did that, interesting little challenge. For me anyway :lol:

I haven't tested it completely, the numbers look right though.

Code: Select all

#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std; 

int main()
{
    double intpart;
    double a;
    

    for (double n = 1;n < 101;n++)
    {
        a = modf (n/3,&intpart);
        if (a == 0)
        {
           cout << "foo";
        }
        a = modf(n/5,&intpart);
        if (a==0)
        {
           cout << "bar ";
        }
        {
        cout << n << endl;
        }
        
    }
    system("PAUSE");
    return 0;
}
They pull out the truncheon, that's when the trouble starts.

'Cause when you've got a badge, the laws don't apply.
User avatar
LuciDreamTheater
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Tue Jan 20, 2009 2:18 am
Location: Southern CA
Contact:

Re: Programming Practice

Post by LuciDreamTheater »

dandymcgee wrote:
Arce wrote:Make an executable output it's own source.

Good luck. ^.^
Omg. :shock:
Quines are EVIL!
Here's a twist: Write a program that reads in a text file and determines whether it is it's own source code. (Note: Cannot read the source file).
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Programming Practice

Post by dandymcgee »

anothrguitarist wrote: Here's a twist: Write a program that reads in a text file and determines whether it is it's own source code. (Note: Cannot read the source file).
What kind of sick twisted person thinks up something like this? :evil: :lol:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: Programming Practice

Post by Arce »

M_D_K wrote:
Arce wrote:Make an executable output it's own source.

Good luck. ^.^
I was talking to avansc about that one time(I was going to submit it here as a challenge)
That was the #4 program for the competition I won last weekend.

It's a team challenge. Each team is 4 members and can only have one laptop. Programs can be written in any language. You have 2 hours to complete 4 programs and present them to a panel of judges.

They are sorted in order of difficulty. Ours were something like this:

1) Read in a comma separated list of words. Display each word only once, but increase the size for the amount of repetitions of the word entered.

Example input:
this,this,this,this,small,gay,gay,hi,sup,hi
Example Output:
this, small, sup , gay, hi

Should handle spacing correctly. Order of output does not matter.

2) Read a maze into an array. 'X' denotes a wall (unwalkable space), 'O' a walkable position, 'S' starting point, and 'E' ending point. Assume that no maze has circles/repeating spots. Write a program to display the coordinates (in order) that one would have to follow to reach the end of the maze. You cannot backtracks (repeat coordinates). Only traverse in cardinal directions.

Example input:

Code: Select all

X X S X X X X X X X 
X X O X X X X X X X
X X O O O O O X X X 
X X O X X X O O X X
X X O O O O X X X X 
X X X X X O X X X X
X X X X X O X X X X
X X X O O O O O X X
X X X O X X X O X X
X X X X X X X E X X
Output: (too lazy to type, fuck you.)

3) Some dipshit has problems sorting .txt files on his desktop. He needs you to help him out. Write a program to parse through all text files on the desktop, read in 3 space-separated words from that files, and rename the files to those three words (replacing spaces with underscores and ignore non-alphanumeric characters characters). If there is less than three words in the file, only use the words that are found. If there is already a file with the existing name, prefix the name numerically (rename the first with a 1, second with a 2, etc).

4) Write a quin. A program that outputs it's own source.

Surprisingly, we got first place trophies. I had a kind or argument with a judge over #2, and he didn't like our #4 solution. :lol:

Will be going to state for this one, too. (in addition to the level editor stuff). I'll let ya know if I get any loot! Also, lemme know if anybody else here thinks they can get all 4 done in 2 hours (I almost call bullshit on that).

I ended up doing one in Blitz, one in Java, one in C++, and one in nothing/Java/C++. :lol:
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Programming Practice

Post by MarauderIIC »

<bored>
Here's how I'd do them, for the interested :P
Arce wrote: That was the #4 program for the competition I won last weekend.

It's a team challenge. Each team is 4 members and can only have one laptop. Programs can be written in any language. You have 2 hours to complete 4 programs and present them to a panel of judges.

They are sorted in order of difficulty. Ours were something like this:

1) Read in a comma separated list of words. Display each word only once, but increase the size for the amount of repetitions of the word entered.

Example input:
this,this,this,this,small,gay,gay,hi,sup,hi
Example Output:
this, small, sup , gay, hi

Should handle spacing correctly. Order of output does not matter.
Click here to see the hidden message (It might contain spoilers)
#include <map>
using namespace std;

map<string, int> myMap;
myMap[word from file]++;
size = map<string, int>::iterator i.second();

2) Read a maze into an array. 'X' denotes a wall (unwalkable space), 'O' a walkable position, 'S' starting point, and 'E' ending point. Assume that no maze has circles/repeating spots. Write a program to display the coordinates (in order) that one would have to follow to reach the end of the maze. You cannot backtracks (repeat coordinates). Only traverse in cardinal directions.

Example input:

Code: Select all

X X S X X X X X X X 
X X O X X X X X X X
X X O O O O O X X X 
X X O X X X O O X X
X X O O O O X X X X 
X X X X X O X X X X
X X X X X O X X X X
X X X O O O O O X X
X X X O X X X O X X
X X X X X X X E X X
Output: (too lazy to type, fuck you.)
Click here to see the hidden message (It might contain spoilers)
A*
No loops mean you can do a tree -- DFS (or a BFS...)
Or you could do an algo that tries all left, then all up, then all down, then all right. But you'd have to keep track of where you've been.
3) Some dipshit has problems sorting .txt files on his desktop. He needs you to help him out. Write a program to parse through all text files on the desktop, read in 3 space-separated words from that files, and rename the files to those three words (replacing spaces with underscores and ignore non-alphanumeric characters characters). If there is less than three words in the file, only use the words that are found. If there is already a file with the existing name, prefix the name numerically (rename the first with a 1, second with a 2, etc).
Click here to see the hidden message (It might contain spoilers)
I could maybe do this in linux using execlp and ls, grep, mv.

4) Write a quin. A program that outputs it's own source.
I dunno. Google tells me how to do it though.

</bored>
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Programming Practice

Post by eatcomics »

MarauderIIC wrote:<bored>
Here's how I'd do them, for the interested :P
Arce wrote: That was the #4 program for the competition I won last weekend.

It's a team challenge. Each team is 4 members and can only have one laptop. Programs can be written in any language. You have 2 hours to complete 4 programs and present them to a panel of judges.

They are sorted in order of difficulty. Ours were something like this:

1) Read in a comma separated list of words. Display each word only once, but increase the size for the amount of repetitions of the word entered.

Example input:
this,this,this,this,small,gay,gay,hi,sup,hi
Example Output:
this, small, sup , gay, hi

Should handle spacing correctly. Order of output does not matter.
Click here to see the hidden message (It might contain spoilers)
#include <map>
using namespace std;

map<string, int> myMap;
myMap[word from file]++;
size = map<string, int>::iterator i.second();

2) Read a maze into an array. 'X' denotes a wall (unwalkable space), 'O' a walkable position, 'S' starting point, and 'E' ending point. Assume that no maze has circles/repeating spots. Write a program to display the coordinates (in order) that one would have to follow to reach the end of the maze. You cannot backtracks (repeat coordinates). Only traverse in cardinal directions.

Example input:

Code: Select all

X X S X X X X X X X 
X X O X X X X X X X
X X O O O O O X X X 
X X O X X X O O X X
X X O O O O X X X X 
X X X X X O X X X X
X X X X X O X X X X
X X X O O O O O X X
X X X O X X X O X X
X X X X X X X E X X
Output: (too lazy to type, fuck you.)
Click here to see the hidden message (It might contain spoilers)
A*
No loops mean you can do a tree -- DFS (or a BFS...)
Or you could do an algo that tries all left, then all up, then all down, then all right. But you'd have to keep track of where you've been.
3) Some dipshit has problems sorting .txt files on his desktop. He needs you to help him out. Write a program to parse through all text files on the desktop, read in 3 space-separated words from that files, and rename the files to those three words (replacing spaces with underscores and ignore non-alphanumeric characters characters). If there is less than three words in the file, only use the words that are found. If there is already a file with the existing name, prefix the name numerically (rename the first with a 1, second with a 2, etc).
Click here to see the hidden message (It might contain spoilers)
I could maybe do this in linux using execlp and ls, grep, mv.

4) Write a quin. A program that outputs it's own source.
I dunno. Google tells me how to do it though.

</bored>
<bull>Oh man! You really showed marcel that it's possible! </bull>
Image
Post Reply