« first day (228 days earlier)      last day (2624 days later) » 

1:55 AM
How can I do this? "https://gist.github.com/aurelianopinheiro/a73b0f501df41cb2d01d7b72249959d5"
 
 
3 hours later…
4:37 AM
do what
 
 
5 hours later…
9:35 AM
Hello guys,
I've a question about a design pattern
specifically decorator
I can't actually get the difference between decorator and strategy
in this question
24
Q: Strategy Pattern V/S Decorator Pattern

Nirav KamaniI am learning some design patterns. I just came across two patterns. Strategy Pattern Decorator Pattern According to implementation i found both of them some what confusing. What i understood is:- Strategy Pattern :- Strategy pattern gives several algorithms that can be used to per...

one of the answers says that the the decorator
"augment" while the strategy changes
I've seen the examples but I can't see much difference
can any of you explain to me in a very nutshell the difference?
and if the "augmentation" that the decorator achieves also can involve "augmenting data"
(like augmented data structures)
 
9:55 AM
We are planning to use netbeans IDE in our project with C++, i proposed using netbeans but my manager asked about the license to use it ..
As per the license terms :: This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means.
 
 
1 hour later…
10:56 AM
@Karti
@KartikV, you should contact a lawyer, nothing said here will have any validity.
 
not to mention it refers to a separate agreement with netbeans which if you got it online you probably don't have or just clicked through
 
On a different line... I'm using CUDA, hope someone listens. Compiling ffmpeg via Mingw32, I get the following error LNK2019: unresolved external symbol _cuInit referenced in function _main...

This is because what's inside cuda.lib on Windows is "_cuInit@4", and the name mangling makes the linker fail. FFmpeg is C code, so it has no mangling, I cannot change the mangling on cuda lib right?
 
you could make a def file to rename symbols
 
But don't I need to rebuild cuda for that?
 
11:15 AM
This is odd to me, can't cuda be linked from C programs? Wouldn't this problem always happen?
 
@SergioBasurco __cdecl vs __stdcall
@ratchetfreak renaming will only delay the problem till run time, since the calling conventions are different
 
so I need to change conventions for ffmpeg
thanks will look into it
 
@SergioBasurco there's no C++ name mangling, but there's C name mangling. _cuInit is the C-mangled name of cuInit on 32 bit systems
__stdcall is callee-clean calling convention and it mangles the name cuInit to _cuInit@HOW_MANY_BYTES_ARE_PASSED_IN
it's 4 which means it gets passed a single pointer or integer
 
I see
 
You'll be delighted to know that 64-bit Windows doesn't have that problem
 
11:30 AM
Seems to be the CUDAAPI definition, which depends on _WIN32... yup that makes sense
Why doesn't win64 have it?
 
because there's only one commonly used calling convention there
 
@milleniumbug finally! :)
 
(there's also __vectorcall but most people don't use it since it only helps if you use SSE on paraneters)
 
where did you learn all this stuff?
 
this specific one I've learned on my uni
 
11:34 AM
experience and finding people talking about it
 
otherwise the rest is like ^
 
No luck with the cuda build..
Let me wrap what I've gathered
c99wrap cl -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Dstrtod=avpriv_strtod -Dsnprintf=avpriv_snprintf -D_snprintf=avpriv_snprintf -Dvsnprintf=avpriv_vsnprintf -D_WIN32_WINNT=0x0502 -nologo -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_WIN32 -IC:\cuda_8\include -c -Fo./ffconf.2Zx4GpNv.o ./ffconf.dxUuwqkd.c
ffconf.2Zx4GpNv.o_converted.c
./compat/windows/mslink -LIBPATH:C:\cuda_8\lib\Win32 -nologo -LARGEADDRESSAWARE -out:./ffconf.GqaA33E5.exe ./ffconf.2Zx4GpNv.o cuda.lib psapi.lib advapi32.lib shell32.lib
^This is the line that seems to fail

This is what cuda.h has:

#ifdef _WIN32
#define CUDAAPI __stdcall
#else
#define CUDAAPI
#endif
This is the method that fails:
CUresult CUDAAPI cuInit(unsigned int Flags);
 
seems like the _cuInit is build using C mangling and cuda.lib has _cuInit@4 mangling right?
built*
 
any of you familiar with boost graph library?
 
11:44 AM
is there any way to make the build use the same naming conventions as the cuda.lib library? so it looks for the correct mangled name?
 
11:56 AM
@user8469759 Don't ask to ask
 
What?
 
That
 
I've asked a question
 
Means you should just ask your question, if anyone knows about boost graph they'll help
Ask the specific question
 
I've just downloaded the library, for windows
but I'm not sure how to install it
I don't see any makefiles
or something similar
(boost 1_60)
 
12:00 PM
boost library is usually self contained in the .h, therefor the classes will be compiled when you include them in your source
 
I like this sentence
"The first thing many people want to know is, “how do I build Boost?” The good news is that often, there's nothing to build."
 
and
this is the link you were looking for probably
 
#define _WIN32 // let's pretend we're Visual C++
#include <cuda.h>
#undef _WIN32 // stop pretending
@SergioBasurco hackish workaround
 
12:03 PM
I don't understand
are they basically only header files?
 
So I just need to include them and use
?
 
> Boost.Graph also has a binary component that is only needed if you intend to parse GraphViz files.
do you intend to parse GraphViz files?
 
Foo.h
class Foo
{
Foo() { // header defined here, no need for cpp }
};
 
if not, then you have nothing to compile, just include the headers
 
12:04 PM
this Foo class is self contained
you can include it in your project and you dont need a Foo.lib because it doesnt exist
same with boost libraries
 
@milleniumbug Will try.. but I defined -D_WIN32 for the cl command, should be the same
 
What's a more efficient way of finding the lowest common multiple other than brute forcing it?
of two numbers
 
euclids algorithm
 
In arithmetic and number theory, the least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b. Since division of integers by zero is undefined, this definition has meaning only if a and b are both different from zero. However, some authors define lcm(a,0) as 0 for all a, which is the result of taking the lcm to be the least upper bound in the lattice of divisibility. The LCM is familiar from elementary-school arithmetic as the "lowest common denominator" (LCD...
 
to get the greatest common divider and then a*b/gcd(a, b)
 
12:18 PM
And how do i find gcd?
 
In mathematics, the greatest common divisor (gcd) of two or more integers, when at least one of them is not zero, is the largest positive integer that is a divisor of both numbers. For example, the GCD of 8 and 12 is 4. The greatest common divisor is also known as the greatest common factor (gcf), highest common factor (hcf), greatest common measure (gcm), or highest common divisor. This notion can be extended to polynomials (see Polynomial greatest common divisor) and other commutative rings (see below). == Overview == === Notation === In this article we will denote the greatest common...
 
Thank you
I'm doing some challenges to practice for a competition, don't know whether to learn more efficient algorithms or not since they don't influence the grade in any way
 
knowledge is power
 
brute force is fast enough if the numbers are small
 
The numbers are between 1 and 500
so they are small enough i guess
 
12:21 PM
@sweg_yolo_69 not in the grade but it will surely influence you ;)
 
a quarter million modulo operations is pretty dang fast nowadays
 
I'll give it a go with lcm and gcd
 
12:42 PM
So, this is what I came up for calculating gcd
int gcd(int a, int b) {
if(b > a) {
std::swap(a, b);
}

while( a % b != 0) {
b = a%b;
a = b;
}
return a/2;
}
Math seems to be correct, but don't know why
Or maybe it isn't...
 
How can I go through a word but only it´s lenght with a n int?
 
you loop over it until you hit n
 
Yeee, I did it
that code above is wrong though
But I can't seem to wrap my head around fibonnaci
Given a number n, I need to print out every fibonnaci number <= n
 
for(int i = 1, f = fib(i); f<=n;i++, f = fib(i)) print(f);
i doesn't need to be the exit condition
 
12:57 PM
and fib is fib(n-1) + fib(n-2) ?
 
or turn it around and do:
int i1=0, i2=1;
while(i1<=n){
    int t = i2;
    i2+=i1;
    i1 = t;
    print(i1);
}
aka the iterative version and insert a print in the correct place
 
Well I know how to print out the `nth` fibonnaci number, so I guess I given an `int i`, i would print out
while(i != 0) {
fib(i);
i--;
}
i is always positive
Though that would print them in reverse
but yeah, i get the idea new
now*
Yeeee, I did this as well
Although I still don't understand how fib(n-1) + fib(n-2) is supposed to work. I guess I'll just have to take that for granted
 
that's a really slow algorithm
because it ends up calling fib(0) and fib(1) fib(n) times
and fib grows exponentially
 
1:13 PM
I want to post my code, but how do I format it like in your previous message?
 
past and then press the fixed font button that pops up
 
int fibonnaci(int a) {
    if(a  <= 1)
        return a;
    return fibonnaci(a-1) + fibonnaci(a-2);
}

int main() {
    int i, start = 1;
    std::cin >> i;

    while(fibonnaci(start) <= i) {
        std::cout << fibonnaci(start) << std::endl;
        start++;
    }
}
 
or if it's really large use a paste site
 
I know that I calculate fibonnaci twice
so I could maybe put that in a variable
But hey, it works
 
the solutions to that performance degradation is memoization, passing extra data around or turn it around and do it iteratively
even with fib(100)?
 
1:17 PM
I'll give it a try
but the site I used passed the code on several different tests
Yep
Output is as expected
 
1:34 PM
I believe I'm missing something
I have this silly main
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/topological_sort.hpp>
#include <boost/graph/graph_traits.hpp>

using std::cin;
using std::cout;
using std::endl;

int main(int argc, char** argv) {
	// Create a n adjacency list, add some vertices.

	boost::adjacency_list<listS, vecS, directedS> g;


	return 0;
}
And it doesn't compile
(It's cut and pasted)
I've used the -I flag to specify where the boost root is
 
what's the error message?
 
it was stupid apologies
basically listS etc
I needed to specify the boost namespace
 
 
1 hour later…
2:38 PM
This whole code compiles fine and run
but It doesn't do what I'm expecting
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/topological_sort.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/edge_connectivity.hpp>
#include <string>
#include <map>

using std::cin;
using std::cout;
using std::endl;
using std::map;
using boost::vecS;
using boost::listS;
using boost::directedS;

int main(int argc, char** argv) {

	int i;

	typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS> Graph;
	typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
it's just a main
 
 
2 hours later…
4:30 PM
I made it work, it was another stupid error
 
5:21 PM
Given input in the form of:
"4 3"
"2 3 2 1"
through STDIN how can I interpret it so that I get all of the values in separate variables/a vector?
The first number of the first line signifies how many numbers will be in the second line
 
readline and then parse each line separately
 
I only know std::cin for reading input
Any help :p
 
what kind of vector are you expecting?
from your example
 
What i want, given the input above, is to somehow capture all the variables
basically add the last line of input to a vector of ints
 
I'm not sure I understand what output you should have from that input
and what's the second number in the first line represent?
sorry I meant
what does the second number in the first line represent?
 
5:36 PM
Well it's a coding challenge, but I can't even get the input in a workable manner, so what I want is to get the second line of input in a vector
 
So you're expecting from your input a vector<int> v = {2,3,2,1}
?
is that right?
 
5:48 PM
int size, something;
std::cin >> size >> something;
std::vector<int> number;
for (int i=0; i<size; i++) {
    int temp;
    std::cin >> temp;
    numbers.push_back(temp);
}
 
 
2 hours later…
8:09 PM
How do you properly parse input when you have an unknown number of lines with an unknown number of ints in each line?
 
nice name
 
1 message moved from Lounge<C++>
 
I only know how to do it with std::cin but that won't work
@littlepootis ty :)
 
1 message moved from Lounge<C++>
 
Can you also move this message?
 
8:11 PM
3 messages moved from Lounge<C++>
@sweg_yolo_69 read entire lines with std::getline, split the lines by using std::stringstream
 

« first day (228 days earlier)      last day (2624 days later) »