|
well, im sort of a newb. basically, just have the numbers be arranged any way possible to make any 2 integers added together a perfect square.
like,
15,1,24,12,4,21
i dont really know how to explain it anymore
|
|
|
|
|
When you say *need* to know, is this something you have personal need for, or is it your homework ?
Think about what you want the program to do. How would you do it manually ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Here's what you asked for, assuming that you have Hexium or 80686 processor (searching within 30! (i.e 30*29*28..*1) elements):
#include <stdio.h>
int Check(int,int);
main()
{
for(int j1=1;j1<31;j1++)
for(int j2=1;j2<31;j2++){if(j2==j1)continue;
for(int j3=1;j3<31;j3++){if(j3==j2 || j3==j1)continue;
for(int j4=1;j4<31;j4++){if(j4==j3 || j4==j2 || j4==j1)continue;
for(int j5=1;j5<31;j5++){if(j5==j4 || j5==j3 || j5==j2 || j5==j1)continue;
for(int j6=1;j6<31;j6++){if(j6==j5 || j6==j4 || j6==j3 || j6==j2 || j6==j1)continue;
for(int j7=1;j7<31;j7++){if(j7==j6 || j7==j5 || j7==j4 || j7==j3 || j7==j2 || j7==j1)continue;
for(int j8=1;j8<31;j8++){if(j8==j7 || j8==j6 || j8==j5 || j8==j4 || j8==j3 || j8==j2 || j8==j1)continue;
for(int j9=1;j9<31;j9++){if(j9==j8 || j9==j7 || j9==j6 || j9==j5 || j9==j4 || j9==j3 || j9==j2 || j9==j1)continue;
for(int j10=1;j10<31;j10++){if(j10==j9 || j10==j8 || j10==j7 || j10==j6 || j10==j5 || j10==j4 || j10==j3 || j10==j2 || j10==j1)continue;
for(int j11=1;j11<31;j11++){if(j11==j10 || j11==j9 || j11==j8 || j11==j7 || j11==j6 || j11==j5 || j11==j4 || j11==j3 || j11==j2 || j11==j1)continue;
for(int j12=1;j12<31;j12++){if(j12==j11 || j12==j10 || j12==j9 || j12==j8 || j12==j7 || j12==j6 || j12==j5 || j12==j4 || j12==j3 || j12==j2 || j12==j1)continue;
for(int j13=1;j13<31;j13++){if(j13==j12 || j13==j11 || j13==j10 || j13==j9 || j13==j8 || j13==j7 || j13==j6 || j13==j5 || j13==j4 || j13==j3 || j13==j2 || j13==j1)continue;
for(int j14=1;j14<31;j14++){if(j14==j13 || j14==j12 || j14==j11 || j14==j10 || j14==j9 || j14==j8 || j14==j7 || j14==j6 || j14==j5 || j14==j4 || j14==j3 || j14==j2 || j14==j1)continue;
for(int j15=1;j15<31;j15++){if(j15==j14 || j15==j13 || j15==j12 || j15==j11 || j15==j10 || j15==j9 || j15==j8 || j15==j7 || j15==j6 || j15==j5 || j15==j4 || j15==j3 || j15==j2 || j15==j1)continue;
for(int j16=1;j16<31;j16++){if(j16==j15 || j16==j14 || j16==j13 || j16==j12 || j16==j11 || j16==j10 || j16==j9 || j16==j8 || j16==j7 || j16==j6 || j16==j5 || j16==j4 || j16==j3 || j16==j2 || j16==j1)continue;
for(int j17=1;j17<31;j17++){if(j17==j16 || j17==j15 || j17==j14 || j17==j13 || j17==j12 || j17==j11 || j17==j10 || j17==j9 || j17==j8 || j17==j7 || j17==j6 || j17==j5 || j17==j4 || j17==j3 || j17==j2 || j17==j1)continue;
for(int j18=1;j18<31;j18++){if(j18==j17 || j18==j16 || j18==j15 || j18==j14 || j18==j13 || j18==j12 || j18==j11 || j18==j10 || j18==j9 || j18==j8 || j18==j7 || j18==j6 || j18==j5 || j18==j4 || j18==j3 || j18==j2 || j18==j1)continue;
for(int j19=1;j19<31;j19++){if(j19==j18 || j19==j17 || j19==j16 || j19==j15 || j19==j14 || j19==j13 || j19==j12 || j19==j11 || j19==j10 || j19==j9 || j19==j8 || j19==j7 || j19==j6 || j19==j5 || j19==j4 || j19==j3 || j19==j2 || j19==j1)continue;
for(int j20=1;j20<31;j20++){if(j20==j19 || j20==j18 || j20==j17 || j20==j16 || j20==j15 || j20==j14 || j20==j13 || j20==j12 || j20==j11 || j20==j10 || j20==j9 || j20==j8 || j20==j7 || j20==j6 || j20==j5 || j20==j4 || j20==j3 || j20==j2 || j20==j1)continue;
for(int j21=1;j21<31;j21++){if(j21==j20 || j21==j19 || j21==j18 || j21==j17 || j21==j16 || j21==j15 || j21==j14 || j21==j13 || j21==j12 || j21==j11 || j21==j10 || j21==j9 || j21==j8 || j21==j7 || j21==j6 || j21==j5 || j21==j4 || j21==j3 || j21==j2 || j21==j1)continue;
for(int j22=1;j22<31;j22++){if(j22==j21 || j22==j20 || j22==j19 || j22==j18 || j22==j17 || j22==j16 || j22==j15 || j22==j14 || j22==j13 || j22==j12 || j22==j11 || j22==j10 || j22==j9 || j22==j8 || j22==j7 || j22==j6 || j22==j5 || j22==j4 || j22==j3 || j22==j2 || j22==j1)continue;
for(int j23=1;j23<31;j23++){if(j23==j22 || j23==j21 || j23==j20 || j23==j19 || j23==j18 || j23==j17 || j23==j16 || j23==j15 || j23==j14 || j23==j13 || j23==j12 || j23==j11 || j23==j10 || j23==j9 || j23==j8 || j23==j7 || j23==j6 || j23==j5 || j23==j4 || j23==j3 || j23==j2 || j23==j1)continue;
for(int j24=1;j24<31;j24++){if(j24==j23 || j24==j22 || j24==j21 || j24==j20 || j24==j19 || j24==j18 || j24==j17 || j24==j16 || j24==j15 || j24==j14 || j24==j13 || j24==j12 || j24==j11 || j24==j10 || j24==j9 || j24==j8 || j24==j7 || j24==j6 || j24==j5 || j24==j4 || j24==j3 || j24==j2 || j24==j1)continue;
for(int j25=1;j25<31;j25++){if(j25==j24 || j25==j23 || j25==j22 || j25==j21 || j25==j20 || j25==j19 || j25==j18 || j25==j17 || j25==j16 || j25==j15 || j25==j14 || j25==j13 || j25==j12 || j25==j11 || j25==j10 || j25==j9 || j25==j8 || j25==j7 || j25==j6 || j25==j5 || j25==j4 || j25==j3 || j25==j2 || j25==j1)continue;
for(int j26=1;j26<31;j26++){if(j26==j25 || j26==j24 || j26==j23 || j26==j22 || j26==j21 || j26==j20 || j26==j19 || j26==j18 || j26==j17 || j26==j16 || j26==j15 || j26==j14 || j26==j13 || j26==j12 || j26==j11 || j26==j10 || j26==j9 || j26==j8 || j26==j7 || j26==j6 || j26==j5 || j26==j4 || j26==j3 || j26==j2 || j26==j1)continue;
for(int j27=1;j27<31;j27++){if(j27==j26 || j27==j25 || j27==j24 || j27==j23 || j27==j22 || j27==j21 || j27==j20 || j27==j19 || j27==j18 || j27==j17 || j27==j16 || j27==j15 || j27==j14 || j27==j13 || j27==j12 || j27==j11 || j27==j10 || j27==j9 || j27==j8 || j27==j7 || j27==j6 || j27==j5 || j27==j4 || j27==j3 || j27==j2 || j27==j1)continue;
for(int j28=1;j28<31;j28++){if(j28==j27 || j28==j26 || j28==j25 || j28==j24 || j28==j23 || j28==j22 || j28==j21 || j28==j20 || j28==j19 || j28==j18 || j28==j17 || j28==j16 || j28==j15 || j28==j14 || j28==j13 || j28==j12 || j28==j11 || j28==j10 || j28==j9 || j28==j8 || j28==j7 || j28==j6 || j28==j5 || j28==j4 || j28==j3 || j28==j2 || j28==j1)continue;
for(int j29=1;j29<31;j29++){if(j29==j28 || j29==j27 || j29==j26 || j29==j25 || j29==j24 || j29==j23 || j29==j22 || j29==j21 || j29==j20 || j29==j19 || j29==j18 || j29==j17 || j29==j16 || j29==j15 || j29==j14 || j29==j13 || j29==j12 || j29==j11 || j29==j10 || j29==j9 || j29==j8 || j29==j7 || j29==j6 || j29==j5 || j29==j4 || j29==j3 || j29==j2 || j29==j1)continue;
for(int j30=1;j30<31;j30++){if(j30==j29 || j30==j28 || j30==j27 || j30==j26 || j30==j25 || j30==j24 || j30==j23 || j30==j22 || j30==j21 || j30==j20 || j30==j19 || j30==j18 || j30==j17 || j30==j16 || j30==j15 || j30==j14 || j30==j13 || j30==j12 || j30==j11 || j30==j10 || j30==j9 || j30==j8 || j30==j7 || j30==j6 || j30==j5 || j30==j4 || j30==j3 || j30==j2 || j30==j1)continue;
if(Check(j1,j2)&&Check(j2,j3)&&Check(j3,j4)&&
Check(j4,j5)&&Check(j5,j6)&&Check(j6,j7)&&
Check(j7,j8)&&Check(j8,j9)&&Check(j9,j10)&&
Check(j10,j11)&&Check(j11,j12)&&Check(j12,j13)&&
Check(j13,j14)&&Check(j14,j15)&&Check(j15,j16)&&
Check(j16,j17)&&Check(j17,j18)&&Check(j18,j19)&&
Check(j19,j20)&&Check(j20,j21)&&Check(j21,j22)&&
Check(j22,j23)&&Check(j23,j24)&&Check(j24,j25)&&
Check(j25,j26)&&Check(j26,j27)&&Check(j27,j28)&&
Check(j28,j29)&&Check(j29,j30)){
printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d ",
j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,j11,j12,j13,j14,j15,j16,j17,j18,j19,j20,j21,j22,j23,j24,j25,j26,j27,j28,j29,j30);
getchar();
return 0;}
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
printf("\nNo solution!.");
getchar();
return 0;
}
int Check(int x,int y)
{
int c=x+y;
if(c==4 || c==9 || c==16 || c==25 || c==36 || c==49) return 1;
else return 0;
}
Zarzor
ZARZOR13
|
|
|
|
|
You are a bad guy;)
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Sorry....what you said ?.
ZARZOR13
|
|
|
|
|
Come down!
1 24 25 11 5 4 12 13 3 6 30 19 17 8 28 21 15 10 26 23 2 14 22 27 9 16 20 29 7 18
You must modify my previous code by adding to each "for" loop (start from j2 loop) in "if" statment the following statment: || !Check(jx,jy)
where jx is the current loop, and jy is the previous loop. e.g.
for(int j2=1;j2<31;j2++){if(j2==j1 || !Check(j1,j2))continue;
Hence,you can reduce the running time from few weeks to few seconds !!
You welcome for any Math problem.
ZarZor
ZARZOR13
|
|
|
|
|
I have this code in my program:
Tmp = theApp.Directory + "\\WulframAutoUpdater.exe";<br />
Both Tmp and Directory are CString's, and directory have a directory location in it. But, for some reason, Tmp is set to "\\WulframAutoUpdater.exe", without the directory string. Why is it doing that?
Thanks!
|
|
|
|
|
Obvious question - have you traced in with the debugger and established that theApp.Directory is a CString with a value in it at the point that this code executes ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Yep, first thing I did
What makes this problem even more weird, is that in most other parts of my program, CString adding operations like that work! It's just in that spot, and a couple other spots that that weird problem happens. I finally got tired of having to manually add using strcat, and that's why I posted this problem here.
|
|
|
|
|
HAve you broken it up ? I'd sprinkle the code with AfxMessageBoxes and build the string in two steps, an = and a +=, and see what I got.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Yeah, I'd try to do it as
theApp.Directory ++ "\\WulframAutoUpdater.exe";
tmp = theApp.Directory;
If that didn't work then god knows, I've never noticed problems like this before. Hope you get it working.
|
|
|
|
|
Ok, I re-arranged it like so:
Tmp = theApp.Directory;<br />
Tmp += "\\WulframAutoUpdater.exe";
It still doesn't work, but stepping into the CSimpleString source tells me that for some reason, GetData() doesn't get the right data, even when the "this" pointer in the class is the right data! I replaced the first line with "Tmp = "Test";", and that works fine. I've also gone through my code for the variable "Directory", and everytime I use it I use .GetBuffer(200). (I've had weird problems before from forgettting to use that function)
|
|
|
|
|
theApp.Directory is definitely empty. You can confirm /deny this by doing ASSERT (!theApp.Directory.IsEmpty()); before the first statement.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I did this:
char *Loc = new char[200];<br />
<br />
ASSERT(!theApp.Directory.IsEmpty()); <br />
strcpy(Loc,theApp.Directory.GetBuffer(200));<br />
It does assert, BUT, when I move the mouse over Directory, the tooltip shows that it isn't empty, and the directory is properly copied into Loc!
|
|
|
|
|
IGx89 wrote:
It does assert
So theApp.Directory contains no chars OR someone (you?) really messed up the internal bookkeeping of the CString. You use CString::ReleaseBuffer()properly?
IGx89 wrote:
the tooltip shows that it isn't emptyWhich Tooltip? Where?
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
I know that it's my fault; I just need to figure out WHAT is my fault
ReleaseBuffer()? Ummm, didn't know about that function . Would that cause these errors?
When you pause the debugger, moving the mouse over different variables shows their contents in a tooltip. Very useful for debugging
|
|
|
|
|
IGx89 wrote:
ReleaseBuffer()? Would that cause these errors?
GetBuffer() takes the char* that CString is wrapping out of the control of the CString -class. With ReleaseBuffer() you return it into the hands of CString .
Between GetBuffer() and ReleaseBuffer() you cant use any CString -functions.
Well - you can, but they do not work.
Your error description sounds to me like a CString not having updated its bookkeeping (eg. does CString not rely on the \0 terminator to determine string length - it counts internaly).
Especially the fact that CString doesnt work and strXY() does.
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Hello,
I have a dialog, with a child dialog in.
My child dialog handle mouse events.
In the OnLButtonUp() function of my child dialog, I would like notify the parent dialog that the child is ready for something.
How can I notify parent of something happen from a function in the child ??
|
|
|
|
|
there are a few ways to handle this. You can set up a custom message and post it to the parent, or you can have a public function within the parent to be called from the child. I usually do the latter (mainly because i'm lazy). Here's what I do:
in the child class:
#include "CYourMainDlg.h"
CYourMainDlg* pMain = static_cast<CYourMainDlg*>(AfxGetMainWnd());
pMain->YourPublicFunction(TheParamsYouWantToSend, MaybeAnother);
hope that helps.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Thx,
It work now.
I have create a class COpDialog: public CDialog with a public method, and all parent classes are public COpDialog. So the child could notify his parents.
|
|
|
|
|
what about defining a pointer variable of the same type of the parent dialog:
<br />
CMyParentDlg *p = NULL;<br />
Use this in order to get access to the parent window/dialog:
<br />
p = (CMyParentDlg *)this->GetParent();<br />
Use this in order to pass the data?
<br />
p->SomeFunction(...);<br />
or this:
<br />
p->SendMessage(...);<br />
Hope this helps
|
|
|
|
|
Hi.
I want to send messages to one or more view classes from either CMainFrame or the doc class. I would like to know, How do you get access to the handles of one or more view classes from inside the doc class and/or CMainFrame?
Thanks,
Kuphryn
|
|
|
|
|
AfxGetMainWnd()->GetActiveView(), from memory.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
If you mean sending to some views belonging to the same document, the way is to use
POSITION pos = GetFirstViewPosition();
while (pos != NULL) {
CView* pView = GetNextView(pos);
...
}
For some documents use
CDocTemplate::GetFirstDocPosition/GetNextDoc and then - the code above
To enumerate all views of all documents of all types you can use
CDocManager::GetFirstDocTemplatePosition/GetNextDocTemplate, then see above
How to get instance of docmanager see CWinApp documentation. If my memory doesn't fail me, CWinApp have a member m_pDocManager
|
|
|
|
|
Thanks everyone.
http://www.codeguru.com/forum/showthread.php?s=&postid=641316#post641316
Andreas Masur of CodeGuru posted a valuable chart on getting access to difference classes in MFC.
http://www.codeguru.com/forum/showthread.php?s=&postid=641316#post641316
Kuphryn
|
|
|
|
|