PDA

View Full Version : Counting



XcOM
04-04-2008, 04:11 PM
http://www.thebestcasescenario.com/jdbnsn/worklogbanners/counting.png

Welcome, this is a challange for the coders here, The idea is to write a program that will count to the number in the section you are entering in.

The rules are as follows:
* No one is to share there code
* No one is to copy anyone else's program
* You are to write your program yourself but you may get help from friends.

The sections are:
* Visual Basic
- 1 Million
- 2 Million
- 5 Million
- 10 Million
- 100 Million

* C & C++
- 1 Million
- 2 Million
- 5 Million
- 10 Million
- 100 Million

* Other languages
- 1 Million
- 2 Million
- 5 Million
- 10 Million
- 100 Million

*your program must make a record of the numbers it counts, wether it displays this or saves a document it is upto you.

To enter make your program and e-mail myself at tbcscomp@gmail.com with your program compiled into an EXE and the source code so i can verify your entry.

I will compile a results table for each section after the compition has ended (19th,Apr,2008 ) and a winner announced.

All programs will be run on my test system to get an accurate result after the comp has ended, a winner will be announced within one week of ending.
And the most important part, Have fun.

halcyonforever
04-04-2008, 05:09 PM
Questions for this competition:

Purpose: Is the goal to write the most elegant code, the spiffiest program, or the fastest running.
Hardware: are we limited in our usage of equiptment. (ie: one computer only or can we botnet a whole company in a distributed computing super-cluster)

XcOM
04-04-2008, 05:25 PM
the purpose is to count to the target as fast as possable, and as for hardware the tables i produce will be for desktops/laptops and one for special pc's IE Clusters

My records sofar are:
1million: 8 seconds
2million: 12 seconds
5million: 26 seconds
10million: 56 seconds
and 1 billion is still running after 1 hour, and is currently writting a file sitting at 8.2GB sofar, but i don't know what number it is upto as i have my program set to ignore everything but counting.

Also mine is coded in VB6, i got to find a way to use dual cores.

Trace
04-04-2008, 06:22 PM
XcOM, did you get this Idea from me? Haha, I will start work immediately.

crenn
04-04-2008, 06:42 PM
Why do I have a feeling I'm going to have to learn multithreading now.....

Should I take a link down to my C code which counts (doesn't store to a file though)?

EDIT: Also does the version of C/C++ use matter?

Trace
04-04-2008, 07:18 PM
Well, My program just told me it took 3.625 Seconds to count to 1 million
Programmed in VB6

This is WITHOUT multi threading

From the values below, you can see it is almost linear relationship between which number you count to and how long it takes. In fact, you will notice that if you multiply the 100 Million time by 5 it is actually longer then what 500 Million took.

System specs: 2.3 GHz Athlon 64 X2

My Records
1 Million: 3.406 Seconds
2 Million: 7.047 Seconds
5 Million: 17.906 Seconds
10 Million: 34.562 Seconds
100 Million: 394.563 Seconds
500 Million: 1887.578 Seconds
1 Billion: 3732.39 Seconds = 62.2 Minutes 12GB file

weazel6265
04-05-2008, 01:35 AM
Who wants a headache?

This is a slight violation of the rules, but I don't think too many people are going to benefit from it.
My program counts from 0 to 1,000,000 in roughly .5 seconds, while storing these values into a .txt file

my code, for anyone who dares:

import java.util.*;
import java.io.*;
import java.lang.management.*;
class ${int _;char O=(char)0X0A;boolean $=!(1!=0%1);String __$=""+'$';
char O(int x){return(char)(x*83+32);}char O1(int x){return(char)((x<<1)+99);}
char l0(int x){return(char)(x+100);}int l01(int y){return(y==1?10:10*l01(--y));}
public static void main(String args[])throws Exception{new $();}$()throws Exception{
long $_=$_();toilet=$$();_%=1;for(;!$;)_();

toilet.flush(); //always a must

_$_(($_()-$_)*.01/(15^5)/(117&(55<<1))/(64|36)/(11^111)
+""+O(0)+O(1)+O1(1)+O1(0)+l0(11)+l0(10)+l0(0)+O(1)+O) ;}
void _()throws Exception{toilet.write(_+""+O);++_;$=(_>l01(6));}
long $_(){return t.getCurrentThreadCpuTime();}
void _$_(Object x){__().print(x);}
PrintStream __(){return System.out;}
BufferedWriter $$()throws Exception{return new BufferedWriter(new FileWriter(__$));}
ThreadMXBean t=ManagementFactory.getThreadMXBean();
BufferedWriter toilet;}

And yes, it is syntactically correct, compiles, and does what it is described as doing.

To run it, just copy the code into a file called $.java, then compile it, and run it. This will output the time taken, and the numbers will be in a new file which it creates.

Have fun:D

Trace
04-05-2008, 02:29 AM
Well, I'm not going to even touch that.
I would really like to learn Java though. I'm currently working on that actually.

crenn
04-05-2008, 07:44 AM
Java gives me a headache... most likely because I don't know how to program it.

Currently I'm holding off this comp because of the fact I need to complete my C assignment. If you want the source code of the program(for my assignment) I'm working on, I'll be happy to share it after Friday 5PM (last day it's due). Just PM me asking for it.

IndyRacer27
04-05-2008, 12:01 PM
weazel6265, yes definitely gave me headache.:) Have you ever heard of the International Obfuscated C Code Contest (http://en.wikipedia.org/wiki/International_Obfuscated_C_Code_Contest) and here (http://www0.us.ioccc.org/main.html)? Your program reminded me of it. The fact that you came up with that is pretty impressive. I'm guessing you're not just a hobby programmer.

mtekk
04-05-2008, 03:38 PM
So we're incrementing here correct? I'm not sure if multi-threading will help at all ... Also for timing, are we just benchmarking how long it takes to count from 0 to upper bound specified (1 Million, 2 Million, 5 Million, 10 Million, 1 Billion) incrementing with a step of 1? I could write this in C for the pic 18f452, but it wouldn't set any records here (40Mhz chip). How are you benchmarking things here? time to exit, or is the program supposed to keep track of this?

Anyways on a 3.2Ghz P4 I'm getting with C++ (MS VC++ 2005 express), no real optimizations:
1M: 2.406sec
2M: 4.937sec
5M: 12.437sec
10M: 24.797sec
1000M: 713.672sec
I'm not sure if the function I'm using for timing is getting me accurate measurements, the resolution of it isn't very great as far as I can tell as it doesn't like measuring things that take too far under a few thousand ICs :(

mtekk
04-05-2008, 03:59 PM
Same code as before but on my Laptop (C2D x9000 (2.8Ghz :D)) on vista, still no major optimizations.
1M: 1.198sec
2M: 2.276sec
5M: 5.763sec
10M: 11.539sec
1000M: 349.184sec

Still seems to be a problem with the 1 billion one, but time wise, my laptop is about 2x faster, with Vista than my desktop with XP. I think what happens is I run out of memory, I have 2GB on the laptop and it ate up more than 600MB, on the desktop it stopped eating at 300MB. For all practical purposes the 1 billion one is too large.

crenn
04-05-2008, 05:35 PM
Seems someone wants my assignment code ;)

For everyone's information, the code won't really help you do this task.

Trace
04-05-2008, 05:55 PM
I figured that C++ would beat out VB6 no problem. I'm going to try my hand at Java and see what I can come up with. Do we have an "Official" end to this contest?

mtekk
04-05-2008, 06:31 PM
Seems someone wants my assignment code ;)

For everyone's information, the code won't really help you do this task.

So what was your assignment?

Anyways I know my code was a little slower than what's possible, but it will give just about the shortest total application run time (if that even matters). I have a few tricks I can pull, though they all have diminishing returns.

weazel6265
04-05-2008, 07:50 PM
I just had to do it after my last "submission":



+00000000+++000000++++++0000++++++++000000++++++++ +++++++++++++++++++++>
++++00++++++0+++++0++++0++++0++++++0++++++0+++++++ ++++++>
++++00++++++0+++++0+++0+++++++++++++0+>++++++++++[<<<
----00------000000----0--------------000-----------------------------[
++++00++++++0+++++0+++0+++++++++++++++++0+++++++++ ++++++++++++++>.<.>>.<<
----00------0-----0----0----0------------0----------------------]>+<
++++00++++++000000++++++0000++++++++00000+++++++++ ++++++++++++++>>>-]



Another great program, but this one only counts from to 99, I didn't feel like going any further.
Anyone want to guess the language? (Hint: its probably what you are thinking when you look at this code)

@indy: yes, I hope to be more than a hobbyist, I'm most of the way through a BS/MS in Comp Sci, and yes, I've heard about such coding competitions.

crenn
04-05-2008, 08:13 PM
So what was your assignment?

Anyways I know my code was a little slower than what's possible, but it will give just about the shortest total application run time (if that even matters). I have a few tricks I can pull, though they all have diminishing returns.

Read values from a file, dynamically allocates memory, does some calculations with it (according to the assignment) and prints calculated information on the screen. It's about 60% done.

Trace
04-05-2008, 08:19 PM
I see "TBCS" in the code.
No idea what language though
I've got a Java code working that does to 1000000000 quite quickly. Only displays the last number though. I also have to get file writing correctly.

I have a WORKING Java program that accepts input from the user as to which number to count to! This is a big accomplishment for me, considering I started earlier today on Java. It doesn't write them to a file but if you look at my Screenshot below you will notice it runs quite quickly. Without file writing, it will run quite quickly. File writing is what takes the time.

Screenshot to 1 Billion:

http://ballerpride.net/images/count.png

crenn
04-05-2008, 10:21 PM
Something doesn't quite seem right with that program.

Trace
04-05-2008, 10:48 PM
It doesn't output to a file, I wish I could get it to.

If you want the source, PM me

mtekk
04-05-2008, 10:56 PM
Something doesn't quite seem right with that program.

It's not doing anything in the loop so the java compiler does it's optimizing duty. ;)

Trace
04-05-2008, 11:01 PM
Oh, that could be it haha
Like I said before, I just started today

NightrainSrt4
04-05-2008, 11:21 PM
Maybe I'll have to try my hand at this. Been working with Java for about a year and did some basic Python stuff before that. Haven't done anything with timers though, other than sleeping/waiting.

Weazel, I think my professors would stab me if I handed in a program that looked like that. Readability, documentation, meaningful variables and such are high on their list. But wow. I am going to really have to take a look at that when I have more time. Looks like a very interesting approach.

Trace
04-05-2008, 11:23 PM
System.currentTimeMillis()

Thats all you'll need to take a time
One at the beginning and one at the end set in variables. Subtract the first variable from the second and you have your time in Milliseconds

IndyRacer27
04-06-2008, 01:00 AM
+00000000+++000000++++++0000++++++++000000++++++++ +++++++++++++++++++++>
++++00++++++0+++++0++++0++++0++++++0++++++0+++++++ ++++++>
++++00++++++0+++++0+++0+++++++++++++0+>++++++++++[<<<
----00------000000----0--------------000-----------------------------[
++++00++++++0+++++0+++0+++++++++++++++++0+++++++++ ++++++++++++++>.<.>>.<<
----00------0-----0----0----0------------0----------------------]>+<
++++00++++++000000++++++0000++++++++00000+++++++++ ++++++++++++++>>>-]



LMAO! It's a do-nothing machine. +rep

crenn
04-06-2008, 02:26 AM
It's not doing anything in the loop so the java compiler does it's optimizing duty. ;)

If we're going to talk about letting the compilers to optimize, 0 to 10,000,000,000 in 0.000 seconds (ie too faster for the program) ;)

Trace
04-06-2008, 03:02 AM
No, it's more for the best code. I just was trying my hand at some Java. So, it ended up running quite quickly

weazel6265
04-06-2008, 10:44 AM
Au Contraire Indy, it is very much a do-something machine. It works as described. Heres another one that counts from 0000 to 9999, and prints the numbers.


+T+++++++++++++++++++++++++++++++++++++++++++++++>
++H++++++++++++++++++++++++++++++++++++++++++++++>
+++I+++++++++++++++++++++++++++++++++++++++++++++>
++++S++++++++++++++++++++++++++++++++++++++++++++>
++++++++++++++++++++++++++++++++<
------P----------------------------------------------------[
+++++++R+++++++++++++++++++C++++++++++++++++++++++ ++++++++++
<-------O-----------------O----------------------------------[
+++++++++G+++++++++++++++U++++++++++++++++++++++++ ++++++++++
<---------R-------------N------------------------------------
[++++++++++A+++++++++++T+++++++++++++++++++++++++++ ++++++++++
<-----------M---------S--------------------------------------
[++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++
>>>.<.<.<.>>>>.<<<<
---------------T----------S----T---------S-------------------
]+++++++++++++O++++++++++T++++++H+++++++R++++++++++ ++>
----------------9-------N--------E-----E---------------------
]++++++++++++++9+++++++I++++++++++++++B++++++++++++ +>
--------------9---D---R--------------M-----------------------
]++++++++++++9+++N+++P++++++++++++++U++++++++++++++ ++>
----------------A------------------N-----------------------]


And by the way, I think there is a +rep in order for whoever figures out which language my last two programs were written in...:devious:


But I think I'll stop now, I don't want to hijack this thread too much

Trace
04-06-2008, 12:35 PM
Is it assembly?

mtekk
04-06-2008, 01:39 PM
If we're going to talk about letting the compilers to optimize, 0 to 10,000,000,000 in 0.000 seconds (ie too faster for the program) ;)

Well not exactly true. It's too fast for the resolution of the timer that you are using, so in theory there are some digits that are less than 10^-3 in cumulative value.

I wonder if the x86 architecture has programmable hardware timers that can be configured like the PIC does...

XcOM
04-06-2008, 03:14 PM
the idea to to see who can code there program to count the fastest in there class,

Im going to edit my code in the hope to stop it locking up,

Also the finish date is the 19th of april 2008

silverdemon
04-06-2008, 06:32 PM
ok, I altered my code a bit, now getting:

1M: 1044ms
5M: 5186ms

I've got no output file though, do I need to redo this and make an output file?

(using VB6.0 btw, and an intel C2D E8400)

crenn
04-06-2008, 08:16 PM
1M: 1.108s
2M: 2.457s
5M: 6.221s
10M: 12.460s
1Bil: -Estimated time of around 22 minutes, I'll do it later-

What do you think? Oh, I should mention that these were run on my uni laptop (1.6GHz Pent-M, 1GB DDR, 160GB 5400rpm). Expect some lovely benchmarking from my desktop tonight.

EDIT: btw, 2 things to mention. My uni laptop uses Vista Business and also my code is in C.

Trace
04-06-2008, 09:37 PM
I'm thinking for classes, we should do Language with output file and Language without Output file so that it is even and then it is just about the code itself.

mtekk
04-06-2008, 10:37 PM
I'm thinking for classes, we should do Language with output file and Language without Output file so that it is even and then it is just about the code itself.

I think the 1Billion one should be replaced by 100Million as unless you have about 4GB of memory you won't have linear results.

What we really need is a way to compare the different systems better, as it's is very obvious that a 2.8ghz C2D kicks the butt of a 3.0Ghz P4.

Oh, yeah BTW. On a P3 866Mhz I got my times much lower than my old ones :D, still in C++ of course :D.

Trace
04-07-2008, 01:41 AM
Maybe, people should post an exe of their program and XcOM can run them so its all on the same machine. And of course they send the source with it so it can be judged.

silverdemon
04-07-2008, 08:02 AM
ok, I altered my code a bit, now getting:

1M: 1044ms
5M: 5186ms

I've got no output file though, do I need to redo this and make an output file?
(using VB6.0 btw, and an intel C2D E8400)

did some major improvement, still no output file, but here are the results:
(VB6.0, C2D E8400)
100K: 2ms
1M: 23ms
10M: 238ms
100M: 2412ms
1B: 24195ms

these times seem pretty fast for me, so I'll now focus on making a file and post back my scores _with_ an output file.

[edit]:
compiled everything into an exe-file (still no output file) and it went even faster:
100K: 1ms
1M: 2ms
2M: 3ms
5M: 6ms
10M: 12ms
100M: 146ms
1B: 1528ms

[edit2]:
Made the program store the numbers it counted and came to very nice results at my second try:
100K: 0ms
1M: 3ms
2M: 7ms
5M: 17ms
10M: 37ms
100M: 369ms
200M: 750ms
300M: 1120ms
310M: 1159ms

If I go any higher I reach the limits of the memory, so I can't count any higher with storing the numbers.
Again I am using VB6.0 and my C2D E8400 (see my system)

mtekk
04-07-2008, 12:46 PM
If I go any higher I reach the limits of the memory, so I can't count any higher with storing the numbers.
Again I am using VB6.0 and my C2D E8400 (see my system)

I assume you have 2GB of memory too :). I run out somewhere around 200M :(, well not really run out, but it's close enough.

XcOM
04-07-2008, 03:38 PM
ok, see my fist post, i have altered the target 1 billion, to 100 million, 1 billion seems to high, the finish date is still to stay the same.

Also if people could compile there program to run from EXE or JAVA to just run, also if you use any dependincies can you include them (Except VB6 ones, i have them all already) and a copy of the source code, this way all the apps will be run on the same hardware and will level the playing field for people that have P3's Vs C2D's and soforth.

When you have your program ready please e-mail it to:
tbcscomp@gmail.com
with the subject "TBCS Counting Comp"
Zip/RAR your project with two folders One containing your compiled program the other the source.

I will not be in the comp becuase it would not be fair as i will see everyones source code.

ENJOY

Collinstheclown
04-07-2008, 10:18 PM
I wrote a program on my TI-83Plus.... I havn't yet run it in full though but keep in mind it runs on a 6MHz CPU with 32KB of RAM. I was going to get a video of it running, but my batteries are dead and charging at the moment.




-CollinstheClown

Prince
04-08-2008, 12:29 AM
I'm guess this does not have to be cross-platform?
If not, I'll get something to you probably by tomorrow.

crenn
04-08-2008, 01:14 AM
1billion is possible. I'm not sure why others are having problems with RAM.

silverdemon
04-08-2008, 04:54 AM
1billion is possible. I'm not sure why others are having problems with RAM.

I can count to a googol no problem, but when you try to save the file (or any other way of saving) I get the 'problem' of not enough memory. as you could see in my previous post it cuts off at about 310M for me, with 2GB of ram.

on topic:
anyways, I'll try to compile an .exe for you to run, but it might take some time to get a 100% user friendly program, if you know what I mean.

good luck everyone ;)

[edit]:
Mail sent...

Helix666
04-08-2008, 09:14 AM
And by the way, I think there is a +rep in order for whoever figures out which language my last two programs were written in...:devious:


Is it Brainf*ck?
;)

I might have a go at this, but I don't think I'd be able to get an .EXE at the end, what with me only having linux boxen in the house.

mtekk
04-08-2008, 10:56 AM
I might have a go at this, but I don't think I'd be able to get an .EXE at the end, what with me only having linux boxen in the house.

There are Open Source tools that do generate windows executables on a Unix like system. Look at MinGW, it supposedly will allow you to cross compile for Windows in Linux.

weazel6265
04-08-2008, 01:37 PM
Is it Brainf*ck?


Ding Ding Ding, we have a winner (your +rep is in the mail). Possibly the worst language ever created, beside malboge, which I don't even want to touch.

Collinstheclown
04-08-2008, 10:19 PM
Ok, stupid me... I didn't get the time for when i started it but I did get a few times if anyone feels like figuring it out.
11:22pm (day 1) - Count was around 44,000
6:00am (day 2) - Count was around 391,000
4:00pm (day 2) - Count was around 917,000
5:39pm (day 2) - Count finished.

This is for 1 Million on a TI-83plus.




-CollinstheClown

Trace
04-09-2008, 01:08 AM
1Bill isn't a problem, heck I've done it. (With one of the worst programming languages ever)

I sent mail. My java is so slow. 84 Seconds for 5 million. My VB6 is faster. Still optimizing, trying to figure out the best way to do this.

silverdemon
04-09-2008, 03:55 AM
1Bill isn't a problem, heck I've done it. (With one of the worst programming languages ever)

I sent mail. My java is so slow. 84 Seconds for 5 million. My VB6 is faster. Still optimizing, trying to figure out the best way to do this.

Hmm, probably depends on how you save your numbers. Java could be slower than VB6, but I think C or C++ should be even faster than basic... since I don't have a lot of experience in C I won't enter for that language, but I think there's a challenge for those who can program in C...

also in my previous post I said I could easily count to a googol when I don't store the numbers... well, that's not entirely true... In my program I use the 'long integer' variable, so I can only count to 18,446,744,073,709,551,615 since it is stored in just 8 bytes in the memory... There's probably a workaround for that too, but I don't have to know :P

mtekk
04-09-2008, 09:28 AM
also in my previous post I said I could easily count to a googol when I don't store the numbers... well, that's not entirely true... In my program I use the 'long integer' variable, so I can only count to 18,446,744,073,709,551,615 since it is stored in just 8 bytes in the memory... There's probably a workaround for that too, but I don't have to know :P

You can manually manage rollovers and store it in two longs (slow, ugly, and what we do for the PIC18F452 in microcontroller land), or go to 64bit where longs are 16bytes long.

Prince
04-09-2008, 02:56 PM
I have kind of a nit picky question.
Do I have to measure the total program run time or just the time it takes to actually count the numbers?

crenn
04-09-2008, 04:49 PM
Time it takes to output the numbers to a file.

mtekk
04-09-2008, 06:15 PM
Time it takes to output the numbers to a file.

Um, not quite, few are doing that, I can tell by the times (unless some one is running a raid array with some super fast SAS drives or those ramdisks, at least for those times under 1sec for 1M). The test is not seeing how long it takes to write to a file but how long it takes to generate the numbers in a retrievable manner. See the official rules:


...your program must make a record of the numbers it counts...

Trace
04-09-2008, 06:22 PM
So, I could write to a variable and that would count? Does it have to print them out afterwards?

mtekk
04-09-2008, 08:21 PM
So, I could write to a variable and that would count? Does it have to print them out afterwards?

You do have to prove that your code doesn't just do a 1, 2, skip a few... 9,999,999... 10 million kinda thing. :rolleyes:

crenn
04-09-2008, 08:42 PM
Um, not quite, few are doing that, I can tell by the times (unless some one is running a raid array with some super fast SAS drives or those ramdisks, at least for those times under 1sec for 1M). The test is not seeing how long it takes to write to a file but how long it takes to generate the numbers in a retrievable manner. See the official rules:

I assumed it was outputting it to a file. But if it's just displaying it, then I'll be able to do that very easily.

Trace
04-10-2008, 05:04 PM
If we are sending the source to XcOM to run, he should be able to verify that it isn't doing a 1, 2 skip a few sort of thing.

Tavarin
04-10-2008, 06:39 PM
Just for the hell of it I wrote a 3 line piece of PHP code that would output the numbers to your browser. It's slow as sin if you lack a T1 connection, but it was interesting to see none the less.

I want to do this in VB 6.0, but I can't since I run a 64 bit system and lack the install for it. I might write it at school where they have VB 6 on all the computers.

Trace
04-10-2008, 09:44 PM
I can give you a portable VB6 program that will work for all intents and purposes. PM for it if you want it.

XcOM
04-11-2008, 02:47 PM
TBCS doesn't condone copyright infringment and you are walking on very ice trace with that remark.

and to clarafy the rules, your program dosen't have to write a file, just display the numbers in some form, even if it runs through them as it counts, this is just to make my life easier when checking the programs to ensure your not cheating.

Trace
04-13-2008, 10:57 PM
(I didn't produce the VB6 Portable. Considering I have a license, I use it as a utility at school.)

So it has to display all of them? That takes longer then writing a file

Helix666
04-14-2008, 02:15 PM
hm, I still haven't managed to get an MS Windows binary compiled, but I have been able to get a run time for 100 Million.


[james@Deamon ProgChall]$ time ./count.bin

real 0m42.290s
user 0m30.738s
sys 0m4.768s
[james@Deamon ProgChall]$


left an 848MB out.txt file... :)

EDIT: - ran 8m54.171s for 1,000,000,000
I'm impressed...

EDIT2: - Finally got a windows binary compiled. yaaaaaaaaaaaaaaaaay!
Email being sent in the next few minutes.

XcOM
04-19-2008, 10:11 AM
ok, comp is closing today, any entries not recived by tonight (9PM GMT) will not be counted,

Last chance to get your entries in.

crenn
04-19-2008, 11:52 AM
I'm pondering if I should do it or not... because your 9PM is a lot different for me (6AM)

mtekk
04-19-2008, 01:20 PM
Can you send confirmation e-mail to those who sent you stuff? I only ask this because gmail does not like sending binaries:mad:, so I sent it in a 7zip archive last night.

silverdemon
04-19-2008, 05:50 PM
Can you send confirmation e-mail to those who sent you stuff?...

that would be a good idea (may for future contests though ;) )


...so I sent it in a 7zip archive last night.

What I did to send all the files (including *.exe files) is zipping all the files just as you normally would do, and then change the extension to something else. I believe I changed it to*.zap for this competition.
All the receiving person has to do is changing the extension back to the original.
I think that would be the most easy way to send *.exe (or other prohibited) files via gmail...

mtekk
04-19-2008, 06:15 PM
What I did to send all the files (including *.exe files) is zipping all the files just as you normally would do, and then change the extension to something else. I believe I changed it to*.zap for this competition.
All the receiving person has to do is changing the extension back to the original.
I think that would be the most easy way to send *.exe (or other prohibited) files via gmail...

Doesn't work with gmail, they actually check the file structure ;), ran into that problem/figure that out a long time ago. You actually have to send them in a compression format that they (google) can't read.

silverdemon
04-19-2008, 06:43 PM
Hmm, in that case I would most definately like to know if my mail actually was sent.

When I tried to send an *.exe file I got a message that for safety things... bla bla... could not send message.
Same thing happened when I zipped the files (*.zip)

but with the extension changed to *.zap I got no message telling me it was not safe or anything...

[edit]: Sent myself an email to confirm what I just said: Message pops up only with *.exe and *.zip. NOT with *.zap.
Also, when I changed the extension of the received file (at an other email account) back to *.zip it worked as it was supposed to work, I could read the zipped files...
maybe they had a change in policy?

mtekk
04-20-2008, 12:39 AM
Hmm, in that case I would most definately like to know if my mail actually was sent.

When I tried to send an *.exe file I got a message that for safety things... bla bla... could not send message.
Same thing happened when I zipped the files (*.zip)

but with the extension changed to *.zap I got no message telling me it was not safe or anything...

[edit]: Sent myself an email to confirm what I just said: Message pops up only with *.exe and *.zip. NOT with *.zap.
Also, when I changed the extension of the received file (at an other email account) back to *.zip it worked as it was supposed to work, I could read the zipped files...
maybe they had a change in policy?
Good find, its hard to believe Google would change from a superior screening process to a "stupider" one. :think:

Helix666
04-20-2008, 09:17 AM
OK, I don't know if you managed to get my submission before my server fell over... I'll email them in an archive if you haven't got them, just let me know.
:|

XcOM
04-20-2008, 02:38 PM
ok, comp close, the enteries are:

Trace,
Silverdeamon
Prince,
Helix,
Mtekk.

Tests will be run later and a winner announced

silverdemon
04-20-2008, 03:23 PM
oh boy, oh boy! can't wait!
I'd really like to see how fast is actually possible...

btw XcOM, you've got a little typo in my name ;)

Trace
04-20-2008, 03:44 PM
Thanks!
I'm thinking that after the winner is announced, we should release source code to both learn from how each other did it and so that we can get a group effort going to get the quickest time...
:D
Thanks
XcOM, it was fun!

Helix666
04-21-2008, 04:30 PM
Well, when the winner's announced... I'll post a link to my source. s'Not pretty, but it gets the job done. (And is possibly more complex than needs be...)

I'll be TBCS'd... :P

Prince
04-21-2008, 07:24 PM
I probably will post it. It is nothing special, but it works well and measures time fairly accurately.

crenn
04-21-2008, 09:16 PM
I'll post the source code I had (it's complete but didn't submit it in time)

Trace
04-21-2008, 10:29 PM
K, sounds good guys

XcOM
04-24-2008, 02:46 PM
got one more program to test, all times are recorded in seconds to 3 decimal places.

Results should be in soon.

Trace
04-26-2008, 02:37 AM
Ok, sweet. Well, I figured out how to make my program run on 4 threads. It was able to do 100 Million in 57 seconds for the longest thread :D

XcOM
04-27-2008, 07:31 AM
the results will be in soon, got them all, table is being made in a minute.

Trace
04-27-2008, 12:28 PM
Can't wait!

XcOM
04-27-2008, 02:19 PM
And the results are in, honstly im suppurised at them.

And helix, your app didn't have a counter and you didn't reply with a revision that did so, in efect your app does not have any scores becuase i couldn't get any.

http://www.thebestcasescenario.com/TBCS_Group/xcom/results.png

XcOM
04-27-2008, 02:26 PM
its strange i think, VB has 2 out of 5 victorys and Java has 2 out of 5, and C++ has only 1 out of 5.

I was expecting C++ to wipe the floor with everything, but apperently not!

jdbnsn
04-27-2008, 02:38 PM
so who won?

silverdemon
04-27-2008, 03:04 PM
so who won?

Yeah, who won?

I can see that VB (my program:)) wins in the shorter countings, but java (trace) takes over at the larger numbers. Also C++ (Mtekk) is quicker at those numbers.
It seems to me that both Java and C++ count faster, but the program takes a little time to initialize or somthing, since the lower numbers all take about 15-16ms...

Anyways, good job you all!
now: let's see the sources :D

mtekk
04-27-2008, 03:20 PM
its strange i think, VB has 2 out of 5 victorys and Java has 2 out of 5, and C++ has only 1 out of 5.

I was expecting C++ to wipe the floor with everything, but apperently not!

In all reality, there are much faster ways of doing this in C++, but mine was the quickest to write, and kept with the STL. I wrote it in the middle of two weeks filled with midterms. Prince probably used vectors, but probably didn't do any preallocation which decreases performance (mine preallocated before counting). I think the timing method I used isn't necessarily the best either, it's resolution is a little low (has a resolution of 1ms).

I'd like to see the code silverdemon used. Mine is in the bottom of this post.

Just out of curiosity, did you do multiple runs and average them? And what system specs?

Here's my code

/*
John Havlik
4-18-2008
Count Benchmark
*/
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;fstream&gt;
#include &lt;ctime&gt;
using namespace std;

int main()
{
clock_t start, end, elapsed;
vector<unsigned int> dump;
unsigned char foo;
unsigned int count(1000000), temp(0);
do
{
cout << "How many iterations do you want to do?\n";
cin >> temp;
count = ++temp;
dump.assign(count, 0);
start = clock();
while(--count)
{
dump[count] = count;
};
end = clock();
elapsed = end - start;
cout << "For " << temp << " loops (count from 0 to " << temp - 1 << ")\n We took: " << elapsed << " ms \n Saving...";
ofstream fout;
fout.open("count.out");
for(unsigned int i(0); i < temp; i++)
{
fout << dump[i] << endl;
}
fout.close();
dump.clear();
cout << " Done.\nWould you like to run again?(y/n)\n";
cin >> foo;
}
while(foo == 'y');
return 0;
}

Trace
04-27-2008, 04:16 PM
Well, who won?
My code is below.
I entered the second 1.

If you want my VB6 code let me know.(PM)

Java (with output):


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
class Count2
{

public static void main(String args[]) throws FileNotFoundException
{
Scanner input = new Scanner( System.in );
PrintStream diskWriter = new PrintStream( "D:/java/numbers.txt" );
System.out.print( "Enter number to count to: " );
int countto = input.nextInt();
int count = 0;
long time = System.currentTimeMillis();
while (count < countto)
{
count = count + 1;
diskWriter.println( count );
}
long timeTook = System.currentTimeMillis() - time;
System.out.println("It took you "+timeTook+"ms to count to "+count);
}
}


Java(without output):


import java.util.Scanner;

public class Count

{
public static void main( String args[] )

{
Scanner input = new Scanner( System.in );
System.out.print( "Enter number to count to: " );
int countto = input.nextInt();
int count = 0;
long time = System.currentTimeMillis();

while ( count < countto)
{
count = count + 1;
}
long timeTook = System.currentTimeMillis() - time;
System.out.println("It took you "+timeTook+"ms to count to "+count);
}
}

mtekk
04-27-2008, 04:17 PM
Just for fun I opened up Mathematica and did some plots of the times. For the following plots, orange is Trace, blue is me (mtekk), red is Silverdemon, and green is Prince.

Here's Trace's Time vs. Count graph
http://mtekk.weblogs.us/images/tbcs_code/trace.png
Here's My Time vs. Count graph
http://mtekk.weblogs.us/images/tbcs_code/mtekk.png
Here's Silverdemon's Time vs. Count graph
http://mtekk.weblogs.us/images/tbcs_code/silverdemon.png
Here's Prince's Time vs. Count graph
http://mtekk.weblogs.us/images/tbcs_code/prince.png
Here is a combined, graph on the common axis of Prince's plot.
http://mtekk.weblogs.us/images/tbcs_code/combined.png

mtekk
04-27-2008, 04:21 PM
Well, who won?
My code is below.
I entered the second 1.

If you want my VB6 code let me know.(PM)


Err, that second one isn't actually storing the count. ;) Unless I'm missing something :?

Trace
04-27-2008, 04:34 PM
Wait, I think that's the one I entered. I'm not completely sure actually.

mtekk
04-27-2008, 05:00 PM
Wait, I think that's the one I entered. I'm not completely sure actually.

If that's the one you entered (the one in the count object, not the count2 object), then doing a similar thing in C++ results in times under the resolution of my timer, for all lengths. :think:

Ok so if you compiler does any optimization you will see your times drop to 0ms if you never use the variable you assign to out of the loop.

If you do use it out side of the loop you get times exactly matching Trace's times (at least on my laptop). What that means is that the Java compiler Trace used did not optimize as it should have (his should have resulted in 0ms for any input number).

The Code I used to test this:


#include &lt;iostream&gt;
#include &lt;ctime&gt;
using namespace std;

int main()
{
clock_t start, end, elapsed;
unsigned char foo;
long count(0), temp(0), temp2;
do
{
cout << "How many iterations do you want to do?\n";
cin >> temp;
count = ++temp;
start = clock();
while(count)
{
temp2 = count--;
}
end = clock();
elapsed = end - start;
cout << "For " << temp2 << " loops (count from 0 to " << temp - 1 << ")\n We took: " << elapsed << " ms\n"
<< "Would you like to run again?(y/n)\n";
cin >> foo;
}
while(foo == 'y');
return 0;
}

silverdemon
04-28-2008, 04:18 AM
ok, here is the snippet of code that does the counting in my VB6 program. There are also comments at the end of all lines (did that for XcOM so he could see what I was doing)


Private Sub cmdStart_Click() 'start button
lblStatus.BackColor = RGB(255, 0, 0) 'make statuslabel red
lblStatus.Caption = "Counting..." 'print busy text
DoEvents 'give windows time to do things (writing in the label)
x = 0 'set startpoint to 0
Finish = Val(txtFinish.Text) 'read endpoint from textbox
ReDim Numbers(1 To Finish) As Long 'ready the array for input
StartTime = timeGetTime 'read the time (starttime)
Do Until x = Finish 'count until x = finish (the number from the textbox)
x = x + 1 'add one to x
Numbers(x) = x 'store x in the array
Loop 'loop the counting
EndTime = timeGetTime 'when finished, get time again (endtime)
TimeTaken = EndTime - StartTime 'calculate time taken
lblStatus.BackColor = RGB(0, 255, 0) 'make statuslabel green and
lblStatus.Caption = "Done!, Numbers stored in array, idle" 'print done text
lblOutput.Caption = Finish & ": " & TimeTaken & "ms" 'print the result to the label
End Sub 'end counting sub

as you can see the numbers are stored in an array. My program also had a display-button, that let's you display the numbers in the array (code not in here)

enjoy

Helix666
04-28-2008, 04:38 AM
And helix, your app didn't have a counter and you didn't reply with a revision that did so, in efect your app does not have any scores becuase i couldn't get any.


*blink**blink*
what?

my last revision outputs the time it takes to run to stdout... and I have the sourcecode to prove it. (well, it's at home, but...)

mtekk
04-28-2008, 08:33 AM
ok, here is the snippet of code that does the counting in my VB6 program...
...as you can see the numbers are stored in an array. My program also had a display-button, that let's you display the numbers in the array (code not in here)

enjoy

Looks like VB6's arrays are faster on small numbers than C++ vectors (vector<T> class objects) and C dynamically allocated arrays (using malloc()). That is interesting.:think:

XcOM
04-28-2008, 12:47 PM
i think the winners should be joint winners between
Silverdemon and Trace,

and sorry helix, but when run yourapp it never displayed the output for me.

my app when i factored it in never won a single catagory.

also yes i ran each test 5 times and got an adverage,

the specs were:
AMD X2 Tk55 (1.8GHz Dual core)
1Gb RAM
80GB SATA HDD

Helix666
04-28-2008, 07:19 PM
XcOM: you did run it from a terminal/command prompt, right?



#include <fstream>
#include <iostream>
#include <time.h>

using namespace std;
int main(int argc, char *argv[]){
int count;
time_t timeAtStart, timeAtEnd;
if(argc>1)
count = atoi(argv[1]);
else
count=1e9;
unsigned long int ulNumber=0;
time( &timeAtStart );
cout << "Time at start: " << timeAtStart << endl;
ofstream fout("out.txt");
for(ulNumber=1;ulNumber<(count+1);ulNumber++){
fout << ulNumber << "\n";
}
fout.close();
time( &timeAtEnd);
cout << "Time at end: " << timeAtEnd << endl;
cout << "Time Taken: " << timeAtEnd - timeAtStart << " seconds." << endl;
return 0;
}


not pretty, but works. ah well, nevermind.

mtekk
04-28-2008, 09:43 PM
Helix, you realize that writing directly to that file is going to really slow things down right? ;) A semi-faster way is to use a stream buffer, dump the numbers into it, and then at the end dump it to the file buffer. The fastest way is to use a vector or array to hold your data. And dump that to the file after you're done with the timed loop, both Silverdemon and I did that. Or you could do what trace did and not actually store the individual values. In which any good compiler will optimize the loop out of the assembly code. :rolleyes:

Trace
04-29-2008, 12:34 AM
Well, apparently the Java compiler didn't lol.
And on the loops, I think that you would find a:



For x = 1 to CountTo
'Loop
Next x


Would work better because it doesn't have to check the value everytime, because it is set to run a specific number of times. My 2-bits

silverdemon
04-29-2008, 03:23 AM
Helix, you realize that writing directly to that file is going to really slow things down right? ;) A semi-faster way is to use a stream buffer, dump the numbers into it, and then at the end dump it to the file buffer. The fastest way is to use a vector or array to hold your data. And dump that to the file after you're done with the timed loop, both Silverdemon and I did that...

That's true. I wanted to make the program as fast as I could, so I got every bit of code outside of the loop. Only the real counting takes place inside the loop. This way the loop will be smaller and since it'll be looped like 1mil or 1bil times every line of code and even every character on the line inside the loop will take a lot of time in the eventual program.

Trace: congrats on the win! +rep is on the way

mtekk
04-29-2008, 08:46 AM
...This way the loop will be smaller and since it'll be looped like 1mil or 1bil times every line of code and even every character on the line inside the loop will take a lot of time in the eventual program...

You mean every instruction, characters are 'free', the number of instructions is what is important.

Trace,

Using a for statement is no faster than using any other loop, the condition to keep within the loop is always checked (unless the loop is unrolled by the compiler). Using something like:


while(count--);

would produce more or less the same assembly as:

while(count)
{
count = count - 1;
}
or

while(count)
{
count -= 1;
}
or

while(count)
{
count--;
}


meaning they all will take the same amount of time to complete, unless you use an optimizing compiler that will say, well count just ends up going to zero, so let's skip the loop and just set it to zero.

Trace
04-29-2008, 07:19 PM
Oops, my mistake on the loop.

silverdemon
04-30-2008, 03:45 AM
You mean every instruction, characters are 'free', the number of instructions is what is important.

yeah, what I meant was that you want to keep the loop for counting as small as possible. At first I had another line of code in my loop, I believe that was for displaying the number 'líve'. I took a heck of a lot more time then... So like you said, as little as possible instructions in the loop.

btw has anybody started with a refined, better, faster program?

mtekk
04-30-2008, 09:38 AM
btw has anybody started with a refined, better, faster program?

Without devolving into assembly, I'm not exactly sure how to make things any faster. I have implemented Trace's method in C++, which takes 0ms for any number to complete for reasons discussed earlier. :rolleyes: There may be slightly faster libraries for C++ dynamic arrays, the boost libraries come to mind. wxWidgets supposedly have a faster dynamic array as well. I guess I could see if they make any difference. Really, what I'd like to see Trace modify his java to store the values (preferably in an array/vector) and see how fast that is.

Prince
04-30-2008, 09:53 AM
I knew full well that my program wouldn't win, but I wanted to be able to see how a basic counting vector versus an optimized one would run, and that right there shows you the difference.

Trace
04-30-2008, 01:13 PM
mtekk, I'll see what I can do in the way of the java.

Idea: Let's get teams together of the same language and come up with a new challenege to see which language and team is the best.

weazel6265
04-30-2008, 01:19 PM
We could always play Perl golf, or something similar with a different language.
Or my favorite, obfuscation.

Trace
05-01-2008, 09:24 PM
I'll come up with some ideas and post a poll in the chatterbox for you programmers to vote on.

XcOM
05-05-2008, 04:05 PM
i was thinking of making this a monthly thing, every month or 2 months or 3 months or so,

Set a new challange for coders to write a program and then run them on a test platform to see who wins, there may even be a long one with teams for prizes.

crenn
05-05-2008, 09:10 PM
Ooooo.... I like the sound of that.

silverdemon
05-06-2008, 03:59 AM
yeah, me too. I like to program a few simple things every once in a while...

_count_ me in (pun intended)

Trace
05-21-2008, 05:30 PM
Ok, I finally got around to re-writing the Java program. The times are almost identical to what they were earlier, crenn.

But I am getting an out of memory error. When I go higher then 10,000,000 so far.

Prince
05-25-2008, 11:00 AM
I'm not the best at the optimization, but I can solve some problems pretty fast. Came in second in a programming contest for all high school students in the state and won a Wii.:)

boost1105
06-01-2008, 04:12 AM
Au Contraire Indy, it is very much a do-something machine. It works as described. Heres another one that counts from 0000 to 9999, and prints the numbers.


+T+++++++++++++++++++++++++++++++++++++++++++++++>
++H++++++++++++++++++++++++++++++++++++++++++++++>
+++I+++++++++++++++++++++++++++++++++++++++++++++>
++++S++++++++++++++++++++++++++++++++++++++++++++>
++++++++++++++++++++++++++++++++<
------P----------------------------------------------------[
+++++++R+++++++++++++++++++C++++++++++++++++++++++ ++++++++++
<-------O-----------------O----------------------------------[
+++++++++G+++++++++++++++U++++++++++++++++++++++++ ++++++++++
<---------R-------------N------------------------------------
[++++++++++A+++++++++++T+++++++++++++++++++++++++++ ++++++++++
<-----------M---------S--------------------------------------
[++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++
>>>.<.<.<.>>>>.<<<<
---------------T----------S----T---------S-------------------
]+++++++++++++O++++++++++T++++++H+++++++R++++++++++ ++>
----------------9-------N--------E-----E---------------------
]++++++++++++++9+++++++I++++++++++++++B++++++++++++ +>
--------------9---D---R--------------M-----------------------
]++++++++++++9+++N+++P++++++++++++++U++++++++++++++ ++>
----------------A------------------N-----------------------]


And by the way, I think there is a +rep in order for whoever figures out which language my last two programs were written in...:devious:


that is abit of a "brainf**k" isn't it