Search found 14 matches

by brainiac1530
Sun Mar 02, 2014 5:51 pm
Forum: Resources
Topic: I'm bad at recursion
Replies: 4
Views: 7816

Re: I'm bad at recursion

One trick I've found is to have the recursive function be a member function of an object designed for that purpose. That way, each instance of the function has access to some common data, without having to drop it in the global scope, or worse -- copying it into every instance of the function. Keep ...
by brainiac1530
Sun Mar 02, 2014 5:30 pm
Forum: Programming languages
Topic: C++, computing with huge numbers and booleans.
Replies: 21
Views: 8936

Re: C++, computing with huge numbers and booleans.

Don't use double for clock(), it returns an unsigned integer type, the specific type is implementation-defined (I just use auto and let the compiler figure it out). Just do something like (stop-start)*1E3 / CLOCKS_PER_SEC at the end to "translate" to a number of ms. It seems that the clock interval ...
by brainiac1530
Sun Mar 02, 2014 5:06 pm
Forum: Programming languages
Topic: determining if a variable is an integer C++
Replies: 8
Views: 4892

Re: determining if a variable is an integer C++

I've solved a lot of problems here in C++, and I've only needed to do this once. You're probably doing something wrong if this is a frequent need. We work with square numbers frequently here, and generally the best way to do that is to generate an array/vector of square numbers by addition, and then...
by brainiac1530
Sun Mar 02, 2014 4:50 pm
Forum: Programming languages
Topic: Int/String conversion in C
Replies: 3
Views: 3236

Re: Int/String conversion in C

Check out http://www.cplusplus.com/reference/cstdlib/

Keep in mind in a C implementation this will be called <stdlib.h>, I think.
by brainiac1530
Sun Mar 02, 2014 4:40 pm
Forum: Programming languages
Topic: Big Integers in C++ [Partially solved]
Replies: 8
Views: 10281

Re: Big Integers in C++ [Partially solved]

GMP is the performance king. https://gmplib.org/ There are theoretically windows-friendly redistributions. If you find it impossible to install, as I did, boost includes a full-featured unlimited-precision integer. http://www.boost.org/
by brainiac1530
Sun Mar 02, 2014 4:01 pm
Forum: Programming languages
Topic: Entering Array in MATLAB (eg. Prob18)
Replies: 6
Views: 3219

Re: Entering Array in MATLAB (eg. Prob18)

If you know C or C++, you should be able to write any function you like in C and call it from MATLAB.
by brainiac1530
Sun Mar 02, 2014 3:56 pm
Forum: Programming languages
Topic: returning a vector C++
Replies: 4
Views: 3988

Re: returning a vector C++

Use return std::move(results) to guarantee no time is wasted copying the vector into a temporary object. std::move isn't actually a function, it's just a language directive to force a move-assignment. Most likely, the compiler will optimize out a copy, but this removes any doubt.
by brainiac1530
Sun Mar 02, 2014 3:52 pm
Forum: Programming languages
Topic: c++ numbers out of range
Replies: 9
Views: 6167

Re: c++ numbers out of range

You can and should do 97 without big integers (a 64-bit type will do.) It should take almost zero processing time -- there is a log-time algorithm that is ideal for it, and easily written.
by brainiac1530
Sun Mar 02, 2014 3:45 pm
Forum: Programming languages
Topic: Creating a sieve of Eratosthenes in C ++
Replies: 16
Views: 9189

Re: Creating a sieve of Eratosthenes in C ++

Use bitset (if the upper bound is definitely compile-time constant) or vector<bool> for the sieve process inside the sieve function, then return a vector of ints or whatever. That will cut the sieve imprint down by a factor of 32. The vector is useful here since it's impossible to predict exactly ho...
by brainiac1530
Sun Mar 02, 2014 3:34 pm
Forum: Programming languages
Topic: MPIR Question C++
Replies: 2
Views: 3125

Re: MPIR Question C++

Or use the compound assignment operator *= . I remember it being defined for the mpz_class, it will take default types or other mpz-types as arguments, and returns a reference to the original object, as expected for the operator.
by brainiac1530
Sun Mar 02, 2014 3:27 pm
Forum: Programming languages
Topic: Help initialising array in C++
Replies: 11
Views: 5513

Re: Help initialising array in C++

Let me suggest some alternatives. If you use std::array<bool,1000> Bools, you can use Bools.fill(true) to fill it with trues. If you use std::bitset<1000> Bools, it does default-construct to zero. Use Bools.flip() to set them all to true. Small bitsets ( < 64 bits ) could be initialized with an inte...
by brainiac1530
Sun Mar 02, 2014 3:15 pm
Forum: Programming languages
Topic: Weird issue with C
Replies: 11
Views: 7616

Re: Weird issue with C

This is one of the reasons I hate C-style arrays. Functions receive arrays as pointer variables. So it is possible for the function to receive a pointer to a different location than the initial position, or for that pointer to get incremented so that it points to the next position. This is probably ...
by brainiac1530
Sun Mar 02, 2014 3:04 pm
Forum: Programming languages
Topic: Programming Guidance
Replies: 3
Views: 2807

Re: Programming Guidance

If you're using C++, the easiest big integer to use is boost's. Get it at http://www.boost.org If you're using ordinary C on Windows, try to find a windows-friendly build of gmp. You might fail; I could not find a build that would compile on my computer (64-bit Windows 8). If you're using ordinary C...
by brainiac1530
Sun Mar 02, 2014 2:52 pm
Forum: Programming languages
Topic: C++ Programmers, how do you organize your code?
Replies: 2
Views: 3347

Re: C++ Programmers, how do you organize your code?

I don't use visual studio, but I imagine it is quite possible to make one project. There is typically no reason to use a header file for these problems, though some exceptions exist -- the monopoly and poker problems merited additional files. I prefer to use a separate directory and project for each...