Yes I did reuse the variable just like you said and it never incremented. I’m not sure I understand exactly where this new code would go in the program. Thanks for the help so far, I think winter break killed the part of my brain that started learning how to code last semester.
Yeah this is exactly what we’ve tackled recently.
Sent from my SPH-D700 using Tapatalk 2
First, make sure you understand for loops.
Next, make sure you understand what happens when you insert a for loop inside of a for loop. That’s nested for loops.
After that, realize you’re doing a for loop, inside of a for loop, inside of a for loop. 3 Loops deep. Inception style. Make sure you can really understand what is going on, the flow of your program. Because I could easily post the solution, but what’s the point if you don’t actually fundamentally understand it?
(for (for (for (for (for (for (for loop) loop) loop) loop) loop) loop) loop)
Nightmares for days.
Mission accomplished
I usually love that moment where everything clicks for me but this one just made me feel like a idiot. Thanks for all the help.
I hate to say this, but I said my line of reasoning ought to come together knowing a good value, so I had to try just that.
And I get sum(1714 + 1715 + . . . + 2221) = 999490 while sum(1714 + 1715 + . . . + 2222) = 1001712
So I did the brute force. There are only 6 solutions, the first one of which is sum(1243 + 1244 + . . . + 1882)
It is true that for the range m…n n = ceiling(sqrt(m²+2*1,000,000) - 1), but I’m not seeing an obvious way to know whether a solution exists other than actually calculating (n)(n+1)/2 - (m-1)(m-1+1)/2 after that.
Yeah double check the solution. Post up your full program so we can spot any bugs
lol thanks guys for the response but i double checked the program already. The picture you see above was only meant to focus on the last 5 numbers. That picture is only a a cropped photo of the whole results.
There is a trick to lining those up by matching the parens on the next line. Really easy with tabs.
(for (for (for (for (for (for (for loop
) loop) loop) loop) loop) loop) loop)
Count up for each open paren, count down for each close paren. Should end back at zero.
1,2,3,4,5,6,7,6,5,4,3,2,1,0
Learned this when using LISP I think.
I was just messing around. I usually tab indent new evaluations.
I’m pretty sure I mentioned this earlier in the thread, but if you have to nest a for loop more than once, I would try rewriting the code. Multiple nested loops can get messy quickly.
Double for loops are basically the most inefficient way of doing something, but oftentimes the easiest. Triple for loops and above are pretty bad. For example, in the previous code, you could start generating your output string before you know if it is valid or not, and then if it is, just output the string instead of calculating it on the fly. That solved the third for loop.
But is it more efficient?
In 500,000 iterations, it’s only going to test positive like 6 times right? So you’re sacrificing a bit of time on each loop (concatenating a string and calling an integer to string conversion) just to save a third for loop. I think actually the for loop is more efficient, but it would depend most likely on the cost of each of the functions involved. One for loop being called 6 times, is better than millions of string conversion and addition calls. But you also don’t know that there is only 6 right answers, so you have to express it more abstractly, which is definitely cool and one of the things most interesting about computer science.
Like a debate I had with a friend over sorting. I implemented bubble sort, and he countered that its redundant because Quick Sort is the best. But I told him, I had a list with unknown length, and only needed the top 10 numbers. So I did a bubble sort, because if I get a list of 1,000,000 numbers sorting anything but the highest 10 is a waste, and bubble sort could actually be better. But then if a list of 20 numbers comes through, bubble sort will probably lose. It’s probably one of the only times I’d advocate implementing bubble sort over another sort.
However, one tip… my statement about only needing to search up to targetNum/2 because once you’re more than halfway, you’re always going to go over the target num? If you consider a single number to be a valid response, then the number 1,000,000 would be a solution that won’t be delivered by this algorithm. Clarify with your professor.
A new edition of Game Prototype Challenge is live. This event is open to anyone, even if you’re new to coding.
Everyone should check out http://store.steampowered.com/app/217860/ my first credited game is finally out! It’s pretty fun(despite the awful steam art).
Congrats on the release!
Congrats? What do you think of the game objectively?
I love how that one guy is pointing and it appears as though a bunch of people just blew up because of it.
Congratulations on getting on Steam.
It’s solid, but a little buggy(stuff that didn’t show up in internal testing). I generally have a lot of fun playing it, and I’ve never been a huge fan of third person/active cover games. It’s got a lot of weapons and weapon mods, some cool active/passive skills, the shooting mechanics are solid and controls are pretty tight. The maps are good as well and the “cool thing” the game does is let you swap out map tiles so it adds some variety to every game.
Right now biggest problem is it takes WAY too long to get the map started. Gives you 45 secodn to swap teams and gear in the main screen, and 35 seconds to vote fo rth emap tile and there’s no “ready” option to speed that up. So if a match goes really fast(high population death match) you have like 4-6 minute matches with 2 minute wait times in between.
Overall, the game is 15 bucks, I definitely think it’s worth that if you like the genre.
I made a game for Game Prototype Challenge, check it out.
I’m gonna see if I can fix the bugs because I just played my game again, and it’s starting to bug me (haha). If anyone knows Flash/ActionScript 3.0 and can help me out, it would be appreciated. I’ll even add your name in the credits.
Here’s the bug: I want to clear the screen of all elements after the game is reset. Currently, I’m doing this by emptying the vectors containing objects, and then removing the child object. This seems to work except the images representing the objects remain on the screen, but they don’t do anything. Here’s a bit of code I’m using in my ResetGame() function:
for each(var e:Enemy in enemyList)
{
removeChild(e);
enemyList.shift(); //removes the first element in a vector
}
That’s it. I have the same problem for any bullets that I want to remove. If I can figure out the issue for one set of objects, then I can fix the rest.
EDIT: Issue resolved. As usual, it was something completely dumb.
<font face=“Arial, Verdana” size=“2”><span style=“line-height: normal;”>Very interesting chapter on how easy it is to write a bug into a code, even as simple as binary search:</span></font><div><font face=“Arial, Verdana” size=“2”><span style=“line-height: normal;”>http://books.google.com/books?id=gJrmszNHQV4C&lpg=PA87&ots=rLOWuzQ4oe&dq=percentage+of+binary+search+is+implemented+incorrectly&pg=PA87#v=onepage&q&f=false</span></font><br></div><div><font face=“Arial, Verdana” size=“2”><span style=“line-height: normal;”><br></span></font></div><div><font face=“Arial, Verdana” size=“2”><span style=“line-height: normal;”>Don’t take details for granted.</span></font></div>