SemiAccurate Forums  

 
Go Back   SemiAccurate Forums > Main Category > Off topic

Off topic Posts not related to technology

Reply
 
Thread Tools Display Modes
  #11  
Old 04-24-2012, 11:14 AM
Spartak's Avatar
Spartak Spartak is offline
8-bit overflow
 
Join Date: Mar 2011
Posts: 442
Spartak is on a distinguished road
Default

Quote:
Originally Posted by laurent View Post
If you only have to count pieces what are the inner two loops "distance" doing? You only need two loops over x and y to count pieces.
I was tired and now I do realise that I described the task not clear enough.
The program is supposed to count all possible squares (1x1, 2x2 etc), which are empty
Quote:
Originally Posted by Rottis View Post


Maybe I didn't get the question, but the braintwister was the code you pasted.
Yes, because so is the assignment
__________________
IMHO
Core i7-4770k with Thermalright True Spirit 140, ASRock Z87 Extreme 4 Mobo, 2x4 GB TeamGroup DDR3-2133, 2xSapphire Radeon HD 6950 2GB CF, 2xSamsung 840 Pro 256 GB in RAID 0, WD Caviar Black 1TB SATA 3 HDD, Super Flower 800W 80+ gold PSU, LG BH10LS30 BD-RE, Ultron Cardreader, Windows 7 Ultimate x64, LG W2261 FullHD monitor
Reply With Quote
  #12  
Old 04-24-2012, 01:19 PM
DarthShader's Avatar
DarthShader DarthShader is offline
2^10
 
Join Date: Jul 2010
Posts: 1,066
DarthShader is on a distinguished road
Default

Code:
for(int d=0;(d<SQR_SIZE-i-1)&&(d<SQR_SIZE-j-1); d++)
In this line both " -1 " are unnecessary. To see why imagine a board without any figures and start with left upper corner (0,0). Your code won't check if there is an empty square of size SQR_SIZE x SQR_SIZE.
Reply With Quote
  #13  
Old 04-24-2012, 02:21 PM
Spartak's Avatar
Spartak Spartak is offline
8-bit overflow
 
Join Date: Mar 2011
Posts: 442
Spartak is on a distinguished road
Default

Quote:
Originally Posted by DarthShader View Post
Code:
for(int d=0;(d<SQR_SIZE-i-1)&&(d<SQR_SIZE-j-1); d++)
In this line both " -1 " are unnecessary. To see why imagine a board without any figures and start with left upper corner (0,0). Your code won't check if there is an empty square of size SQR_SIZE x SQR_SIZE.
I don't think you are a right, the matrix is defined as
field[SQR_SIZE][SQR_SIZE]
__________________
IMHO
Core i7-4770k with Thermalright True Spirit 140, ASRock Z87 Extreme 4 Mobo, 2x4 GB TeamGroup DDR3-2133, 2xSapphire Radeon HD 6950 2GB CF, 2xSamsung 840 Pro 256 GB in RAID 0, WD Caviar Black 1TB SATA 3 HDD, Super Flower 800W 80+ gold PSU, LG BH10LS30 BD-RE, Ultron Cardreader, Windows 7 Ultimate x64, LG W2261 FullHD monitor
Reply With Quote
  #14  
Old 04-24-2012, 04:08 PM
DarthShader's Avatar
DarthShader DarthShader is offline
2^10
 
Join Date: Jul 2010
Posts: 1,066
DarthShader is on a distinguished road
Default

Yes and you use the "lower" operator in the for loop condition statement, so you need d to be lower than SQR_SIZE, to reach index SQR_SIZE - 1 which is the highest of the field, since we start counting at 0. Alternatively you could use "lower or equal" and keep the "-1".

For an empty checkboard of SQR_SIZE = 8, in the higher left corner, where (i,j) = (0,0) your algorithm should count 8 empty squares, so d should be allowed to go from 0 to 7 and it can't be 7 now since the for loop gets terminated.
Reply With Quote
  #15  
Old 04-24-2012, 06:54 PM
Spartak's Avatar
Spartak Spartak is offline
8-bit overflow
 
Join Date: Mar 2011
Posts: 442
Spartak is on a distinguished road
Default

Ok I reverse my previous statement. You ARE right
It works at last! yahoo!
__________________
IMHO
Core i7-4770k with Thermalright True Spirit 140, ASRock Z87 Extreme 4 Mobo, 2x4 GB TeamGroup DDR3-2133, 2xSapphire Radeon HD 6950 2GB CF, 2xSamsung 840 Pro 256 GB in RAID 0, WD Caviar Black 1TB SATA 3 HDD, Super Flower 800W 80+ gold PSU, LG BH10LS30 BD-RE, Ultron Cardreader, Windows 7 Ultimate x64, LG W2261 FullHD monitor
Reply With Quote
  #16  
Old 04-26-2012, 12:30 AM
Rottis's Avatar
Rottis Rottis is offline
8-bit overflow
 
Join Date: Jul 2009
Posts: 541
Rottis is on a distinguished road
Default

Quote:
Originally Posted by Spartak View Post
I was tired and now I do realise that I described the task not clear enough.
The program is supposed to count all possible squares (1x1, 2x2 etc), which are empty

Yes, because so is the assignment
I couldn't derive that from description gives. 8)
I do remember school assignments being fairly stupid and ambiguous..

So much posting tired.
__________________
Mmm, bacon balls.

Last edited by Rottis; 04-26-2012 at 12:33 AM.
Reply With Quote
  #17  
Old 05-11-2012, 04:35 AM
Zizy Zizy is offline
640k who needs more?
 
Join Date: Jun 2010
Posts: 916
Zizy is on a distinguished road
Default

To hijack a bit with a C problem.

Relevant part of code is:

printf("%f\n", 0.5);
if (bla[1] > 0) { printf("%f\n", 0.5); }
printf("%f\n", bla[1]);

First 2 lines work just fine, while for the third one bla[1] is written, but Valgrind throws a long list of errors (ca 50).
How come the problems appear only then, why not in the second one as well?
Reply With Quote
  #18  
Old 06-04-2012, 01:08 PM
Spartak's Avatar
Spartak Spartak is offline
8-bit overflow
 
Join Date: Mar 2011
Posts: 442
Spartak is on a distinguished road
Default

Let's say given:

class My_class //which consists of:
{
private:
Subclass1 a;
Subclass2 b;
float f;
public:
My_class(Subclass1, Subclass2, float);//CTOR prototype
~My_class(); //DTOR
//methods
};
Question:
What the CTOR definition should look like, so the subclasses could be initialized concurrently with My_class?
i. e.
My_class(Subclass1('u', 8), Subclass2("ab", 98465), 3.5)
__________________
IMHO
Core i7-4770k with Thermalright True Spirit 140, ASRock Z87 Extreme 4 Mobo, 2x4 GB TeamGroup DDR3-2133, 2xSapphire Radeon HD 6950 2GB CF, 2xSamsung 840 Pro 256 GB in RAID 0, WD Caviar Black 1TB SATA 3 HDD, Super Flower 800W 80+ gold PSU, LG BH10LS30 BD-RE, Ultron Cardreader, Windows 7 Ultimate x64, LG W2261 FullHD monitor
Reply With Quote
  #19  
Old 08-26-2012, 09:01 AM
Spartak's Avatar
Spartak Spartak is offline
8-bit overflow
 
Join Date: Mar 2011
Posts: 442
Spartak is on a distinguished road
Default

what is the difference between template function and function template?
__________________
IMHO
Core i7-4770k with Thermalright True Spirit 140, ASRock Z87 Extreme 4 Mobo, 2x4 GB TeamGroup DDR3-2133, 2xSapphire Radeon HD 6950 2GB CF, 2xSamsung 840 Pro 256 GB in RAID 0, WD Caviar Black 1TB SATA 3 HDD, Super Flower 800W 80+ gold PSU, LG BH10LS30 BD-RE, Ultron Cardreader, Windows 7 Ultimate x64, LG W2261 FullHD monitor
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -5. The time now is 11:13 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SemiAccurate is a division of Stone Arch Networking Services, Inc. Copyright 2009 Stone Arch Networking Services, Inc, all rights reserved.