mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

Depends on the compiler I suppose...

Idk, maybe someone more knowledgeable can comment. I haven't seen one implementation that uses a list, simply because calculating at runtime is very fast and way less memory intensive than generating a list of pseudo random numbers, which can be very very long.

mrnutty 761 Senior Poster

>>Random numbers are not calculated, they are pulled from a huge list

Are you sure? I thought they were calculated via linear congruential algorithm given a seed to start from.

mrnutty 761 Senior Poster

You probably forgot to seed it. Try this:

#include <iostream>
#include <ctime>
using namespace std;

int main(){
 srand( time(0) ); //seed the RGN
 for(int i = 0; i < 10; ++i){
   std::cout << (rand() % 100 + 1) << std::endl;
 }
 return 0;
}
mrnutty 761 Senior Poster

Ok so what I need to do is take the key and find the value in the array that matches the key and replace it there. But wouldn't I still have to move the data over to the right and insert the new data into the empty spot?

Key should be unique to each hashtable. So every key of value 5 for example, should map to the same spot in the array.

mrnutty 761 Senior Poster

No all you need is a insert function. Usually what happens is that if you try to insert into the map with a key that already exist you return the already existed key/value pair. It is up to the user to decide whether to remove that key or just replace the value associated with that key

mrnutty 761 Senior Poster

why do you have that? A key should be unique. In your insert function you are shifting values around. That would cause the get method to fail or act incorrectly because a key that was hashed into a slot is no longer in the same slot.

mrnutty 761 Senior Poster

>> CollisionBoxTest(sf::Sprite Hitter, sf::Sprite Hittee) Change that to take a constant reference. Copying Sprite can be expensive. So try making that into CollisionBoxTest(const sf::Sprite& Hitter, const sf::Sprite& Hittee) . Make sure to change the prototype as well. Also you can do without creating all of those temporaries, but for now leave them. Change the above first and see if it helps. Also show us how you are calling it, more specifically the context its being called from? It is important to know if its being called 1000 times per second ?

mrnutty 761 Senior Poster

why do you have both "put" and "insert" function? Most likely, you should only have one function to insert into the hashmap.

mrnutty 761 Senior Poster

whats the problem?

mrnutty 761 Senior Poster

I don't need to be exact, all I need is collision detection for boxes. The most obvious way I can think of (what labdabeta said) seems to run really slow in real-time applications where I test each box against another.

The box-test should be really fast. Your problem lies somewhere else. If you have a lot of boxes in the screen, then you need to do some pruning to the screen to eliminate certain checks. Post your code and we'll try to help

mrnutty 761 Senior Poster

Can someone give me some resources (books, online tutorials, etc.) on algorithms for 2D collision detection? I've searched a little, and all the ones I can find are for 3D collision detection.

Thanks in advance.

EDIT: Just to clarify, I know how to do collision detection, just not efficiently.

which shapes are you trying to find collision detection on? There seems to be tons of resource in google

mrnutty 761 Senior Poster

I haven't worked with mandelbrot set but try using this :

//zn is your last complex number used and n is the iteration count
flota smoothcolor = n + 1 - Math.log(Math.log(zn.abs()))/Math.log(2)
Color col = Color.HSBtoRGB(0.95f + 10 * smoothcolor ,0.6f,1.0f);
mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

>>Now, all my pieces have no unique "rules" on how they act

Well it should if c_ChessPiece has proper virtual functions? Btw, not a fan of the class-prefix.

For example take a look at this interface. A ChessPiece should at least have some uniform functions, like move and such. So what you should be doing is having an array of chesspiece pointers. And inside the constructor, initialize them to their proper piece. And when time comes to promote the pawn, all you do is create a new Knight piece( assuming use picks knight ), then copy the pawn's information into the newly created knight piece, for example its location and stuff. Then just delete the pawn and add the new chess piece which points to a knight. Make sense?

mrnutty 761 Senior Poster

I'll look into the clone thing, but I think we are supposed to write a recursive copy function

what is recursive copy?

mrnutty 761 Senior Poster

First you should be using templates. But the solution to your problem is to provide a virtual clone function. Look here for more information.

mrnutty 761 Senior Poster

I think it will be easier if you try to compress a series of bytes into a smaller chunk instead of trying to compress a byte into something smaller. I suggest to read this and see if it helps.

mrnutty 761 Senior Poster

>>I am storing many variables of different types.

Can you convert/encode all those variables to a string version?

mrnutty 761 Senior Poster

Uhh well that's the thing.. I want to allow "empty parameters" and that's why I need to check.. so that I can do:

class DoStuff
{
	private:
		void Insert(){}
		vector<Types> Meh;
		
	public:
	    DoStuff() {}           //This constructor doesn't get kicked in due to the one below it..
		
        template<typename T, typename... Args>
        DoStuff& Insert(T First, const Args... Remaining)
        {
           if !(Template parameter empty)
           {
            this->Meh.push_back(First);    //Error will be here if it's empty..
            Insert(Remaining...);
           }
           else
             Meh.push_back(i(0));
        }
}

int main()
{
    DoStuff P();   //This should be DoStuff P;    I just solved it but learned lots from your posts above.. THANKS! +1
}

I'll check out what you guy's suggested. And it doesn't matter if you're wrong lately. I seriously appreciate the reply :)

DoStuff P(); //This should be DoStuff P; I just solved it but learned lots from your posts above.. THANKS! +1

Also a easy way to solve this problem is to make make sure there is at least 1 argument for the second constructor to be called. Example,

template<typename T, typename... Args>
DoStuff& Insert(T First, const Args& arg0, const Args... Remaining){
  //...
}

I think that should work, no guarantees.

mrnutty 761 Senior Poster

what is data-type for your list?

mrnutty 761 Senior Poster

The number of possible binary tree you can create is [tex]2^n[/tex] where n is the number of nodes. And for each one, you will do at max [tex]n[/tex] comparison when trying to insert a new element. Hence the maximum number of comparison for this problem will be [tex]2^n*n[/tex]

mrnutty 761 Senior Poster

I'm not sure what exactly you are saying. What is a binary tree with 1 and 2? Maybe a picture would help.

mrnutty 761 Senior Poster

You would want to use the concept of iterators, and just assume certain property like being able to move forward. Check out http://www.cplusplus.com/reference/algorithm/find/ for more reference.

mrnutty 761 Senior Poster

Hey guys, haven't been on here for a while. Just thought, I'd get the ball rolling and interact with the community. Anyways, tell me and everyone else on the internet, the derivation of your username? Why? How? What? When? Who? WTF?

mrnutty 761 Senior Poster

In my opinion "++" in C/C++ is just terrible. I don't even know why they allow it to be part of the language. Try

pID = pID + 1;

"++" increment its value by 1 and assigns it to the variable. However, if the operator is inserted inside a conditional statement "as the condition to be evaluated", the value will be assigned to the variable, but the conditional statement will treat it as if such an operation never happened. Just terrible, but that's just me, many programmers use "++" as "the best way".

I disagree. That is all.

mrnutty 761 Senior Poster

thank you! I don't have any formal training in time complexity and all the examples online only show how to denote a single variable. Basically I wrote a whole program and I was trying to figure out the time complexity but it had so many variables in it I didnt know how to show it. this should help me finish.

My only question now is, is there any real point to time complexity? I mean granted it helps show how quick or slow an algorithm is but it not it terms of iterations in relations to but they dont fully represent the correct time. Take sort by insertion it time complexity is averages 0(N^2) however, if you are dealing with mostly sorted data, which most programs are it would be (N*D) D-being the number of things need to be inserted. So is there really a point?

Big-O allows one to compare between different algorithms. That is the point you should get out of this. How else would you cleanly compare bubble-sort against merge-sort?

mrnutty 761 Senior Poster

>>M- happens to be a unknown function of N

That means, M = f(N), and you can't assume anything about f(N), so the runtime would be O(N * f(N)).
That could be linear, polynomial, quadratice, factorial, or whatever; all depending on f(N)

grh1107 commented: thanks! very helpful +1
mrnutty 761 Senior Poster

What do you need help with? Maybe this will get you started.

#include <iostream>

using namespace std;

bool isPrime(int number){
  bool isPrimeNumber = false;
  //do logic here

  return isPrimeNumber;
}

int main(){
  cout << boolalpha << "Is 5 prime : " << isPrime(5) << endl; //should be true
  cout << boolalpha << "Is 97 prime: " << isPrime(97) << endl; //should be true
  cout << boolalpha << "Is 27 prime: " << isPrime(27) << endl; //should be false

 return 0;
}
mrnutty 761 Senior Poster

What do you need help with? Maybe this will get you started.

#include <iostream>

using namespace std;

bool isPrime(int number){
  bool isPrimeNumber = false;
  //do logic here

  return isPrimeNumber;
}

int main(){
  cout << boolalpha << "Is 5 prime : " << isPrime(5) << endl; //should be true
  cout << boolalpha << "Is 97 prime: " << isPrime(97) << endl; //should be true
  cout << boolalpha << "Is 27 prime: " << isPrime(27) << endl; //should be false

 return 0;
}
mrnutty 761 Senior Poster

Use std::vector whenever possible, only use static arrays, when you absolutely need to

mrnutty 761 Senior Poster

If you want to read the file into a vector, then you can represent each pixel as a char or int. For example you can have something like so, std::vector<char> pixels; and read from file into that vector. For example:

std::vector<char> pixels;
ifstream fileInput("imagefile.txt");
//read from file into vector
std::copy( std::istream_iterator<char>(fileInput), 
                std::istream_iterator<char>(),
                std::back_inserter(pixels));

for(int i = 0; i < pixels.size(); ++i){
  cout << pixels[i];
}
mrnutty 761 Senior Poster

I still don't know what 0R1,0R2,0S4,1S4 does! Can you give an example of what each of the instruction should do on some input

mrnutty 761 Senior Poster
INPUT-BUFFER: 973 456.2 77F NEWLINE 973 456.2 77F

1)	cin>> m;  //m = 973 
INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F

2)	cin.clear (); //clears the state bits
INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F

3)	cin.ignore (200, '\n');  //ignores 200 characters or until a new line is reached
INPUT-BUFFER: 973 456.2 77F

4)	cin>> letter>> n>> n;   //letter = '9' , n = 73 then n = 456

INPUT-BUFFER: [ is in a failed state I think not sure, sets the state bits ]

5) cout<< letter<< m<< n<< endl; //pass out 9973456
mrnutty 761 Senior Poster

You know if you use std::vector, it does that for you.

int main(){
 std::vector<int> array; //size = 0;
array.push_back( 1) ; //size = 1, [1]
array.push_back(5); //size = 2, [1,5]
}
mrnutty 761 Senior Poster

Check out string::erase

mrnutty 761 Senior Poster

If its just 1's and 0's you might as well use std::bitset

std::bitset<15> mat1(std::string("010101010111101"));
cout << mat1.to_ulong() << endl;
mrnutty 761 Senior Poster

Matrix 1:

0 1 0 1 0
1 0 1 0 1
1 1 1 0 1

What's the data type of Matrix?

mrnutty 761 Senior Poster

>>//Given x=10 and y=5

y = 2*y++ + --x;

y = (2*y++) + (--x)

//substitute, not valid but easier to see
y = (2 * 5++) + (--10);
y = (2 * 5) + (--10) //5++ returns 5 first then increments, so 5 will be multiplied to 2
y = 10 + (--10)
y = 10 + 9 //--10 decrements first then returns so --10 decrements to 9 first
y = 19

mrnutty 761 Senior Poster

There are better ways of doing it, here is one examples.

typedef std::vector<int> Matrix; //alias

Matrix getMatrix(){
 return Matrix(10,1); //returns an array with 10 elements each initialized to 1
}
int main(){
 Matrix m = getMatrix();
 for(int i = 0; i < m.size(); ++i){
   cout << m[i] << endl;
 }
}
mrnutty 761 Senior Poster

Adding to above, change this

ANew() : ArrayOfTypes(0) {}

to this

ANew(){}

The vector will be default constructed already

mrnutty 761 Senior Poster

Thank you all for the replies. Do you guys have any online references? I'm mainly trying to find online resources.

Wiki is usually a good place to start!

mrnutty 761 Senior Poster

I am working on this because it looks like fun. I am just wondering what the challenge is, implementation wise. I have a BoggleBoard class now, and a function in it called getAllMoves() this function takes an array of c-style strings and an integer array length. Should I return an array of the possible c-style strings that can be made using the tiles on the board, or should I return just the best possible word, or what?

You solution should print out all possible words that can be created by the boggle board. Note the word has to be of length 3 or greater.

mrnutty 761 Senior Poster

Check out the wiki for boggle.

You job is to create a program that generates all possible words that can be constructed given the boggle board and a dictionary. A word has to be of length three or greater and the word has to exist in the dictionary.

For example check out this example.

The result should be sorted and unique and be printed out to the console. On my mac, my current time for a 100x100 board is 15 seconds, and for a 4x4 board 0.10 seconds. See if someone can beat it. But note, that my hardware might be better than yours or worse, so to be fair, we might actually need to compare in a controlled environment( ex. post your solution and I'll time it on my mac).

Good luck guys!!!!!

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

When you run a program, it creates a process for that program. So when you call exit within that process, the os kills that process and cleans up memory. As for its actual implementation, I do not know. It is most likely implementation specific, that is I don't think there would be one set of implementation that all would follow. But as homework you can create your own exit function using winAPI, by manually deleting the associated process. Other than that, I don't believe you should worry about its details too much.

mrnutty 761 Senior Poster

You can look at previous days/weeks/months/years data and observe the context at which the price was stated and then look at the current situation of the stock/company then make a educated prediction based on the information.

mrnutty 761 Senior Poster

Sometimes it helps to see concrete examples:

int r1 = rand() ; //random number from [0 , RAND_MAX]
int r2 = rand() % 100; // random number from [0,100);  Note doesn't include 100
int r3 = rand() % 100 + 1; //random number from [1,100]; Note includes 100

const int max = 100;
const int min = -100;
int r4 = rand() % (max - min) + min; // random number between [min,max)

When you want to look up a function, you can see examples here. Bookmark it if you need to. Its a good reference

mrnutty 761 Senior Poster

The difference is purely semantics (and type-related), but that doesn't make the distinction a trivial one. Just like in English, we mean different things when we say "nothing", "no-one", or "nowhere", which correspond, analogously, in C++ to 0 , '\0' , and NULL (which was actually replaced by nullptr now). Just like in English, you won't say "this argument goes 'nothing'." or "I went to the mall, but at the end, I bought 'no-one'.", or "there was 'nowhere' left at the meeting when I arrived.". In C++, it's the same thing, each of these expressions are valid and meaningful in different contexts. The fact that they might have (and usually, do have) the same value to the computer (who doesn't care about semantics or context) is mostly irrelevant (unless you're actually doing the kind of low-level bit-tweaking code that requires you to know that). Just like the fact that "nothing", "no-one" and "nowhere", or any other expression to mark the absence of something, could all be mathematically interpreted as zero (or nil, or null, depending on your particular English dialect), but that doesn't make them all the same or equivalent, because, to us, humans, semantics and contexts are things that matter a lot!

Arguably, that's the most important thing that programming languages do, i.e., provide semantics and contexts, and tools (and rules) to organize them and obey them. We need that to be able to construct good software designs. So, don't say, because different things mean the same to a …

mrnutty 761 Senior Poster

Skip defines and macros. Use enums when you need type saftey and when it makes more sense.