Posts by Lucas Virgili • 3,092 points
48 posts

1
votes1
answer168
viewsA: Division of a line into a number of segments
Diophantine equations A Diophantine equation is a polynomial equation in which only integer solutions are desired (more information on wikipedia). In your case, you want to solve the following…

6
votes3
answers31819
viewsA: Random number range in C
To generate random integer values in C in the range [a, b): a + rand() % (b  a) For example, x % 5 can be one of the values 0, 1, 2, 3 or 4. So when do we rand() % (b  a) let’s generate a number…

0
votes2
answers207
viewsA: Method and Subprogramme
All the same thing. From wikipedia: In Different Programming Languages a subroutine may be called a Procedure, a Function, a routine, a method, or a subprogram. The Generic term callable Unit is…

3
votes2
answers190
viewsA: Delete repeated values
You can create other tables and use as "signal" variables (flags) to see if the element is already in the array. If your table has tables inside, just iterate for each table inside the first table:…

1
votes1
answer1849
viewsA: I’m not able to calculate the auto values and auto vectors of a matrix
And only use the function eig. For example, if your matrix calls A: [V, D] = eig(A) V is a matrix that the columns are the eigenvectors on the right and D and a diagonal matrix with eigenvalues.…
matlabanswered Lucas Virgili 3,092 
8
votes4
answers9003
viewsA: Invert a 3digit number in C
If you need a function that reverses numbers of arbitrary size: int inverte(int x) { int inv = 0; while (x > 0) { inv = 10 * inv + x % 10; x /= 10; } return inv; } What she does is take the rest…

1
votes1
answer284
viewsA: Initial end term of the Fibonacci sequence (closed interval)
The Fibonacci sequence and defined as follows: F(1) = 0 F(2) = 1 F(n) = F(n1) + F(n2), se n > 2 That is, the sequence begins with the terms 0 and 1 and from there the next terms are the sum of…

4
votes2
answers295
viewsA: Why did a dynamic array work without the use of malloc()?
Arrays with variable size are allowed from the C99, as you can see here. According to the same link, these arrays function like any other of size which is a constant expression, so it has the same…

2
votes1
answer470
viewsA: Pair de vector c++
make_pair is not an instance method x, and a method that returns a pair. Therefore, Voce needs to use so: x = make_pair(custoMinimo, push_back(caminho))…
c++answered Lucas Virgili 3,092 
0
votes3
answers280
viewsA: How to Show the file path opened in VIM
You can run an external command by vim with the syntax :! comando. The command pwd returns the directory you are in. Soon: :! pwd

25
votes2
answers40473
viewsA: How to create a vector of variable size?
Once you have declared the vector, no. However, you can make the vector have different size depending on the user input. For example, if we want the user to enter a value for the vector size, we can…
canswered Lucas Virgili 3,092 
9
votes8
answers481
viewsA: I can’t learn syntax for
The variable does not go out of scope (it is not "deleted") so the for ends, then the i gets the ultimate value from it. The last comparison in your example is with i = 10. He does 10 < 10, which…

1
votes1
answer10434
viewsA: Replace a string character with an asterisk
To iterate over a string in C is usually done like this: #include <stdio.h> #include <string.h> int main() { char s[128]; gets(s); for (int i = 0; i < strlen(s); ++i) { printf("%c",…
canswered Lucas Virgili 3,092 
2
votes1
answer69
viewsA: How is an integer pointer variable stored?
This works by the symbol table. When Voce does int *x; compiler goes in this table, allocates a 4 bytes space in memory and associates the address of that location with the name x and the guy int *.…
canswered Lucas Virgili 3,092 
2
votes2
answers391
viewsA: Why comparing a variable to None should be done using is or is not
They are different. The == invokes the method __eq__ of the class to his left. Ja the is really compare equality. In that case, however.
python3.xanswered Lucas Virgili 3,092 
1
votes1
answer1060
viewsA: C/C++  Error comparing char with strcmp()
You are comparing characters and not strings. Just do if (cEmail == simbolo).

1
votes1
answer1364
viewsA: How to use the Curl library for c++ correctly?
Apparently Voce needs to link the library. In the Dev Voce build options you need to put lcurl. According to that answer, You also need to add the directory: Project > Project Options >…

1
votes1
answer102
viewsA: C programming error, how to make it work
1) You are going through the string wrong way. A for is executed as the logical condition of it, the second parameter, is true: for (inicializacao ; condicao; passo) right? Now think: if yours i…
canswered Lucas Virgili 3,092 
0
votes1
answer73
viewsA: Is it possible to create an Std::list with an initializer_list?
Works for me: #include <iostream> #include <list> template<typename T> void mostra(const std::list<T>& myList) { for(T var : myList) std::cout << var << "\n";…

3
votes1
answer139
viewsA: Doubt in the complexity analysis of an algorithm
and very simple :) when n > 1, the function makes an operation that has constant time, multiplication, and makes a recursive call that has size n  1. so the recurrence is: T(n) = T(n1) + 1 (ou…

3
votes6
answers2305
viewsA: Transform results combination function into a dynamic function
I do not know JS, but I will explain a solution and show in C++, should not be difficult to translate. One caveat: this type of algorithm has a disgusting complexity and soon stops working. For…

21
votes1
answer8180
viewsA: What is a minimal generating tree?
One generating tree in a graph you already know, even without knowing! Think of this graph here (which turned ugly, but for something automated until it’s ok :P) A generating tree is simply a set of…

1
votes3
answers474
viewsA: Getting Output Terminal History on Ubuntu
Well, it’s not very pleasant to read, but it works: Before you start using the terminal (and assuming Voce uses bash, which is the default shell on Ubuntu): bash  tee bash.output At the end, you’ll…

3
votes1
answer4146
viewsA: Stock and sales control
The problem with your code is that you call the function several times main. Besides being a little weird, what Voce ends up doing and redeclareting everything, including its vector of produto. A…

3
votes2
answers132
viewsA: How to create a popup warning that the script has come to an end?
Well, your answer is a possibility. Another and use the package ring. For this, Voce will need to have installed Tcl/Tk and the Bwidget package. Then, inside the R, knife: install.packages("rpanel")…

4
votes4
answers1844
viewsA: Factoring in Javascript
NOTE: I don’t know if you set your example wrong, since 13 not and divisible by 3 or if that’s what you want it to be displayed. If it is comment I update my reply. I will write in C, since I don’t…
javascriptanswered Lucas Virgili 3,092 
2
votes2
answers93
viewsA: What is the difference between these expressions?
He’s doing the cast implicitly, which has no problems in some cases. For example: int x = 3; double y = 4.5; x = x + y; What happens in these cases and the following: 1. Na soma de `x` com `y`, `x`…

4
votes1
answer347
viewsA: interpretation of quicksort
Quicksort works, in pseudo code, as follows: 1) Escolha um elemento do vetor, chamado de pivo. 2) Ordene o vetor de forma que todo elemento menor que o pivo esteja a esquerda dele e todo elemento…

67
votes1
answer722
viewsQ: Why (!+[]+[]+![]). length returns 9 in Javascript?
I just read that article and in it there is this expression: (!+[]+[]+![]).length Evaluating this in the interpreter: > (!+[]+[]+![]).length 9 Good, why?…
javascriptasked Lucas Virgili 3,092 
3
votes3
answers8272
viewsA: How to call external command with Python?
And very simple: import os os.system("ls")

3
votes1
answer329
viewsA: Pointer of struct in C
You do not change root at the function. You need it to receive a pointer to a pointer of type Node so that the value is not lost after the function returns. That code: #include<stdlib.h>…

2
votes1
answer175
viewsA: Problem with echo` e`
The problem is not with your script, it is perfect :) The problem is only with your shebang: # !/bin/bash If you delete the space between the # and the ! everything will work. With this space the…

5
votes1
answer141
viewsA: Error of logic?
There is no error in your code. Prolog is returning all pairs (X,Y) that satisfy the query avo(X,Y). He would return true if Voce asked a question where both the "variables" X and Y "have some…
prologanswered Lucas Virgili 3,092 
1
votes1
answer63
viewsA: Reading values from a C file
I’ll assume that Voce can read every line in your file, okay? This code here takes every number of a line: #include <stdio.h> #include <string.h> int main() { char linha[] = "10 100…

0
votes2
answers148
viewsA: Code refactoring in C
The first conditions in the else if, so much for the precoAtual how much to vendaMedia, are the complement of conditions in if. Therefore, Voce can take the first check, since if precoAutal it is…

4
votes3
answers1021
viewsA: Iterated inline functions
Compiling with the g++ 4.8.1, with the option O2, both excerpts above have exactly the same Assembly code (with the exception of the names of the Abels). Therefore, there is no difference and no…
c++answered Lucas Virgili 3,092 
2
votes3
answers176
viewsA: Syntactic Sugar in PHP
According to the manual, yes and no. For example, they are identical: <?php $arr = array("one", "two", "three"); reset($arr); while (list(, $value) = each($arr)) { echo "Value: $value<br…

14
votes4
answers793
viewsA: Simple Teaching of Pointers
In fact, as @Dante said, the Feofiloff tutorial is very good, but I will try my own explanation. Suppose you have a memory with 5 positions. Each position has an address, going from 0 to 4: Endereco…

1
votes1
answer1273
viewsA: How to validate a regular expression text not allowing everything in white space?
A regex ^\S+$ has a match if the string is not empty and has at least one character that is not whitespace. Therefore, Voce can break its initial string into two parts, one from the beginning to the…

4
votes2
answers1037
viewsA: Use "ping" on a Python site
I assume it’s windows, right? That’s fine, I guess, I can’t test it. I took from here. from subprocess import check_output check_output("ping www.facebook.com", shell=True)…
pythonanswered Lucas Virgili 3,092 
4
votes1
answer124
viewsA: What’s the best way to make a minidecoder?
Without removing the letters k, y and w (which have been incorporated into the Portuguese alphabet in the new rule) (soon 'a' will be valid 26 and so on). Each character is already a number, and…
c#answered Lucas Virgili 3,092 
2
votes6
answers1170
viewsA: Why is it not possible to define an interface with static methods?
Because it would be a contradiction of how Java does to invoke a statistical method. A static method and independent of instances, correct? Therefore, it can be executed directly from the ". class".…

0
votes4
answers313
viewsA: Changing a random string of characters using Stringbuilder
(I don’t know C#, but I suppose this solution (in C++) works, with the right changes). int posicao = 0; // qual dos numeros na sua string numero estamos for (unsigned i = 0; i < mascara.size();…

2
votes3
answers302
viewsA: How to separate a file with multiple FASTA into different variables
This method is OK if your file is not too large: sub ler_fasta { my %seqs; my $header; my $seq; open (IN, $arq) or die "abrir o arquivo falhou $arq: $!\n"; while (<IN>) { if (/>/) { if…
perlanswered Lucas Virgili 3,092 
13
votes3
answers3787
viewsA: How to decompose a number into powers of 2
Remember that a number on the PC is represented in binary, that is, base 2. What this means is that the number is already a sum of powers of 2 when it is on the computer. An example: 44 = 1 x 2^5 +…
javascriptanswered Lucas Virgili 3,092 
8
votes4
answers12575
viewsA: What does "0x" mean at the beginning of hexadecimal numbers?
The prefix 0x identifies the number it follows as a hexadecimal constant, and the prefix 0 as a number in octal (base 8). For example, #include <iostream> using namespace std; int main() {…
hexadecimalanswered Lucas Virgili 3,092 
1
votes1
answer224
viewsA: Error reading %f and %e from a file in C
I can’t seem to reproduce your mistake. That code #include <stdio.h> int main() { /* int i; */ float x; char c1, c2; int ind = 0; while (ind < 2) { /* fscanf(stdin,"%d",&i); */…

3
votes1
answer8916
viewsA: Rows with same height in table in Latex
As Voce also used, the package tabularx and better to handle tables with large lines, as it makes the line break alone. To get all the cells of the same height I used the command \parbox. This…
latexanswered Lucas Virgili 3,092