frogboy77 73 Posting Pro in Training

This is actually a very difficult problem. As far as i am aware it was solved by the prolific mathematician Leonard Euler. It relates to pentagonal numbers(don't know why). I have the code for your problem if you want it, but i will not post it now in case you want to get this thing by yourself. I will pm it if you ask.

frogboy77 73 Posting Pro in Training

where's the recursion?

p.s is this a euler question?

frogboy77 73 Posting Pro in Training

first off how would the game work on say a 4x4 board?
how would a diagonal win work?(is it still 3 in a row or is it the full length of the board) if its the former its closer to a connect 4 game. if its the latter then again how would a diagonal work?

frogboy77 73 Posting Pro in Training

thanks got it now:)

frogboy77 73 Posting Pro in Training

Hey there.

I'm trying to figure out how to subtract one array of integers from another. I have figured out how to add 2 together going digit by digit and carrying over. I have no idea how to go about subtracting one from another. Basically i want to do simple calculations on numbers that long long wouldn't hold. I also want to do it using the standard library.

Does anyone have any hints on how to start or a link to a tutorial?

Any help is most appreciated.

frogboy77 73 Posting Pro in Training

search the many other threads here related to your problem.

frogboy77 73 Posting Pro in Training

thanks

frogboy77 73 Posting Pro in Training

i don't get the for loop

frogboy77 73 Posting Pro in Training

where do i find and how do i access limits.h?

frogboy77 73 Posting Pro in Training

Can anyone tell me how to find the maximum value for a specific variable(i.e int, long long int, double)?
Also is there a way to set a variable to this value(without knowing it and typing it in)?
Using Dev C++.
Any help appreciated.:)

frogboy77 73 Posting Pro in Training

Yes i was meaning an int array, will just have to try it with max value instead. Thanks.

frogboy77 73 Posting Pro in Training

Can anyone tell me if it is possible to set a value in an array to infinity and if so how to go about it?
Thanks.

frogboy77 73 Posting Pro in Training

can't say for the recursive version but for the iterative one you could put an if statement in the loop to see if the MAX value(for data type) divided by the next term to be multiplied is less than your running total then this would overflow the range of your data type, so break the program there and output the last value.:)

i.e

if(MAX/N<total){break;}

cout<<N;
frogboy77 73 Posting Pro in Training

What's the question?

frogboy77 73 Posting Pro in Training

Yeah picked up Accelerated C++ and i'm trying to get through it.
The name is apt though, about 20 new ideas every chapter. Hard to follow(still trying though).

frogboy77 73 Posting Pro in Training

thanks will have a look.

frogboy77 73 Posting Pro in Training

Don't think i can help as this is more advanced than i can manage but i would recommend that you actually ask a question or state a problem giving details of what it is you need help with. (you may get more replies this way) Good luck.:)

frogboy77 73 Posting Pro in Training

Hey, i know this is a commonly asked question (and will probably get burned for asking it again) but wanted an up to date answer so here we go.

I'm trying to learn to program in c++ purely as a hobby. I have recently spent some time doing problems at http://www.projecteuler.net/ and found it quite enjoyable (and due to the problems, learned some stuff i.e file I/O, use of arrays, vectors etc.) but i've got to the point where the maths has got me beat. Done all the ones i can find that are brute-forceable.

I have some books on programming but i find i have no concentration span for just reading through a textbook.

Sorry for the rambling.

Finally my question is "Can anyone recommend some similar sites (not necessarily maths based) at which noobs can have a go at some problems?"

Thanks in advance for any replies.

frogboy77 73 Posting Pro in Training

thanks for all the help gonna go and try to digest this now.

frogboy77 73 Posting Pro in Training

don't really get your code as i'm a total noob but

if ( ( npx - opx !== 2 && -2 || npy - opy !== 1 && -1 ) && (npx-opx !== 1 && -1 || npy-opy !== 2 && -2) )

should these !== not be just != ?
may be completely wrong though.

Ancient Dragon commented: you are right :) +34
ccube921 commented: awesomeness +3
frogboy77 73 Posting Pro in Training

thanks for all the help guys

slong (*newarray)[limitsqr] = new slong[limitsqr][limitsqr] ;

this worked a treat.
gonna have to learn more about pointers by the look of it.

frogboy77 73 Posting Pro in Training

thanks.

frogboy77 73 Posting Pro in Training

thanks will give this a try(even though i don't really understand it).

i would still like to know why i can create a 4 million 1D array but i can't create
a 4 million 2D array????????

if anyone can explain i would be grateful.:)

frogboy77 73 Posting Pro in Training

in my code i have declared

typedef signed long long int slong;
const slong limit=4000000;
    const slong limitsqr=2000;

i then created an array

slong* array=new slong[limit];

without any problem.

when i try this

slong* newarray=new slong[limitsqr][limitsqr];

i get the error message:

in function int main()
cannot convert slong(*)[2000] to slong in initialization

can anyone point out where i'm going wrong?

frogboy77 73 Posting Pro in Training

thanks gonna go work on this now.

frogboy77 73 Posting Pro in Training

thanks. put it all in one project and it seems to work fine.

frogboy77 73 Posting Pro in Training

hi again, i'm just full of problems.

i have a vectors of ints and i am trying to find a way to check if there is a repeatting sequence within the vector and what size this sequence is.
Does anyone have any suggestions on how i should go about this?
not looking for code just a nudge in the right direction.
:)

frogboy77 73 Posting Pro in Training

using dev on windows

the files are just saved in the directory

isn't a project (unsure what that means, have only been writing one off programs up to this point) just three seperate files.

frogboy77 73 Posting Pro in Training

don't understand thought i had.

frogboy77 73 Posting Pro in Training

ok tried that and still getting same error message.

frogboy77 73 Posting Pro in Training

this is the test program i wrote

#include <iostream>
#include "is_prime.h"

using namespace std;

int main()
{
    if(is_prime(50)){cout<<"yes"<<endl;}
    else{cout<<"no"<<endl;}
    
    
    system("pause");
    return 0;
}
frogboy77 73 Posting Pro in Training

Hi, new to this so go easy.
I'm trying to store a function i wrote in a file and call it with a header file rather than copy and paste as ive been doing but i keep getting error messages from the compiler.
Can anyone point out what i'm doing wrong?

the header file is:

#ifndef GUARD_is_prime_h
#define GUARD_is_prime_h

bool is_prime(unsigned long long int);

#endif

this is saved as is_prime.h

is_prime.cpp is;

bool is_prime(unsigned long long int a)
{
     if(a==1){return false;}
     if(a<4){return true;}
     if(a%2==0){return false;}
     if(a<9){return true;}
     if(a%3==0){return false;}
     unsigned long long int i;
     for(i=5;(i*i)<=a;i+=6)
     {
                           if(a%i==0){return false;}
                           if(a%(i+2)==0){return false;}
     }
     return true;
}

i then tried to write a simple program that asks if a number is prime having used
#include "is_prime.h" and i get the following error

In function main
[Linker error]undefined reference to is_prime(unsigned long long)
Id returned 1 exit status

any help greatly appreciated.:)

frogboy77 73 Posting Pro in Training

worked a treat thanks guys

frogboy77 73 Posting Pro in Training

to firstperson
tried your first suggestion and got two compile errors

invalid conversion from int* to int
type int argument given to delete, expected pointer

frogboy77 73 Posting Pro in Training

thanks will give this a go.

frogboy77 73 Posting Pro in Training
frogboy77 73 Posting Pro in Training

How do i create a large array in c++?

Apologies if this has been answered already but after searching didn't find what i was looking for.

i want to create an integer array of size 1500000 i.e int array[1500000] but my compiler wont allow it. I remember seeing something about using "new" but can't remember where i saw it. As you can tell am just beginning and trying to learn online(difficult).

If anyone could point me in the right direction or suggest a link to something it would be much appreciated.

frogboy77 73 Posting Pro in Training

if your "question"(i.e give me solution) does not embarrass you nothing i say will.
have you made any effort?

frogboy77 73 Posting Pro in Training

shameless

frogboy77 73 Posting Pro in Training

if u want i could just post you the code
save you the work

frogboy77 73 Posting Pro in Training

then you will have to learn or you will fail(rightly so).
no help will be given to you to trick your professor

frogboy77 73 Posting Pro in Training

nice logic thanks.

frogboy77 73 Posting Pro in Training

to anantk

just a newb myself but i was under the impression that the size of an array had to be specified by a constant not a variable entered by the user. i may have this wrong.

frogboy77 73 Posting Pro in Training

i dont really understand what you are attempting.
could u be more specific?

frogboy77 73 Posting Pro in Training

Yes.

frogboy77 73 Posting Pro in Training

edit

instead of count++
should be sum+=i

forgot what u asked
my bad

frogboy77 73 Posting Pro in Training

most basic code for this problem(not the best,can be done with pencil & paper )is
for(i=1;i<1000;i++){
if(i%3==0||i%5==0){count++;}}

many better ways than this

p.s. am currently running a program for project euler(will take days) so i can access the forum for the problem and see how the clever people did it.
great site but very addictive

frogboy77 73 Posting Pro in Training

what in particular do u want to return
for example if the input is "f"?

frogboy77 73 Posting Pro in Training

as a newbie myself take my advice with a pinch of salt

why have three functions that all do the same thing why not have just one and call it three times?

secondly i find recursion a nightmare to get my head round so where a simple while loop would suffice i would use it until my grasp of the language and the idea of recursion was better.

also be wary of user input as factorial numbers get very big very very quick

frogboy77 73 Posting Pro in Training

NO.
(as noob don't know if i could do this, but even if i could answer would be NO.)