• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:09
CEST 03:09
KST 10:09
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL59Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event19Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
Program: SC2 / XSplit / OBS Scene Switcher Statistics for vetoed/disliked maps The SCII GOAT: A statistical Evaluation Weekly Cups (June 23-29): Reynor in world title form? PiG Sty Festival #5: Playoffs Preview + Groups Recap
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event RSL: Revival, a new crowdfunded tournament series Korean Starcraft League Week 77 Master Swan Open (Global Bronze-Master 2) [GSL 2025] Code S: Season 2 - Semi Finals & Finals
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Flash Announces Hiatus From ASL SC uni coach streams logging into betting site BGH Mineral Boosts Tutorial Video Player “Jedi” cheat on CSL Replays question
Tourneys
[Megathread] Daily Proleagues [BSL20] Grand Finals - Sunday 20:00 CET Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Trading/Investing Thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 703 users

The Big Programming Thread - Page 186

Forum Index > General Forum
Post a Reply
Prev 1 184 185 186 187 188 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
CarelessPride
Profile Joined March 2011
United States146 Posts
November 02 2012 02:53 GMT
#3701
On November 02 2012 11:28 simcaster wrote:
Show nested quote +
On November 02 2012 11:13 CarelessPride wrote:
Hey I just started taking classes in programming and I have a few questions:
1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games?

The vast majority of games license an engine. C++ is commonly used to design engines and lighter scripting languages like lua and python are used for everything else.
Show nested quote +
On November 02 2012 11:13 CarelessPride wrote:
2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch

It would take years and a large team to recreate a game of the quality of SC2 or D3.


How long would it take me to learn the skills needed to start?
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
November 02 2012 02:55 GMT
#3702
On November 02 2012 11:53 CarelessPride wrote:
Show nested quote +
On November 02 2012 11:28 simcaster wrote:
On November 02 2012 11:13 CarelessPride wrote:
Hey I just started taking classes in programming and I have a few questions:
1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games?

The vast majority of games license an engine. C++ is commonly used to design engines and lighter scripting languages like lua and python are used for everything else.
On November 02 2012 11:13 CarelessPride wrote:
2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch

It would take years and a large team to recreate a game of the quality of SC2 or D3.


How long would it take me to learn the skills needed to start?

In order to work on something of SC2 scale, at least 3 years. Realistically more like 4-7 in order to get a job as a C++ software engineer at one of those studios. These are assuming you're obtaining a Bachelor's degree in CS, and a really good one at that.
chaokel
Profile Blog Joined October 2010
Australia535 Posts
November 02 2012 03:12 GMT
#3703
On November 02 2012 11:13 CarelessPride wrote:
Hey I just started taking classes in programming and I have a few questions:
1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games?
2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch


As far as i'm aware almost all large commercial games are created in engines written primarily in C++ (with some delving down into assembly for further optimisation). A lot of companies lease these, due to the fact that creating a game engine will often cost as much if not more than what they pay to lease one, not to mention all the hassles that come with it, and the fact that it simply wont be as polished and bug free as one that has been worked on and patched for years. Though some games require a custom engine which once created can be either for solely personal use or designed in mind so that they can lease it out. A well known example of this would be the unreal engine made by epic, or cryengine developed by crytek.

Recreating any commercial game would take a lot of effort and time, something as polished (technically speaking, not balance) as starcraft and diablo would probably take a similar sized team around a few years (the main difficulty would be in recreating the game engine, which would need to be built from scratch to emulate the one blizzard has made.)

chaokel
Profile Blog Joined October 2010
Australia535 Posts
November 02 2012 03:20 GMT
#3704
On November 02 2012 11:55 CecilSunkure wrote:
Show nested quote +
On November 02 2012 11:53 CarelessPride wrote:
On November 02 2012 11:28 simcaster wrote:
On November 02 2012 11:13 CarelessPride wrote:
Hey I just started taking classes in programming and I have a few questions:
1. When video games are being developed do they create their own engine or do they buy the licenses off others already made engines? Also what are the common or efficient languages used to design video games?

The vast majority of games license an engine. C++ is commonly used to design engines and lighter scripting languages like lua and python are used for everything else.
On November 02 2012 11:13 CarelessPride wrote:
2. How long would it take to recreate a similar game to lets say starcraft 2 or Diablo 3. like no create design wise just recreate everything from scratch

It would take years and a large team to recreate a game of the quality of SC2 or D3.


How long would it take me to learn the skills needed to start?

In order to work on something of SC2 scale, at least 3 years. Realistically more like 4-7 in order to get a job as a C++ software engineer at one of those studios. These are assuming you're obtaining a Bachelor's degree in CS, and a really good one at that.


3 seems a bit optimistic, i know i wouldn't want to hire someone for a project like that straight out of college / uni. We are talking a large professional undertaking with probably multi-millions in funding. If you skipped the degree, specialised your learning and built up a portfolio (by working in the industry for a few years) demonstrating your capability in that specific field it may be possible(even then without the degree, you face the reality of being turned down for people who have both the degree and experience). Still i would say to get onto a team that size, working on a project that large you would be looking at 5-6 years at a realistic minimum.

From what i've seen companies like blizzard won't even look at hiring someone as a programmer unless they have many years of experience in the industry already. They are pretty much the cream of the crop and can afford to be picky.
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
Last Edited: 2012-11-02 06:22:54
November 02 2012 05:00 GMT
#3705
Rewrote that recursive function from the last page non-recursively here. Might have some performance hits, but no duplicates, and so no tracking for duplicates needed.

A brief summary... given a MaximumNumber and MaximumSum, calculate all the possible 1 or 2 set moves where their sum is less than or equal to MaximumSum.

ex. MaximumNumber = 4, MaximumSum = 6.
Valid moves are {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4}, since the summation of any of them are <= MaximumSum


void generateLegalMoves()
{
vector<int>temp;

for (unsigned int d = 0; d < board.size(); ++d)
{
// finds all the single moves
if (board[d] <= maxSum)
{
temp.push_back(1);
temp.push_back(board[d]);
temp.push_back(board[d]);
legalMoves.push_back(temp);
temp.clear();
}

// finds all the double moves
if ((d + 1) < board.size() )
{
for (unsigned int n = (d + 1); n < board.size(); ++n)
{
if (board[d] + board[n] <= maxSum)
{
temp.push_back(2);
temp.push_back(board[d]);
temp.push_back(board[n]);
legalMoves.push_back(temp);
temp.clear();
}
}
}
}
}


I still feel like it can be done better recursively, but so far my efforts always end up with duplicate numbers and then trying to track for duplicate numbers which makes me think the non-recursive approach might end up performing just as well in the end.
Undefeated TL Tecmo Super Bowl League Champion
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
November 02 2012 20:41 GMT
#3706
@ESCPlan: your code examples use a board array but your problem description says you have a maximum number n and simply use (1...n) as available tokens to construct your sets -- which one is it?

also, please try to make clean code examples. Your example code looks like that whole vector pushback stuff is the complicated problem when all you are looking for is how to arrange the for loop counters and conditions..

oh and if ((d + 1) < board.size() ) is redundant. for (unsigned int n = (d + 1); n < board.size(); ++n) automatically skips that case because when you substitute the n<board.size() with the initialization n=(d+1), the for loop actually checks that exact condition automatically before executing.
Gold isn't everything in life... you need wood, too!
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-11-02 21:47:10
November 02 2012 21:26 GMT
#3707
On November 02 2012 14:00 EscPlan9 wrote:

+ Show Spoiler +

Rewrote that recursive function from the last page non-recursively here. Might have some performance hits, but no duplicates, and so no tracking for duplicates needed.

A brief summary... given a MaximumNumber and MaximumSum, calculate all the possible 1 or 2 set moves where their sum is less than or equal to MaximumSum.

ex. MaximumNumber = 4, MaximumSum = 6.
Valid moves are {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4}, since the summation of any of them are <= MaximumSum


void generateLegalMoves()
{
vector<int>temp;

for (unsigned int d = 0; d < board.size(); ++d)
{
// finds all the single moves
if (board[d] <= maxSum)
{
temp.push_back(1);
temp.push_back(board[d];
temp.push_back(board[d];
legalMoves.push_back(temp);
temp.clear();
}

// finds all the double moves
if ((d + 1) < board.size() )
{
for (unsigned int n = (d + 1); n < board.size(); ++n)
{
if (board[d] + board[n] <= maxSum)
{
temp.push_back(2);
temp.push_back(board[d];
temp.push_back(board[n];
legalMoves.push_back(temp);
temp.clear();
}
}
}
}
}


I still feel like it can be done better recursively, but so far my efforts always end up with duplicate numbers and then trying to track for duplicate numbers which makes me think the non-recursive approach might end up performing just as well in the end.




It doesn't matter whether you use your recursive approach to skip the {1,1} {2,2} ... {n,n} test cases. It's not going to make any noticeable difference whether you check those or not, even if you had just put a crude if x1 != x2 to skip that case.

Judging by your code, I would really consider making another function that returns a vector vector with the elements you want. It would make the code a lot less confusing to look through. In general, it's pretty impossible to track since your variables aren't that explicit and such.

You can do a few simple optimizations here and there, but your code isn't really clear about what variables are used for what purpose. Also, no one has any idea what board.size() means but you. :/


If you loop your second loop starting from the index your already started with, you will skip all the repeating cases. Then you only have to handle the {n,n} cases, which is also slightly trivial.

+ Show Spoiler [cheating] +


// solution

vector vector legal_moves(max_num, max_sum){
for x in 1 to max_num
if x <= max_sum
vector.add(x)

for x in 1 to max_num
for y in x to max_num
if x != y
if x + y <= max_sum
vector.add( new vector {x,y} )

return vector
}



// better

vector vector legal_moves(max_num, max_sum){
for x in 1 to max_num
if x <= max_sum
vector.add(x)

for x in 1 to max_num - 1
for y in x + 1 to max_num
if x + y <= max_sum
vector.add( new vector {x,y} )

return vector
}




Something like that. The max_num - 1 means you skip the {4,n} cases since it's pointless anyways. It also allows you to start the second loop at x + 1, so you don't have to skip checking the {n,n} cases.


If you put max_number = 4 and max_sum = 6

vector should have {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} in that order if I'm tracing properly.


Sure, you can improve the performance of this by a bit, but really, is it really necessary? (Actually, I'm not sure about this statement)



Again, I emphasize making a function to perform this task, even if it's just for readability.
There is no one like you in the universe.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-11-02 22:28:13
November 02 2012 22:27 GMT
#3708
Hey I wrote some small C practice programs. Maybe some of you guys will have fun or find it useful to check them out: link. It'd be cool to compare solutions.
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
Last Edited: 2012-11-03 03:30:45
November 03 2012 03:19 GMT
#3709
On November 03 2012 05:41 MisterD wrote:
@ESCPlan: your code examples use a board array but your problem description says you have a maximum number n and simply use (1...n) as available tokens to construct your sets -- which one is it?

also, please try to make clean code examples. Your example code looks like that whole vector pushback stuff is the complicated problem when all you are looking for is how to arrange the for loop counters and conditions..

oh and if ((d + 1) < board.size() ) is redundant. for (unsigned int n = (d + 1); n < board.size(); ++n) automatically skips that case because when you substitute the n<board.size() with the initialization n=(d+1), the for loop actually checks that exact condition automatically before executing.


Ah, didn't think about that one line being redundant. About the confusion with board, and what it represents, and why I'm using the datatypes I'm using... well... it's a large project. Throughout this quarter I had to use a generic AI solver algorithm for various 2 player games.

I have a Solver template class that only has the SolveForBestMove(T GameType) function inside it. It solves for whatever GameType object I throw at it. Within the SolveForBestMove function, I have calls out to overloaded functions for each GameType. For instance, in the example I've been showing above, the game is called Crossout. I have a CrossoutGame class with overloaded functions from what is called within the generic Solver template. So for example, within Solver template, in it's recursive SolveForBestMove method:


if ( GameType.isFinalPosition() )
{
// If it is a tie game, return 0 for the score
if ( GameType.isTied() )
return NEUTRAL_MOVE_SCORE; // score of 0 for the move

//Checks players turn (To see if good or bad move)
if ( GameType.getTurn() == FIRST_PLAYER_TURN )
return GOOD_MOVE_SCORE; //Returns score of +1 for the move

else
return BAD_MOVE_SCORE; // Returns score of -3 for bad move
}
...
// calls GameType.getLegalMoves() and with a depth-first search recursively iterates
// through the resulting position of each move and returns the score.


And then within Crossout:


// When there are no more legalMoves remaining, the final position has been reached
// No more numbers can be crossed out. So whoever crossed out the last number
// wins the game
bool CrossoutGame::isFinalPosition() const
{
return (legalMoves.size() == 0) ? true : false;
}


I've had each GameType use a vector<vector<int>> to store the Legal Moves, so I did the same for the Legal Moves of Crossout. The SolveForBestMove function explicitly expects a vector<vector<int>> when it calls GameType.getLegalMoves(), so each GameType (CrossoutGame, Connect3Game, etc) returns a vector<vector<int>> for the LegalMoves.

I am using a vector<int> for "board" in Crossout, since the game only requires me displaying it as a single line of integers. Like with the "1 2 3 4" example, the board has a size of 4, with board[0] == 1, board[1] == 2... board[3] == 4. It is a vector rather than an array because numbers are removed throughout the game and this allows me to constantly resize the array as needed.

For other games, such as Connect3 (Connect 4 with 3-in-a-row as the winning conditions), I use a vector<vector<int>> for "board".

It's fairly lengthy to post all the code I'm using... I was more curious with the recursive approach I tried last night that ended up running into duplicates. With the newer version, I'm fine with it as is, though there may be small improvements that can be made.

Thanks for the input. I'll remove the one redundant line anyways I apologize for the lack of clarity in the code in some areas. It's a small piece of a much larger project.
Undefeated TL Tecmo Super Bowl League Champion
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
November 03 2012 09:28 GMT
#3710
@EscPlan9: It's perfectly fine to re-use algorithms in bigger projects, but when making small examples you need to a) make sure you are correct on specifications - for instance using the board array instead of just numbers (1...n) is fundamentally different as it doesn't allow you to skip ahead in the algorithm without knowing if the number sequence in the array have holes (which i just assumed they do because otherwise the array would be pointless) or even worse if it isn't even a sequence in increasing order. Also, when extracting a piece of sample code from your large project, don't just copy/paste it 1:1 - take out
the essential parts so readers can cope with the complexity as easily as possible. Yes it's a bit of extra work, but you want them to help don't you? ;D

As for your description of why array or vector: sounds a lot like you are trying to over-optimize. How many legal moves are there? if it's less than 100 i'd argue that it's completely pointless (performance wise) to aim for reducing the array size when moves become illegal. In fact, it's probably worse to do so because in addition to not having any benefits, it just makes your code needlessly harder to read, understand and maintain. As a general rule of thumb, do performance optimization after you implemented a solution, and only do it where needed. Micro-optimizations such as reducing a 100 entry array in size are generally bad.
Gold isn't everything in life... you need wood, too!
Ruscour
Profile Blog Joined April 2011
5233 Posts
November 03 2012 10:21 GMT
#3711
Hello guys, I have more dumb questions.

1) I'll be doing a robotics project for a year, I don't know anything about hardware interaction but they'll teach me, however what I do need to know is C/C++. I know C decently well and haven't touched C++ but it seems like C++ would be preferable and it's seemingly used in a lot more places than C. Should I bend to Torvalds' divine will and stick to C or is C++ as beneficial as it seems?

2) C compilers for Windows? I'm used to make doing all the work for me, and using an IDE for compilation of small doodads is a waste of time. How do gcc on Windows best? MinGW? Cygwin?
Akka
Profile Joined August 2010
France291 Posts
Last Edited: 2012-11-03 10:54:31
November 03 2012 10:45 GMT
#3712
On November 03 2012 19:21 Ruscour wrote:
Hello guys, I have more dumb questions.

1) I'll be doing a robotics project for a year, I don't know anything about hardware interaction but they'll teach me, however what I do need to know is C/C++. I know C decently well and haven't touched C++ but it seems like C++ would be preferable and it's seemingly used in a lot more places than C. Should I bend to Torvalds' divine will and stick to C or is C++ as beneficial as it seems?

2) C compilers for Windows? I'm used to make doing all the work for me, and using an IDE for compilation of small doodads is a waste of time. How do gcc on Windows best? MinGW? Cygwin?


1) What does "decently well" mean? Are you confortable with pointers? Linked lists? Threads? Sockets? Sorting? Parsing?
I don't know about C++ being used more than C, or even if it is used at all in robotics, but good knowledge of C will take you anywhere you want anyway so being very confortable with C will probably help you more than being decent in both C and C++.

2) Just use visual studio's ^^
flexgd
Profile Joined September 2011
183 Posts
November 03 2012 10:49 GMT
#3713
Hi Guys,
I work at a small software company ( only an accomodation job) and this company offers services through their website which is in php. Now my boss gave me the job to find a programm that is able to analyze php code and notice any flaws security-wise. I have found a programm called rats that would be capable but now I need to find phpcode with security flaws so i can test the programm. so my question is: does anyone have experience with automated php code analyzing and can recommend a tool for that purpose (it doesnt have to be free if its really good)? does anyone know where i can find dedicated false php code to test this rats-tool that i found?

thanks in advance
Akka
Profile Joined August 2010
France291 Posts
November 03 2012 10:58 GMT
#3714
On November 03 2012 19:49 flexgd wrote:
Hi Guys,
I work at a small software company ( only an accomodation job) and this company offers services through their website which is in php. Now my boss gave me the job to find a programm that is able to analyze php code and notice any flaws security-wise. I have found a programm called rats that would be capable but now I need to find phpcode with security flaws so i can test the programm. so my question is: does anyone have experience with automated php code analyzing and can recommend a tool for that purpose (it doesnt have to be free if its really good)? does anyone know where i can find dedicated false php code to test this rats-tool that i found?

thanks in advance


Have you had a look here : http://stackoverflow.com/questions/4156157/tool-for-php-code-analysis ?
Shenghi
Profile Joined August 2010
167 Posts
Last Edited: 2012-11-03 13:43:05
November 03 2012 12:21 GMT
#3715
On November 02 2012 14:00 EscPlan9 wrote:
Rewrote that recursive function from the last page non-recursively here. Might have some performance hits, but no duplicates, and so no tracking for duplicates needed.

A brief summary... given a MaximumNumber and MaximumSum, calculate all the possible 1 or 2 set moves where their sum is less than or equal to MaximumSum.

ex. MaximumNumber = 4, MaximumSum = 6.
Valid moves are {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4}, since the summation of any of them are <= MaximumSum


void generateLegalMoves()
{
vector<int>temp;

for (unsigned int d = 0; d < board.size(); ++d)
{
// finds all the single moves
if (board[d] <= maxSum)
{
temp.push_back(1);
temp.push_back(board[d]);
temp.push_back(board[d]);
legalMoves.push_back(temp);
temp.clear();
}

// finds all the double moves
if ((d + 1) < board.size() )
{
for (unsigned int n = (d + 1); n < board.size(); ++n)
{
if (board[d] + board[n] <= maxSum)
{
temp.push_back(2);
temp.push_back(board[d]);
temp.push_back(board[n]);
legalMoves.push_back(temp);
temp.clear();
}
}
}
}
}


I still feel like it can be done better recursively, but so far my efforts always end up with duplicate numbers and then trying to track for duplicate numbers which makes me think the non-recursive approach might end up performing just as well in the end.

If you're only looking for subsets of size one or two, then the iterative solution is probably the best. If you insist on using a recursive solution, then here's something I threw together in a few minutes that does not produce double results:

#include <cstdio>
#include <vector>

typedef std::vector<int> vi;
typedef std::vector<vi> vvi;

// d: depth
// k: current number
// n: end of set (1,..,n)
// m: max sum
// cs: current sum
// cur: current answer
// res: resultset
void dfs(int d, int k, int n, int m, int cs, vi &cur, vvi &res)
{
if (d==2) {
res.push_back(cur);
return;
}

if (k > m) return;

if (d==1) res.push_back(cur);

for(int i=k;i<=n;++i) {
cs+=i;
if (cs > m) return;
cur.push_back(i);
dfs(d+1, k+1, n, m, cs, cur, res);
cs-=i;
cur.pop_back();
}
}

int main()
{
vvi res;
vi cur;

for(int i=4;i<20;++i) {
res.clear();
cur.clear();
printf("Solution for N=%d and M=%d\n", i, i+5);
dfs(0, 1, i, i+5, 0, cur, res);
for(int j=0;j<res.size();++j) {
for(int k=0;k<res[j].size();++k) {
printf("%d ", res[j][k]);
}
printf("\n");
}
printf("\n");
}

return 0;
}


EDIT: I just read up a few posts. This is probably useless to you. =[
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
itsJaeger
Profile Joined March 2011
Australia17 Posts
November 03 2012 12:35 GMT
#3716
i miss old school programing. gold old c++ none of this evil java stuff.
:D
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
Last Edited: 2012-11-03 23:07:19
November 03 2012 23:06 GMT
#3717
I miss C# Taking a class that demands I use C++ this year has been painful lol. I've taken C++ previously and I'm better at it now, but still find it painful to use. So much more typing required for all the programming I want to do. Meh. I know its a religious debate topic... so... yeah... I had to learn C# at my last job and loved coding with it.
Undefeated TL Tecmo Super Bowl League Champion
white_horse
Profile Joined July 2010
1019 Posts
Last Edited: 2012-11-04 23:53:34
November 04 2012 23:51 GMT
#3718
Hey guys, I'm trying to print a 52 x 72 rectangular grid using character X's and two dimensional arrays, and I'm not sure what I'm doing wrong here. Can you see what is wrong? Thanks


const int row = 52;
const int column = 72;


void printRace(const char grid[row][column]) //prints 52 by 72 grid
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
cout << grid[i][j];
}
cout << endl;
}
}


void initRace(const char track[row][column])
{
for (int i = 0; i == 0 && i == 51; i++) //top and bottom boundary
{
for (int j = 0; j < 72; j++)
{
track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE
}
}

for (int i = 1; i == 50; i++) //left and right boundary
{
for (int j = 0; j == 0 && j == 71; j++)
{
track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE
}
}
}


int main()
{

printRace(row, column);
initRace(row, column);


return 0;


}


Translator
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
Last Edited: 2012-11-04 23:57:46
November 04 2012 23:56 GMT
#3719
On November 05 2012 08:51 white_horse wrote:

void initRace(const char track[row][column]) <--- look here
{
...
track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE
...
track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE
...
}


also an error:

printRace(row, column);
initRace(row, column);




Read the lines i left over very carefully and you should notice the problem.
HaRuHi
Profile Blog Joined November 2010
1220 Posts
Last Edited: 2012-11-05 00:53:04
November 05 2012 00:24 GMT
#3720
On November 05 2012 08:51 white_horse wrote:
initRace does so not do what you want it to do. There is no need to nest the for loops!



void initRace(const char track[row][column])
{
for (int i = 0; i == 0 && i == 51; i++) //top and bottom boundary
{
for (int j = 0; j < 72; j++)
{
track[i][j] = 'X'; // <------------- COMPUTER SAYS ERROR ON THIS LINE
}
}

....

}



I would try something like


void initRace(char track[row][column])
{
for (int j = 0; j < 72; j++)
{
track[0][j] = 'X';
track[51][j] = 'X';
}

....

}



actually 2 errors, wrong parameters and you print before you init



int main()
{

printRace(row, column);
initRace(row, column);

return 0;

}




for (int i = 0; i == 0 && i == 51; i++)

The for loop runs as long as i equals 0 and i equals 51, at the same time, not either one.

if you would use:
for (int i = 0; i == 0 || i == 51; i++)

The loop would check if i is 0 or 51, it would run 1 time, while i == 0, after that i would be 1 and the loop would end.

You could however:
for (int i = 0; i == 0 || i == 51; i+51)

but pls don'T. ;D
Prev 1 184 185 186 187 188 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 8h 52m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 245
NeuroSwarm 154
ProTech79
ROOTCatZ 55
RuFF_SC2 53
StarCraft: Brood War
NaDa 115
yabsab 42
Icarus 4
Dota 2
febbydoto12
Counter-Strike
Fnx 1570
Stewie2K809
Heroes of the Storm
Khaldor178
Other Games
summit1g9593
tarik_tv7615
JimRising 515
fl0m429
ViBE150
Organizations
Other Games
BasetradeTV15
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• Berry_CruncH274
• davetesta35
• Hunta15 4
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• Azhi_Dahaki36
• Pr0nogo 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21171
• Ler73
League of Legends
• Doublelift6374
• Jankos1704
Upcoming Events
RSL Revival
8h 52m
Clem vs Classic
SHIN vs Cure
FEL
10h 52m
WardiTV European League
10h 52m
BSL: ProLeague
16h 52m
Dewalt vs Bonyth
Replay Cast
1d 22h
Sparkling Tuna Cup
2 days
WardiTV European League
2 days
The PondCast
3 days
Replay Cast
3 days
RSL Revival
4 days
[ Show More ]
Replay Cast
4 days
RSL Revival
5 days
FEL
5 days
RSL Revival
6 days
FEL
6 days
FEL
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.