BPsite Forums

BPSITE => Geek's Corner => Topic started by: smi256 on September 15, 2005, 07:28:03 PM



Title: The Gathering of Programmers
Post by: smi256 on September 15, 2005, 07:28:03 PM
Programmers (from, but not limited to Mission) of various languages (Visual Basic, C, C++, C#, Java, Perl, anything and everything else) are welcomed to join this forum to discus and seek help about programming (including homework).

General Forum Rules (http://www.bpsite.co.uk/forums/index.php?act=ST&f=2&t=2) are short and simple

Code:
Use the formatting buttons will let you use most of the formatting option

[code] [ /code] this is what I used to make this box.

--but you need to add the “New” to this line of code!--
[font=Courier New] [/font]  using this makes some code look nicer


 :sheep: Please ask your questions (about the forum and such) here in order to keep other threads on topic.[/size]
The Sheep commands it so.


Title: The Gathering of Programmers
Post by: Mr.Slippery on September 15, 2005, 08:30:03 PM
Hi, we are on a mission, are from Mission, and seek to get through this semester of programming with minimum headaches and maximum grade. If those are your goals also, then join up (register and log in) and have some fun. We can still use the file area at the Yahoo MC_Programmers group for shared data and code, but discussions may be easier in this forum. It's all voluntary, so do what you like. Just as long as you do SOMETHING.   :D

ttyl,
Will :cool:

btw, this forum does allow small files to be attached to messages, so if that's easier for you, then have at it.  :sheep:  


Title: The Gathering of Programmers
Post by: SS on September 16, 2005, 03:25:18 PM
Welcome Mission people! :thumbs-up:


Please feel free to spill over into the non-computer areas and contribute to the numerous thoughtful and intellectual discussions. ;)


Title: The Gathering of Programmers
Post by: smi256 on September 16, 2005, 08:47:36 PM
REALLY?!  WHERE?! :o
 :unsure:
At this point I'd like to suggest that the people that are just joining to post and possibly one of those threads will start "thoughtful and intellectual discussions".
 :)

HW (something more serious) Due: Sep 20

Bubble Sort:
100
1,000
10,000

Selection Sort:
100
1,000
10,000

Merge Sort: (must be recursive)
100
1,000
10,000


We need to give the amount of time it takes to sort these sets of elements (using the fast timer given by Mr. Slippery), and the number of comparisons also of each set of elements.

All-n-all, we’ll end up with 6 run times and 6 number of comparisons, a printout of the 3 source codes along with a ‘before’ and ‘after’ test array (a small one) for each sort function to show that they work.
 


Title: The Gathering of Programmers
Post by: smi256 on September 20, 2005, 07:30:00 PM
I printed out the Source Code and did some screen captures (print screen)
Like this :D


I took it down <_<
Too bad for you!!! :hmmm:


oops, there's my name, owell :P
I hate those who don't post, and I hate those who havn't signed up yet! :devil:
 :sheep:  


Title: The Gathering of Programmers
Post by: Mr.Slippery on September 21, 2005, 01:44:32 AM
Smi256,
Hmmm, I got about 120,000 comparisons in the 10,000 element Merge Sort algorithm.
That's about twice your figure.

where did u put ur comparison counter? I put mine after splitting the arrays into 2 pieces, then I counted the comparisons in the for loop.

-Slip


Title: The Gathering of Programmers
Post by: matt_the_shark on September 21, 2005, 02:27:23 AM
Quote

oops, there's my name, owell :P
OMG I'M GONNA BOMB YOUR HOUSE NOW PETER!!!! :P


Title: The Gathering of Programmers
Post by: smi256 on September 21, 2005, 07:01:48 AM
Quote
Quote

oops, there's my name, owell :P
OMG I'M GONNA BOMB YOUR HOUSE NOW PETER!!!! :P
:mellow:  :huh:  :blink:  :o
terrorist terrorist!! Home Land Security, get off your stupid asses and arrest that man!!!
 :P

[edit]
Slip, ya I think I put my counter in the wrong place I think...
I'll post my code if people want me to.


Title: The Gathering of Programmers
Post by: RipperRoo on September 21, 2005, 02:57:09 PM
Why does everyone on here have the name Peter? :(
Get off it, its mine.

What does this thingy actually do btw?


Title: The Gathering of Programmers
Post by: SS on September 21, 2005, 06:01:34 PM
I had the name first! :angry:


What it's doing is sorting random numbers into order.


Title: The Gathering of Programmers
Post by: mole on September 21, 2005, 06:05:45 PM
Quote
numerous thoughtful and intellectual discussions

 LOL  youve made my day  


Title: The Gathering of Programmers
Post by: Hornet on September 21, 2005, 10:07:22 PM
Quote
Please feel free to spill over into the non-computer areas and contribute to the numerous thoughtful and intellectual discussions. ;)

He does enjoy his little joke.

On topic, is there anyone else here, apart from those who've already posted, who are programmatically inclined?  And which languages?


Title: The Gathering of Programmers
Post by: smi256 on September 22, 2005, 06:44:04 AM
JAVA[/size]
We went over:  While, Do while, Logic operators, Switch, Formating, and how to draw Rectangles and Ovals..

HW #2  Pg161 #4.2 I guess she really did want us to do it  ^.^;;;
      #3  Pg228 #5.17  out put should look something like this:
Quote
Item#    cost per item    Qnty    Cost
1           $2.98                2        $5.96
3           $9.98                1        $9.98
-------------------------------------------------------
                          Grand Total:  $15.94
Can I die yet?  I'm going to read ahead to learn more GUI  :blink: hehe, that sounds funny


Title: The Gathering of Programmers
Post by: smi256 on September 24, 2005, 06:01:02 AM
Advanced C[/size]

I did the salesman problem…I think :blink: …
I didn’t do it the brut force way though, which makes me think that it’s not going to be correct when there are a lot of cities :cry:

I’m now asking for a hint (or two, or three, or four, oh hell, just give me the answer!)
How do you do a depth-first-search?
I mean, I know how it works… but how the hell do you code something like that?
The “distances” between the “cities” are stored in a 2D array.
 :sheep:  


Title: The Gathering of Programmers
Post by: Mr.Slippery on September 27, 2005, 01:37:44 AM
That's impressive Smi,  <_<

You can test if it works properly by making the city list very small, like 4 locations, and then seeing if your algorithm works for that quantity.

Btw, I hope this homework isn't due tomorrow. otherwise, i'm hosed.

Could you bring your DM book to class?

-Slip


Title: The Gathering of Programmers
Post by: smi256 on September 27, 2005, 04:01:42 AM
I've worked it out with 4 and 5 cities.
but the problem is that I don't think that my technique works when there are more cities...
the only way for me to see if mine works is for someone to make the program as the instructor suggested (the brut force way), even if that person has to be me if everyone wants to be punks and not show in the forum <_<

My technique works by starting at one city and fallowing the shortest path to all adjacent cities.  Here’s the problem, it doesn't look far ahead, and there are paths that are shorter overall.  I tried to overcome some of this by starting anew at every city, but this only helps, not fixes the problem.
(http://home.ripway.com/2005-9/438358/Paths.PNG)
it looks like ripway is having major server trouble (the thing was totaly destroyed apparently) my image won't work till they fix their hardware


Title: The Gathering of Programmers
Post by: Mr.Slippery on September 27, 2005, 06:32:02 PM
ADV-C:[/b][/size]
Traveling Salesman Problem:

Try these links:
 some have animations of Depth-First and Breadth-First algorithms:

http://www.cs.duke.edu/csed/jawaa/DFSanim.html (http://www.cs.duke.edu/csed/jawaa/DFSanim.html)
http://www.cs.duke.edu/csed/jawaa/BFSanim.html (http://www.cs.duke.edu/csed/jawaa/BFSanim.html)

http://en.wikipedia.org/wiki/Depth-first_search (http://en.wikipedia.org/wiki/Depth-first_search)
http://en.wikipedia.org/wiki/Breadth-first_search (http://en.wikipedia.org/wiki/Breadth-first_search)
http://en.wikipedia.org/wiki/Traveling_sal...alesman_problem (http://en.wikipedia.org/wiki/Traveling_salesman_problem)

More links than I can deal with:
http://www.ing.unlp.edu.ar/cetad/mos/TSPBIB_home.html (http://www.ing.unlp.edu.ar/cetad/mos/TSPBIB_home.html)

Here's a Java algorithm:
http://www.pms.ifi.lmu.de/lehre/compgeomet...l#visualization (http://www.pms.ifi.lmu.de/lehre/compgeometry/Gosper/shortest_path/shortest_path.html#visualization)


Dijkstra's algorithm (NOT the same as the Traveling Salesman prob):
http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm (http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm)
http://www.cs.sunysb.edu/~skiena/combinato...s/dijkstra.html (http://www.cs.sunysb.edu/~skiena/combinatorica/animations/dijkstra.html)


--Slip


Title: The Gathering of Programmers
Post by: smi256 on October 03, 2005, 12:01:30 AM
For the “traveling salesman” problem are we to printout all duplicate paths?  For instance, if you have four cities and the shortest path is ABCD, should we also print ADCB?  It’s the same path, but traveling the other way around.

PS. Yes, this does indeed imply that my program works.  ( moral +10 ), ( moral -10 ) if otherwise.  >.>

PSS. Don’t forget to do the adaptation of the…umm…something that we already did…umm…were we to do the adaptation of the sort program(s) to make use of pointers instead of using array indices?

Should I post the code here?  Maybe more people will post or even signup.
(http://home.ripway.com/2005-9/438358/Sortbyforce.PNG)
[Edit]

Good lord…stupid factorial problem
I collected some data, number of cities versus the time it took for my program to complete.  I had only gotten five data points but I used Excel’s trend line thingy anyways, it told me that it would take 2.1 weeks for my program to find every single shortest path if there were 20 cities…I also saw that it would take 10 hours to find the shortest path with 15 cities; I figured that I could at least get another data point by the next morning.  However!! It’s now been 12 hours and my program is at almost 12% complete.  In which case, my logic dictates to me two things. One, that the trend line I used was wrong, either because I set it up incorrectly, or that I didn’t have enough data. Two, that the 2.1 weeks to search through 20 cities is much MUCH too short a time… <_<

I have now set my program's priority down to “below normal”.  This way I get to know how long it’ll take to complete, AND I get to use my computer.  Which doesn’t change the fact that it will take something like four and half days to complete…I guess that means it’ll take a total of 5 days to complete…O_o
 


Title: The Gathering of Programmers
Post by: Mr.Slippery on October 03, 2005, 08:32:30 PM
Uhhh, that can't be right.

Weeks?? to solve a 20 city problem?

Is your computer "powered" by a treadwheel, revolving only by the sheer willpower of an elderly, arthritic hampster--as it negotiates the tricky wire slats with its custom-made walker??

(or, maybe I should finish coding my program...)  ;)
--Slip :alien:  


Title: The Gathering of Programmers
Post by: Mr.Slippery on October 03, 2005, 10:34:09 PM
Quote
I've worked it out with 4 and 5 cities.
but the problem is that I don't think that my technique works when there are more cities...
the only way for me to see if mine works is for someone to make the program as the instructor suggested (the brut force way), even if that person has to be me if everyone wants to be punks and not show in the forum <_<

My technique works by starting at one city and fallowing the shortest path to all adjacent cities.  Here’s the problem, it doesn't look far ahead, and there are paths that are shorter overall.  I tried to overcome some of this by starting anew at every city, but this only helps, not fixes the problem.
great graph, Smi!!

Looks vaguely familiar, as if in a dream, in a Dungeon, spoken in the foreboding voice of the D.ungeon M.aster...

Well, actually those Red paths are looked at, but not in that particular part of the graph. So C-D and C-E are either taken or looked at, but they were rejected at that particular point in the sequence.
I know what you're talking about, tho.
--Slip  :alien:  


Title: The Gathering of Programmers
Post by: smi256 on October 03, 2005, 11:24:44 PM
Quote
Well, actually those Red paths are looked at, but not in that particular part of the graph. So C-D and C-E are either taken or looked at, but they were rejected at that particular point in the sequence.
I know what you're talking about, tho.
--Slip  :alien:
True, but they were only looked at once.  I like graphs :hehe:

I recalculated things.  I found that it takes about 4.8E-6 seconds to make a complete path, which brings my 15 city test to 4.8 days to complete. <_<   That brings my 20 city test to 2,700 years. :blink:   However!!  I added a little bit of code saying, “if the current running total is more then the current shortest path, don’t continue down that path!”  Having said this, my 5 day runtime went down to 24 seconds!!! :o  :D

There is no real way for me to calculate the amount of time my program will take to complete, but if my program goes at it’s current rate it’ll take about 9 hours. :cool: It finished in 55 minutes :cool:

Time to work on that other HW.  
Quote
yeah, increment pointers rather than array indices. Messy-er,
but gotta practice pointer stuff.
Just one of the search programs? :sheep:

[edit]
Speaking of which, Java HW is Page 283 #6.30.  Don’t forget your  :)/:(  faces!


Title: The Gathering of Programmers
Post by: Mr.Slippery on October 04, 2005, 02:13:51 AM
Quote
I recalculated things.  I found that it takes about 4.8E-6 seconds to make a complete path, which brings my 15 city test to 4.8 days to complete. <_<   That brings my 20 city test to 2,700 years. :blink:   However!!  I added a little bit of code saying, “if the current running total is more then the current shortest path, don’t continue down that path!”  Having said this, my 5 day runtime went down to 24 seconds!!! :o  :D

There is no real way for me to calculate the amount of time my program will take to complete, but if my program goes at it’s current rate it’ll take about 9 hours. :cool: It finished in 55 minutes :cool:

Time to work on that other HW. 
[Just one of the search programs? :sheep:

Speaking of which, Java HW is Page 283 #6.30.  Don’t forget your  :)/:(  faces!
Smi,
Werry impwessive.
That's a nice optimization.
What is the final time for 20-cities?

Yeah, I believe that the pointer-array stuff applies to all 3 sort methods. (hah, since I put all 3 sort functions into 1 prog, that'll save me some time. (and I need time, all the time!)

We are all just  :sheep: in the world.

Except for me, of course. I'm an  :alien:
--Slip


Title: The Gathering of Programmers
Post by: smi256 on October 04, 2005, 07:08:18 AM
Damn, I can’t seem to get a counter working.
I have it set up to count the number of paths that have been ‘searched’
When a path has reached full circle then, paths++
Depth is the number of cities that have already been added to the current path.
When the current path length is greater then the shortest path then, paths+= factorial (number_of_cities-Depth-1);
When I go to print the percentage then, printf("%3.2f%c ",((float)paths*100/TotPaths),37);
I sometimes get a number that’s too small, and other times one that’s too big… I don’t know why is doesn’t work. :(

Btw, my program now takes 30minutes to find the shortest path with 20 cities. :D  


Title: The Gathering of Programmers
Post by: Guest on October 04, 2005, 09:04:14 AM
Quote
Btw, my program now takes 30minutes to find the shortest path with 20 cities. :D
That's a bit better than 2,700 years, ya' think?

I guess, you'll have to rename your program now to PizzaDriver.exe
(30 minutes or it's FREE!)

--Slip  :alien:

p.s. at least your program runs.


Title: The Gathering of Programmers
Post by: Guest on October 04, 2005, 09:15:30 AM
Quote
--Slip  :alien:

p.s. at least your program runs.
Could you perhaps loan me your hamster? :(
--Slip  :alien:  


Title: The Gathering of Programmers
Post by: Guest on October 04, 2005, 02:51:12 PM

Hi Peter,

It is the first time I read and knew how to post reply here. Mine travelling salesman seems to be good to me. He works fast, but sometimes, he gives me the negative tour.   :rolleyes: My point is that: can we wrok on the same program? That case, more people are interested in signing up. As you know, people here seem to be busy and stress all the time with their living. You just say that you have problem and people cannot have a look at your code, they cannot say anything. Maybe they can tell you that theirs work better or worse.

Anyway, you are working hard and doing good job. :)

Thank you for the link.
 


Title: The Gathering of Programmers
Post by: smi256 on October 04, 2005, 09:02:48 PM
Quote
/*******************************************
 * Name:              Peter Kaminsky
 * Course:            Adv. C
 * Assingment:        Traveling Salesman
 * Compiler:          Div-C++
*******************************************/
#include <stdio.h>
#include <math.h>
#include <time.h>
//#define PERCENT  //doesn't work corrently
#define SPIN       //doesn't refresh enough when there are too many cities
void starter(int array[][], int size_of_array, long long int TotPaths);
void depth  (int array[][], int size_of_array, intCol, intTot, char string[],
                            char Min_Path[], int *Min_Length,
                            long long int TotPaths, int Depth);
long long factorial (long long n);
FILE *f;
int step=1;

main()
char meh;
/*
   #define ASIZE 5
   int a[][ASIZE]={ { 0,29, 5,20,15},
                    {29, 0,42,24,35},
                    { 5,42, 0, 8,38},
                    {20,24, 8, 0, 4},
                    {15,35,38, 4, 0} };
*/
/*
   #define ASIZE 10
   int a[][ASIZE]={ { 0,30,39,24,11,27,30,26, 3,31},
                    {30, 0,11, 3,36,32,20, 1,48,50},
                    {39,11, 0, 7,41,50,13,34, 9,12},
                    {24, 3, 7, 0,31,31,46,24,25,23},
                    {11,36,41,31, 0,29,12,10,28,34},
                    {27,32,50,31,29, 0,47,15, 8,42},
                    {30,20,13,46,12,47, 0, 2,22, 3},
                    {26, 1,34,24,10,15, 2, 0,10,10},
                    { 3,48, 9,25,28, 8,22,10, 0,20},
                    {31,50,12,23,34,42, 3,10,20, 0} };
*/
/*
   #define ASIZE 13  //has two paths!
   int a[][ASIZE]={ { 0,37, 6, 7,14,32,34,37,31, 7,42, 8,14},
                    {37, 0,35,14,46,47, 6,44, 3,17,28,39, 8},
                    { 6,35, 0,14,41,23,12,35, 3,28,25,45,50},
                    { 7,14,14, 0,33,21,24,27,23,16,29, 2,45},
                    {14,46,41,33, 0, 7,46,42,14,19,43, 7, 3},
                    {32,47,23,21, 7, 0,25,40,37,36,26,48,44},
                    {34, 6,12,24,46,25, 0, 7,44,31,23, 6,33},
                    {37,44,35,27,42,40, 7, 0,10,29,25,44, 7},
                    {31, 3, 3,23,14,37,44,10, 0,35,34, 8,10},
                    { 7,17,28,16,19,36,31,29,35, 0,14,25,11},
                    {42,28,25,29,43,26,23,25,34,14, 0,19,47},
                    { 8,39,45, 2, 7,48, 6,44, 8,25,19, 0,39},
                    {14, 8,50,45, 3,44,33, 7,10,11,47,39, 0} };
*/

   #define ASIZE 15
   int a[][ASIZE]={ { 0,12,38,44,47,23,33,13,13,39,50,33, 7,20,29},
                    {12, 0,31,27,21, 6,10,36,19,40,13,12, 1, 2,25},
                    {38,31, 0,39,14,39,32,23,47,25,10, 7,40, 4,25},
                    {44,27,39, 0,12,50,12, 9,35,38,19,42, 8, 7, 6},
                    {47,21,14,12, 0,11,32,23,29,42,29,26,48,25,25},
                    {23, 6,39,50,11, 0,28,46,10,44,40,40, 4,16,19},
                    {33,10,32,12,32,28, 0,20, 6,35,42, 6,37, 3,29},
                    {13,36,23, 9,23,46,20, 0,48,19,45,28,27, 9, 3},
                    {13,19,47,35,29,10, 6,48, 0,36, 4,29,19,16,22},
                    {39,40,25,38,42,44,35,19,36, 0,14,18,40, 4,36},
                    {50,13,10,19,29,40,42,45, 4,14, 0, 9,18, 6,32},
                    {33,12, 7,42,26,40, 6,28,29,18, 9, 0,36, 4,33},
                    { 7, 1,40, 8,48, 4,37,27,19,40,18,36, 0,46, 2},
                    {20, 2, 4, 7,25,16, 3, 9,16, 4, 6, 4,46, 0,25},
                    {29,25,25, 6,25,19,29, 3,22,36,32,33, 2,25, 0} };

/*
   #define ASIZE 20
   int a[][ASIZE]={ { 0,12,40,37,18,15, 5,17,49,11, 4,40,18,46,37,25,14,40,30,44},
                    {12, 0,32, 5,47,48,21,29,45,31,16, 4,44,22,31,18,47,14,50,24},
                    {40,32, 0,11,37,41,49,14,29,41,23,20,42,41,14,46,47,28,41,19},
                    {37, 5,11, 0,37,30,40,47,19, 1,21,40, 6,12, 6,42,14,24,13, 7},
                    {18,47,37,37, 0,29,21, 8,34, 9,18,37, 1,42,45, 2,48,48,11,25},
                    {15,48,41,30,29, 0,20,38,33,22,12,11,47,14,26, 9,22, 2, 7,27},
                    { 5,21,49,40,21,20, 0, 4,42,39,13,21,19,11,38,47,13,20,45,43},
                    {17,29,14,47, 8,38, 4, 0,21,38,36,43,30,47,49,35,27,20,47,20},
                    {49,45,29,19,34,33,42,21, 0,23, 5,27, 3,23,14, 7,18,44,49,25},
                    {11,31,41, 1, 9,22,39,38,23, 0, 6, 9,16,24,29, 6,11,37, 3, 4},
                    { 4,16,23,21,18,12,13,36, 5, 6, 0,27,28,39,33,50,45,50,14,35},
                    {40, 4,20,40,37,11,21,43,27, 9,27, 0, 3, 7,29, 9,36,33,11,48},
                    {18,44,42, 6, 1,47,19,30, 3,16,28, 3, 0,40,19, 9,23,18,49,22},
                    {46,22,41,12,42,14,11,47,23,24,39, 7,40, 0,33,39, 4, 7,22,35},
                    {37,31,14, 6,45,26,38,49,14,29,33,29,19,33, 0,12,48, 7,44,17},
                    {25,18,46,42, 2, 9,47,35, 7, 6,50, 9, 9,39,12, 0, 6, 1,36,22},
                    {14,47,47,14,48,22,13,27,18,11,45,36,23, 4,48, 6, 0,34,31,34},
                    {40,14,28,24,48, 2,20,20,44,37,50,33,18, 7, 7, 1,34, 0,16, 3},
                    {30,50,41,13,11, 7,45,47,49, 3,14,11,49,22,44,36,31,16, 0,34},
                    {44,24,19, 7,25,27,43,20,25, 4,35,48,22,35,17,22,34, 3,34, 0} };
*/
   int i, j, size=sqrt((sizeof(a)/sizeof(int)));
   printf("Cities: %d\n",size);
   printf("Segments between cities: %d\n",((size*size-size)/2)); //cities choose 2
   long long int TotPaths=factorial(size-1);
   printf("Posible paths: %.0f\n", (float)TotPaths);
   long int startT=clock(); //start timer
   starter(a,size,TotPaths);//call function
   long int stopT=clock();  //stop timer
   printf("%c\nSearch Time: %.2f Seconds",13,(float)(stopT-startT)/CLK_TCK);
   printf("\n\nPress a key to close this window.");
   meh=getch();
}//end main()

void starter(int a[][], int size, long long TotPaths)
int minlen=0;
   char minpath[100]={};
   depth  (a, size, 0, 0, "A", minpath, &minlen, TotPaths, 0);
   printf("%cThe shortest path has a length of %d\n",13,minlen); //Print the Total Length
   printf("All of the shortest (directional) paths are:\n\n");
   /*Print the Paths*/
   f=fopen("minTemp.txt","r");
   while(fgets(minpath,size,f)!=NULL)
      fputs(minpath,stdout);
   fclose(f);
}//end starter()

void depth (int a[][ASIZE], int size,   int Old_Col, intTot, char Old_Str[],
            char minpath[], int *minlen, long long int TotPaths, int Depth)
int i, j, row=Old_Col, col, stop=1;
   static long long int paths=0;
   char string[100]={}, sub[0]={};  /**  create a new private string for the path  **/
   strcpy(string,Old_Str);          /**  copy the old path to the new string       **/
   sprintf(sub,"%c",Old_Col+65);    /**  find new city letter                      **/
   if(strrchr(string,sub[0])==NULL) /**  don't double-up on the print command      **/
      strcat(string,sub);           /**  add the new city to the new string        **/
   a[Old_Col][Old_Col]=-1;                //came from this city, can't go back to it
/************************************//// start end-of-the-line block
/**/   for(i=0; i<size; i++)              //check for the end-of-the-line
/**/      if(a==0)
/**/         stop=0;
/**/   if(stop==1)                        //if this IS the end-of-the-line
/**/   {  Tot+=a[0][Old_Col];             //go back to city 'A'
          #ifdef PERCENT                  //switch the printing of the % on/off
/**/      paths++;                        //the number of paths already taken
/**/      printf("%c%3.2f%c  ",13,((float)paths*100/TotPaths),37);
          #endif          //there is something wrong with paths count
          #ifdef SPIN                     //switch the spining thing on/off
/**/      switch(step)                    //because... I can
/**/      {  case 1: { printf("%c\\",8); step=2; break; }// this needs to go more often,
/**/         case 2: { printf("%c|",8);  step=3; break; }// when there are more cities
/**/         case 3: { printf("%c/",8);  step=4; break; }// it doesn't get
/**/         case 4: { printf("%c-",8);  step=1; break; }// triggered enough
/**/      }
          #endif
/**/      if( (Tot==*minlen) )                    //store current "minpath" to a file
/**/      {  f=fopen("minTemp.txt","a");          //and other "minlen" paths
/**/         fprintf(f,"%s\n",string);            //
/**/         fclose(f);                           //when there is a new "minpath"
/**/      }                                       //start the file over again
/**/      if( ((*minlen==0) || (Tot<*minlen)) )   //
/**/      {  *minlen=Tot;                         //at the very end,
/**/         strcpy(minpath,string);              //print the real shortest paths
/**/         f=fopen("minTemp.txt","w");          //from the file
/**/         fprintf(f,"%s\n",string);            //
/**/         fclose(f);                           //
/**/      }                               
/**/   }
/************************************//// end end-of-the-line block
   for(col=0; col<size; col++)            //step through all unvisited cities
   {  if( a[col][col]!=-1 )               //continue if the current length is shorter
      {  if(((Tot+a[row][col])<*minlen) || *minlen==0)
         {  depth(a,size,col,Tot+a[row][col],string,minpath,minlen,TotPaths,++Depth);
            a[col][col]=0;                //this city is now back 'open'
            Depth--;                      //came back a level
         }
         #ifdef PERCENT                   //switch the printing of the % on/off
         else  //something is wrong with paths count
         {  paths+=( factorial(size-Depth-1) ); //this should be the number of paths that
         }     //would have been searched through but weren't because the current path
         #endif//was longer then the current "shortest path"
      }
   }
}//end depth()

long long factorial(long long n)          //a "long long" O_o? crazy
if(n==1)
      return(1);
   else
      return(n * factorial(n-1));
}


Title: The Gathering of Programmers
Post by: Mr.Slippery on October 04, 2005, 11:15:13 PM
Hmmm, Smi.

Looks complicated.   :unsure:

Here are some more thoughts (to further complicated/simplify the tour logic):

The algorithm should have some penalty in not going in a straight line (or large circle).
That is, there should be some bias given to paths that are
approximately in the same direction (in successive moves). I don't
know how to do it yet, but I think it involves taking the cosine or
sine of two successive paths and encoding them into a matrix. Then,
not only the length of the nearest city but it's straightness along
your current path helps the salesman decide where to go.

In the ideal case, you would start in a straight line and move from
one end to the other. In another case, all cities are arranged in a
circle with very little arc (sine penalty) between cities.

--Slip  :alien:


Title: The Gathering of Programmers
Post by: smi256 on October 04, 2005, 11:24:56 PM
:miffed: I don't understand :(  


Title: The Gathering of Programmers
Post by: smi256 on October 16, 2005, 12:23:36 AM
I think this is a crap problem, not just because it’s very poorly worded, it’s just lame.
Quote
7.10) Sales Commissions
Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000, or a total of $650. Write an application (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson’s salary is truncated to an integer amount):
     a) $200-299
     b) $300-399
     c) $400-499
     d) $500-599
     e) $600-699
     f) $700-799
     g) $800-899
     h) $900-999
     i) $1000 and over
Summarize the results in tabular format.

The part that I have a problem with is the,
“Write an application that determines how many of the salespeople earned salaries in each of the following ranges:”

I’m thinking it should read,
“Write an application that determines how much a salesperson would earn with a gross sale in each of the following ranges:”

Or even to the effect of,
“Write an application that determines how much a salesperson’s gross sale was, based on their salary based on the following ranges:”

I’m either reading it wrong or there is a certain amount of ambiguity here <_<

[edit/add]

It was suggested to me that the user is supposed to enter the gross sales for each salesperson (however many the user chooses to enter).  When the user is done, print a table of how many salespeople fall into a particular bin (the ranges given in the problem)

Ya… I think that makes more sense :sheep:


Title: The Gathering of Programmers
Post by: smi256 on October 19, 2005, 10:15:23 PM
Adv. C HW
(Due the first of Nov.  Expect more HW on the 25th)

1)  Print the contents of a link list in reverse order

2)  Research how link lists are useful in text editors (concepts, not code)

3)  Use link lists to add and multiply (fourth order) polynomials
      a)  Both polynomials should have all of its orders
      b)  One polynomial should have all of its orders


I wonder if anyone reads this? :hmmm:  


Title: The Gathering of Programmers
Post by: SS on October 20, 2005, 01:17:34 PM
I read it! :D


(link lists are the same as linked lists, right?)


Title: The Gathering of Programmers
Post by: smi256 on October 20, 2005, 08:01:42 PM
link list==linked list ? printf("I thought so") : printf(" oops :blink: my bad");

mayeb I should work on and finish that Knight's Tour problem....
I don't know how to make it GUI though, I could just as well do it in the MS-DOS window...in which case I'd just do it in C!!
or just print the movements A1, B3 sort of thing...


Title: The Gathering of Programmers
Post by: smi256 on November 01, 2005, 02:05:38 AM
Oh YES!
*CHARGING*
CLEAR!!
*ZAP*
 :sheep:
Well… not really, but seeing that my code takes 6 pages 8 pages (+2 for screenshots) (I couldn't fit as many lines as I thought on one page)[/size] to print it would have been a big post.  However, I did find the Export option on my compiler, so I exported it to html and added a little bit to it (my screen shots).  

Oh right, what the hell is the assignment?  
The assignment was to:
Add two full fourth order polynomials
(I’m saying “full polynomial”, I just mean that there are no gaps in the polynomial powers, ex 1x^4 + 1x^3 + 1x^2 + 1x^1)
Multiply two full fourth order polynomials
Add one full and one NOT full polynomial
Multiply one full and on NOT full polynomial
Oh ya, did I mention that this is to be done ALL with linked lists? No? Well, they are!

Here it is.
Project Polynomial Index (http://home.ripway.com/2005-9/438358/Polynomial%20web/poly.htm)

Could some please tell me why I’m getting those errors.   :unsure:


Title: The Gathering of Programmers
Post by: Mr.Slippery on November 02, 2005, 08:36:45 AM
Quote
Oh YES!
*CHARGING*
CLEAR!!
*ZAP*
 :sheep:
Well… not really, but seeing that my code takes 6 pages 8 pages (+2 for screenshots) (I couldn't fit as many lines as I thought on one page)[/size] to print it would have been a big post.  However, I did find the Export option on my compiler, so I exported it to html and added a little bit to it (my screen shots). 

Oh right, what the hell is the assignment? 
The assignment was to:
Add two full fourth order polynomials
(I’m saying “full polynomial”, I just mean that there are no gaps in the polynomial powers, ex 1x^4 + 1x^3 + 1x^2 + 1x^1)
Multiply two full fourth order polynomials
Add one full and one NOT full polynomial
Multiply one full and on NOT full polynomial
Oh ya, did I mention that this is to be done ALL with linked lists? No? Well, they are!

Here it is.
Project Polynomial Index (http://home.ripway.com/2005-9/438358/Polynomial%20web/poly.htm)

Could some please tell me why I’m getting those errors.   :unsure:
Your next assignment is to integrate the Zero Wing game graphics into your Java program for teaching Multiplication to children:

"MAIN SCREEN TURN ON"

     What is the answer to 6 x 7 ?
[ummm, 67?]

WRONG!! ANSWER!! <YOU KNOW WHAT YOU DOING??>
     Try again: What is 6 x 7?
[uhh, 76?]

WRONG AGAIN!! <YOU HAVE NO CHANCE TO SURVIVE MAKE YOUR TIME>

and so on...

--Slip :alien:  


Title: The Gathering of Programmers
Post by: smi256 on November 03, 2005, 10:25:59 PM
I'm glad you like that Slip :P

Things I should add to my polynomial program:
  • De-allocate my linked lists at the end of the program:
    • From the main: poly1, poly2, sum, prod…
      [li]From other functions free up set individual links to NULL at the end of the function: current, preS, preC, slot…
    [li]Add special cases to the print function:
    • If the coefficient is zero, then don’t print that term
      [li]If the power is zero, then only print the coefficient
      [li]If the power is one, then print the coefficient and the variable


Title: The Gathering of Programmers
Post by: Mr.Slippery on November 04, 2005, 03:27:13 AM
Quote
I'm glad you like that Slip :P

What i'd really like is for you to find a way to make your AYBABTU animation run only once, then hold at a specifc graphic image. think u can do it?
(fortunately, my Firefox setup can disable animated graphics, but... whew! eyestrain.)

-Slip  :alien:  


Title: The Gathering of Programmers
Post by: smi256 on November 04, 2005, 07:01:26 AM
I didn't make the image...I stole it.  I don't know how to make animated gif files...mostly because I’ve never really cared to find out


Title: The Gathering of Programmers
Post by: snowinferno on November 06, 2005, 12:11:05 PM
Quote
Could some please tell me why I’m getting those errors.   :unsure:
I think in your POLY struct if you change
struct POLY * next;
to
POLY * next;
it will get rid of a bunch of those errors warnings...
if that causes it to not even run, then look through configuration/preferences and turn the warning level down.
It seems to think that a "struct POLY*" is incompatible with "POLY *" :blink: .


Title: The Gathering of Programmers
Post by: snowinferno on November 06, 2005, 12:44:30 PM
Quote
Things I should add to my polynomial program:
  • De-allocate my linked lists at the end of the program:
    • From the main: poly1, poly2, sum, prod…
      [li]From other functions free up individual links at the end of the function: current, preS, preC, slot…
I should have put this in the other post but its late, and i've been working on java homework :o
you really don't want to free the individual links...
*gets out a soapbox, steps up and begins a speach*
since you dont copy the contents of the struct around, freeing up your current, preS, preC, etc... at the end of those functions will "inadvertently" free up the node in your linked list, then if you go and try to free up your list, you'll get heap overflow... returning more memory than you were allocated.
The best option for your other functions is to set the current, preS, preC, etc... pointers null as the last thing you do in the function.
*takes a bow, picks up the soapbox and puts it away*
 :ph34r:


Title: The Gathering of Programmers
Post by: smi256 on November 06, 2005, 09:03:10 PM
Thanks snowinferno!
In java I haven’t read about “throws Exception” stuff yet.  But what I have done is found a few little ways around the whole situation

One, if you have a known list of options, only let those options be chosen:
Quote
public static Object showInputDialog
(  Component parentComponent,
   Object message,
   String title,
   int messageType,
   Icon icon,
   Object[] selectionValues,
   Object initialSelectionValue
)
Quote
JOptionPane.showInputDialog(null,"Message","Title",3,null,inputOptions,null);
Note: this doesn’t work with switch, use a large if, else if, else if block


When asking the user to input a number:
Quote
public boolean stringIsDigits(String input)
{  boolean result=true;
   char test[] = input.toCharArray();
   for(int i=0; i<test.length; i++)
   {   if(result==true)
      {   result=Character.isDigit(test);
      }
   }
   return (result);
}//end stringIsLettersOrDigits


Title: The Gathering of Programmers
Post by: smi256 on November 07, 2005, 07:12:24 AM
My Part 5 for Java :)
I really need to learn Exception Handling  :rolleyes:
Quote
 /***********************************************
 * Name:              Peter Kaminsky
 * Course:            CIS 43 Java
 * Assingment Number: #6
 * Assingment:        Getting started with OOP
 * Compiler:          JCreator
 ***********************************************/
package Kaminsky.Peter.Bank;
public class BankAccount //extends object
{  private int balance;
   private int totalWithdraw;
   private int totalDeposit;
   private String accountHistory;
   private String accountSummary;
   private String userName;
   
   public BankAccount()
   {  balance = 0;
      totalWithdraw = 0;
      totalDeposit = 0;
      accountHistory = "";
      userName = "";
   }
   public void deposit(int amount)
   {  balance += amount;
      totalDeposit += amount;
      accountHistory += String.format("deposit            %,7dn",amount);
   }
   public void withdraw(int amount)
   {  balance -= amount;
      totalWithdraw -= amount;
      accountHistory += String.format("withdraw          %,7dn",amount);
   }
   public void setUserName(String name)
   {  userName=name;
   }
   public int getBalance()
   {  return balance;
   }
   public int getTotalWithdraw()
   {  return totalWithdraw;
   }
   public int getTotalDeposit()
   {  return totalDeposit;
   }
   public String getAccountHistory()
   {  return accountHistory;
   }
   public String getAccountSummary()
   {  accountSummary  = String.format("Deposits       %,7dn",totalDeposit);
      accountSummary += String.format("Withdrawals    %,7dn",totalWithdraw);
      accountSummary += String.format("......................n");
      accountSummary += String.format("Balance       $%,7d",balance);
      return accountSummary;
   }
   public String getUserName()
   {  return userName;
   }
}
Quote
/***********************************************
 * Name:              Peter Kaminsky
 * Course:            CIS 43 Java
 * Assingment Number: #6
 * Assingment:        Getting started with OOP
 * Compiler:          JCreator
 ***********************************************/
import Kaminsky.Peter.Bank.BankAccount;
import Kaminsky.Peter.Check.Strings;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import java.awt.Font;
import java.awt.Color;
//import java.lang.Character;
//import java.lang.String;
public class UseBankAccount
{  public static void main (String[] args)
   {  Strings check = new Strings();
      BankAccount account = new BankAccount();
      JTextArea outputArea = new JTextArea();
         outputArea.setFont(new Font("Courier New", Font.BOLD, 13));
         outputArea.setBackground(null);
      String inputS, message;
      int inputI=0;
      Object answer;
      String inputOptions[] = {"Deposit", "Withdraw", "Account History",
                              "Account Summery", "New Account", "Exit"};
      //public static Object showInputDialog   (Component parentComponent,
      //                                       Object message,
      //                                       String title,
      //                                       int messageType,
      //                                       Icon icon,
      //                                       Object[] selectionValues,
      //                                       Object initialSelectionValue)
      //                              throws HeadlessException
      //Page 515
      //PLAIN_MESSAGE       = -1
      //ERROR_MESSAGE       =  0
      //INFORMATION_MESSAGE =  1
      //WARNING_MESSAGE     =  2
      //QUESTION_MESSAGE    =  3
      do
      {  account.setUserName(JOptionPane.showInputDialog(null,
                              "What is your name?","New Account",3));
      }while(account.getUserName()==null);
      do
      {  message  = String.format("Welcome %s!n", account.getUserName());
         message += String.format("Your Balance: $%,dnn", account.getBalance());
         message += "Please make a selection:";
         answer = JOptionPane.showInputDialog(null, message, "Bank-O-Pete", 3,
                                              null, inputOptions, null);
         if(answer == "Deposit")
         {  //System.out.println("Deposit");
            do
            {  do
               {  inputS = JOptionPane.showInputDialog(null,
                           "How much is to be deposited?", "Deposit",3);
                 
               }while(check.stringIsDigits(inputS)==false);
               inputI=Integer.parseInt(inputS);
            }while(inputI<0);
            message = String.format("Deposited:  $%,d",inputI);
            JOptionPane.showMessageDialog(null, message, "Deposit", -1);
            account.deposit(inputI);
         }
         else if(answer == "Withdraw")
         {//   System.out.println("Withdraw");
            do
            {  do
               {  inputS = JOptionPane.showInputDialog(null,
                           "How much to withdrawal?", "Withdraw",3);
                 
               }while(check.stringIsDigits(inputS)==false);
               inputI=Integer.parseInt(inputS);
            }while(inputI<0);
            if(inputI>account.getBalance())
            {  message  = "I'm sorry. You can't take more then what you have.nn";
               message += String.format("You'r withdrawal  $%,dn",inputI);
               message += String.format("Balance  $%,dn",account.getBalance());
               JOptionPane.showMessageDialog(null, message, "Withdraw", -1);
            }
            else
            {  message = String.format("Withdrawal:  $%,d",inputI);
               JOptionPane.showMessageDialog(null, message, "Withdraw", -1);
               account.withdraw(inputI);
            }
         }
         else if(answer == "Account History")
         {  //System.out.println("Account History");
            message  = account.getAccountHistory();
            message += "n______________________n";
            message += account.getAccountSummary();
            outputArea.setText(message);
            JOptionPane.showMessageDialog(null, outputArea, "Account History", -1);
         }
         else if(answer == "Account Summery")
         {  //System.out.println("Account Summery");
            message = account.getUserName() + "'s Account Summery";
           
            outputArea.setText(account.getAccountSummary());   
           
            JOptionPane.showMessageDialog(null, outputArea, message, -1);
            //System.out.println(account.getAccountSummary());
         }
         else if(answer == "New Account")
         {  //System.out.println("New Account");
           
            //public static int showConfirmDialog   (Component parentComponent,
            //                                       Object message,
            //                                       String title,
            //                                       int optionType,
            //                                       int messageType)
           
            inputI = JOptionPane.showConfirmDialog(null,
                        "Are you sure you want to make a new Account?",
                        "Confirm New Account", 0, 2);
            //System.out.println(inputI);
            if(inputI==0)
            {  account = new BankAccount();
               do
               {  account.setUserName(JOptionPane.showInputDialog(null,
                                       "What is your name?","New Account",3));
               }while(account.getUserName()==null);
            }
         }
         else if(answer == "Exit")
         {  //System.out.println("Exit");
            inputI = JOptionPane.showConfirmDialog(null,
                        "Are you sure you want to Exit?",
                        "Confirm Exit", 0, 2);
            if(inputI!=0)
               answer = "";
         }
      }while(answer != "Exit");
   }//end main
}//end class UseBankAccount
Quote
package Kaminsky.Peter.Check;

public class Strings

   public boolean stringIsLetters(String input)
   {  boolean result=true;
      char test[] = input.toCharArray();
      for(int i=0; i<test.length; i++)
      {  if(result==true)
         {  result=Character.isLetter(test);
         }
      }
      return (result);
   }//end stringIsLettersOrDigits
   
   public boolean stringIsDigits(String input)
   {  boolean result=true;
      char test[] = input.toCharArray();
      for(int i=0; i<test.length; i++)
      {  if(result==true)
         {  result=Character.isDigit(test);
         }
      }
      return (result);
   }//end stringIsLettersOrDigits
   
}


Title: The Gathering of Programmers
Post by: smi256 on November 07, 2005, 07:15:22 AM
:o I can not edit my post ;)
[correction]
that last file is named Strings.java  


Title: The Gathering of Programmers
Post by: Guest:blackmail on November 08, 2005, 11:10:15 PM
O o. A lot of new things happened on the Forum. Gggggggggggggggggrrrrrrrrrrrrrrrr. I needed to know it before.


Title: The Gathering of Programmers
Post by: smi256 on November 09, 2005, 08:37:13 AM
I told you!! Didn't I tell you?? Well I did.
 :P
You have untill tomorrow afternoon to get it done.  remember, you don't have to make it GUI.

PS. normaly people who have an account, login then post :rolleyes:


Title: The Gathering of Programmers
Post by: Mr.Slippery on November 11, 2005, 10:17:43 PM
Quote
I told you!! Didn't I tell you?? Well I did.
 :P
You have untill tomorrow afternoon to get it done.  remember, you don't have to make it GUI.

PS. normaly people who have an account, login then post :rolleyes:
Huh?  :blink:

Hoo r u ranting to?
--Slip  :alien:  


Title: The Gathering of Programmers
Post by: smi256 on November 12, 2005, 03:57:43 AM
To Blackmail

BTW!! WTF?!  You didn't go to either class this week.  The class you did go to you walked back out.....
What's up with that, Slip? ;)  


Title: The Gathering of Programmers
Post by: Mr.Slippery on November 13, 2005, 10:56:56 AM
Quote
To Blackmail

BTW!! WTF?!  You didn't go to either class this week.  The class you did go to you walked back out.....
What's up with that, Slip? ;)
Time is not a constant; it's a very flexible medium...
Therefore, I merely had to approach the campus--even hours after it was over--and the class materials were automatically downloaded into my notebook. Amazing.

Then, I realized that I had done this sometime before. Hmm, so this is actually review material, in a way. Then, I woke up and realized it was all just a bad dream, and I hadn't actually registered for this semester.

Then I woke up from that dream with a smile, because I realized it was true.
--Slip


Title: The Gathering of Programmers
Post by: Mr.Slippery on November 28, 2005, 01:26:54 AM
So is everyone else finished with their Java problems #7 and #8?
Yeah, I thought so.

one question: did you modify all of the source files for the payroll program (Hmwk #7) and print them out to hand in? Or did you just show the modified output? I'm curious, cuz it's a lot of source code to print!

(Looks like I need another THanksgiving holiday to catch up.)
--Slip


Title: The Gathering of Programmers
Post by: smi256 on November 28, 2005, 10:09:22 PM
I had to mod every source file, and I printed every source file...
and yes, I did finish 8 :)  


Title: The Gathering of Programmers
Post by: Mr.Slippery on December 01, 2005, 09:54:08 AM
Quote
I had to mod every source file, and I printed every source file...
and yes, I did finish 8 :)
Ah, that's what I thought. Also, that is what Dung did in her version.

In my version, I kept the 3-input constructor(params) the same, and
simply created a data object in the constructor that would be updated
later in the main() program. That way, I didn't have to change the
constructor type in all the different employee classes. See below code
example:
Code:
// in Employee.java:
      // three-argument constructor
      public Employee( String first, String last, String ssn )
      {
            firstName = first;
            lastName = last;
            socialSecurityNumber = ssn;
            birthDate = new Date();            //WGG creates NULL date object
      } // end three-argument Employee constructor

// in PayrollSystemTest.java:
            employees[3].setBirthday( new Date(2,22,1904) );      // update birthdate


It seemed simpler that way. (it's rare when I choose the simpler path,
btw)
--Slip


Title: The Gathering of Programmers
Post by: smi256 on December 01, 2005, 10:02:11 AM
That's an interesting way of doing it.  I have no idea why that shouldn't be acceptable.  In this way however you would have to remember to setBirthday in the main for every single employee after the fact, instead of when you're inputting the rest of the employee's data.

I think that the main should be the flow of the program, so I try to have the nitty-gritty stuff in functions (in this case, methods)
But since when do I listen to my own advice?
 :sheep:  


Title: The Gathering of Programmers
Post by: smi256 on December 08, 2005, 06:41:34 AM
I have a C programming question...
Lets say that I already have some stuff printed to the consol.  But I want to back and change something up there.  I'll keep it simple, I want to simply put a '*' as the first character of that printed line.
I can go back one character '\b'
I can go back to the beginning of the current line '\r'
I can go to the next line... '\n'
How do I go UP?


Title: The Gathering of Programmers
Post by: smi256 on February 19, 2006, 04:10:19 AM
Here’s me problem, I’m doing this assignment for Data Structures using Java class… I problem is that I need to have 10,000 elements so I can feed the sorting algorithms that we are coding.  I keep getting an error: “code is too long”.  
I’m using: int a[]={ … };
Should I be feeding my elements in using a file, or is there an easier way, like an array size workaround?  

I didn't have this problem with C  <_<  


Title: The Gathering of Programmers
Post by: smi256 on April 17, 2006, 05:59:53 AM
I managed to get my Java program up and running.  No GUI though.
It makes a binary tree it also uses an automated rotation thingy to make it a balanced tree.  I don’t know, it geeky... but I’m happy with it.  The only thing that I’m having trouble with is printing it out either in the command prompt or in GUI (preferred).  The thing is that I want to to look like a tree…
Quote

    *
   / \
  *   *
/ \ / \
* * * *