Posts by JJoao • 5,113 points
222 posts
-
2
votes2
answers122
views -
3
votes3
answers129
viewsA: Split a string that contains scores
Based on the 99.9% response from @Acco... blatantly! preg_match_all('~\b\w[\w\-.*#]*\w\b|\w|\.\.\.|[,.:;()[\]?!]|\S~u', $t, $ps); print_r($ps) ( [0] => Array ( [0] => Baseando-me [1] =>…
-
5
votes1
answer2044
viewsA: Creating processes with Fork
In fact your solution is generating 2 10 processes (since each child with x=n will create grandchildren (with x=n+1 ... x=10), and these great-grandchildren, etc). Proposed: int main () { int i,…
-
1
votes5
answers1065
viewsA: Remove duplicated names with regular expression
gsub(".*[a-z]([A-Z])", "\\1", p) that is to say: de Morais, PrudentePrudente de Morais ..................eP ↓ Prudente de Morais…
-
3
votes1
answer3573
viewsA: Line in a flow chart in Xelatex tikz
Before the end of the figure, add one more path: \path [line,rounded corners=7ex] (teorias.west) -- ++(-1.5cm,0) |- (observacoes.west); (remove the rounded corners=7ex for connections with straight…
-
5
votes5
answers5611
viewsA: Draw square on the canvas using wire fences (#)
print ("#" * largura +"\n") * altura
-
3
votes1
answer2749
viewsA: Transform an array to string in python
"|".join(a) produces a string with elements separated by "|" '|C170|1|14879||1,00000|UN|29,99|0,00|1|..... 3010107010057|\n' Joining "|" at beginning and end: "|" + "|".join(a) + "|" or "|%s|" %…
-
0
votes2
answers75
viewsA: Deconstructing a perl-based one-Liner error occurs "Can’t Modify single ref constructor in scalar assignment"
it is not very clear what you are to do, but tries something like: perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=\1024};print md5($_)' or to make it more legible: perl -'MDigest::MD5 md5_hex' -ne…
-
2
votes3
answers3514
views -
6
votes3
answers2628
viewsA: How to optimize this function for Fibonacci sequence?
An approach memorizer, directly using the initial algorithm: var yourself = { cache:{}, fibonacci : function(n) { if (n in this.cache){ return this.cache[n] } if (n === 0) { return 0; } if (n === 1)…
-
1
votes1
answer189
viewsA: Syntax Error no lex/flex
In the sentence ESCREVER 1; the space ' 'is matching the rule . {return yytext[0];} that is before the rule that processes spaces and catches string with the same length. This returns the symbol ' '…
-
0
votes2
answers258
viewsA: Remove stopwords listed in a txt file from another txt file
If we are in Linux environment, and if we can use Sed and Perl proposed... sed -rf <(perl -00nE 'say "s/\\<(",join("|",split),")\\>//g"' stopw.txt) l.txt Example: $ cat stopwords a de que…
-
2
votes2
answers4111
viewsA: Copy string from a given character
I suggest using sscanf. Example assuming fixed length fields 14,20,20: #include <stdio.h> int main(){ char texto[] = "cod 1234567890 Joaquim da Silva 933322232"; char a[30], b[30],c[30]; if(…
-
1
votes4
answers8334
viewsA: How to list all tables in a Sqlite database?
sqlite3 fffffff.sqlite .tables
-
2
votes2
answers110
viewsA: Why is the output coming out like that?
The answer from @Luiz Vieira, is perfect. Together only one more variant: use of filter (pass only the values approved by a filter function). Example: lista=range(11) par = filter(lambda x: x % 2 ==…
-
15
votes8
answers3166
viewsA: Fewer moves from a horse to a given house in Chess
Proposed strategy: see this problem how to find path in graph: nodes = positions on board; branches = horse jumps; calculate the list of all horse jumps (=branches) -- list in understanding; based…
-
5
votes3
answers756
viewsA: Get larger number of items in a Python list array
Other version: max(map(len,matriz))
-
2
votes4
answers2433
viewsA: Count the number of times a character appears in a string
By the way using Perl: perl -nE 'say tr!/!!' <<< $v_dir_relatorio The command tr (which turns the character set of the first group into the corresponding of the second) returns the number…
-
2
votes3
answers242
viewsA: table html shellscript
Assuming the html code is in file.html, grep -Po '<li>\K.*(?=</li>)' file.html
-
1
votes2
answers479
viewsA: Handling dates in AWK scripts
In relation to date arithmetic I present below a hypothese of this time with perl Assuming the F file looks like this: timestamp | legume | preço 2008-07-31T21:42:52.667 | batatas | 30…
-
2
votes1
answer96
viewsA: How to convert a normal integer name to its bibliographic format in c?
char* nome="Leonel da Silva Messi"; char* aux=strdup(nome); // aux = cópia do nome char* ue=strrchr (aux,' '); // apontador para o ultimo espaço *ue='\0'; // aux = "Leonel da…
-
1
votes2
answers803
viewsA: Recursive search for files in directories
As it was said that it was in linux, I can’t resist remembering that C allows us to take advantage of the operating system (=a little cheating ). Using popen: #include <stdio.h> #include…
-
5
votes2
answers297
viewsA: List Comprehension for this case
(as @stderr simultaneously suggested), in this case the simplest is to concatenate(ie +) the "a" to the list in comprehension novalista = [a] + [num for num in lista if num%2 == 0]…
-
0
votes2
answers981
viewsA: Modify xml in multiple files
If you can use perl, here’s a suggestion: perl -i -pe 's!<VDesc>.*?</VDesc>!<VDesc>0.00</VDesc>!s' *.xml If you prefer to create a backup of the original (a. xml ,…
-
2
votes2
answers96
viewsA: Decimal counting in nodes
What I’m going to say is probably an irrelevant comment... The number 0.01 is tricky: it has no exact representation in normal binary notation (periodic infinite tithe). Try something like for(var i…
-
2
votes3
answers763
viewsA: I need to validate a TXT layout in C#
@Britto, in an analogous situation, I used awk/gawk, with enough versatility. I know that the solution I point out does not meet the conditions you refer to, yet I think it might be useful.…
-
2
votes2
answers5730
viewsA: Problem with Latex Figures Skipping Paragraphs
This answer is actually a longer comment... As @Avelino very well said, \begin{figure}[H] can be used to force a figure to be inserted at that exact point. This operation force figures or tables to…
-
1
votes4
answers1228
viewsA: Alternative to sed with Powershell
By the way, the Strawberry-Perl for windows comes with some utilities (gcc, Compile tools, libraries, database interface, etc). Provides a Unix perl-like development environment. then an example…
-
0
votes1
answer203
viewsA: XML returning strange characters
...This is not really a response, it’s more of a difficult comment: Your XML file is corrupted: denotes two different mixed encodings: the first paragraph of despription is in UTF8 (probably coming…
-
3
votes3
answers1007
viewsA: Parity test in C
Be it x composed of 8 bits x=(a b c d e f g h) Parity(x) = xor( a b c d e f g h ) The xor operator in C is ^. int check(unsigned char x) { x ^= x >> 4; // x = abcdefgh xor 0000abcd = a b c d…
-
2
votes4
answers715
viewsA: What’s wrong with the c-code?
Sorry again, but I liked this problem! and I can’t resist to propose yet another solution with another alternative algorithmic path: grammars! Being the statement of the problem that is intended to…
-
1
votes10
answers1739
viewsA: How to count the zeroes to the right of a number?
Assuming entries to be a number per line, follow 4 solutions oneliners a little Machiavellian. Version Perl 1 perl -nE '/\d(0*)\b/g and say length($1)' Explanation para cada linha ∈ texto ⎪ perl -n…
-
8
votes4
answers715
viewsA: What’s wrong with the c-code?
The code presented although quite close to responding correctly, has 3 problems: j < sizeof(exp) that is to say j < 3000000 will lead to what *p is accessing to potentially uninitialized…
-
4
votes4
answers715
viewsA: What’s wrong with the c-code?
Perl is almost C perl -ne ' while( s!\(\)|\[\]|\{\}!! ){}; print (/\S/ ? "N\n" : "S\n")'` ex1 Update: explanation The problem posed is interesting. Just for asking "where is my mistake?" (I tried to…
-
0
votes1
answer42
viewsA: Error generating section title references when using amsmath package
Function definition is correct (and works perfectly) (check only if the \usepackage{...} is in the preamble (i.e. before the \begin{document}) the issue of bibiography is something completely…
-
4
votes1
answer3950
viewsA: Change figures numbering in Latex
I assume that 2.1 is Figure 1 of Section 2... In that case, in the preamble, we join: \usepackage{amsmath} \numberwithin{figure}{section} For the numbering of figures to include the section number…
-
0
votes2
answers310
viewsA: Json Array for C#string array
Using the line command jq: jq ".chatters.moderators,.chatters.viewers" ex.json produces: [ "gumagames", "juliavidoto", "nightbot", "pinkpanthersz_", "victoriia66" ] [ "andreschramm",…
-
1
votes2
answers1420
viewsA: Read numbers separated by commas
awk is almost C awk -F, '{print $6}' arquivo.txt Simplified explanation: Internally awk divides each row into fields (in this case the field separator is , due to -F,), each field is assigned a…
-
6
votes6
answers4038
viewsA: What is lexical analysis?
Everything has been said; however I like language processors, and I cannot resist setting an example here in this case Lex+Yacc. Statement: given a CSS (simplified, I will take as an example the…
-
1
votes2
answers27
viewsA: Reallocate line to a certain position of another line
Using vim (assuming that the vim installed and supported for Perl, as usual) :perldo if (m!// (.*)!){ push(@a,$1)}; :perldo s/''/"'".shift(@a)."'"/e 1 guard in vector @a the values started by //…
-
2
votes2
answers143
viewsA: Copy all before the first blank line
The following command creates files "output1", "output2", etc., with each block. awk -v RS="" '{print > "output" NR }' input.txt Explanation: RS="" records separated by one or more blank lines…
-
0
votes2
answers1858
viewsA: Shell script Sed read one file and write to another only on the first occurrence of a string
perl -p0e 's/(, pasta)/"$1\n" . `cat teste.txt`/e ' Report.html i.e.: replaces the first occurrence of ", pasta" by the result of eval("$1\n" . `cat teste.txt`) (perl -0 ... file loads the whole…
-
1
votes2
answers2307
viewsA: Delete all lines that have a specific string
Using Perl: perl -n0E 'say grep !/Excluído/ , split(/(<p class="FolderPath">.*?<\/p>)/s)' where: split(/(<p class="FolderPath">.*?<\/p>)/s) divides the input file by…
-
2
votes1
answer444
viewsA: Class complexity P and NP
John, Foreplay Your question is unclear! If it is really "What is the complexity of the P/NP class?" the two displayed automatics are doing nothing -- I assume that’s not what you want. For the…
state-machineanswered JJoao 5,113 -
2
votes2
answers89
views -
0
votes2
answers121
viewsA: Can I return a struct by initiating it into a Return in ANSI C?
@pmg has said it all (+1); Just one more variant: typedef struct Result { int low, high, sum; } Result; Result teste(){ return (Result){0,100,150}; } int main(){ printf("%d\n",teste().sum); return…
-
1
votes1
answer851
viewsA: Extract information from a text file with shell script and regular expressions
I’m not sure I fully understand your request... In the example below the polarity of a file is calculated. Actually this is bash but with small changes should work as ksh... #!/bin/bash pos=$(grep…
shell-scriptanswered JJoao 5,113 -
1
votes2
answers1591
viewsA: Receive file lines, and treat them (BASH)
Excuse me: this is more a set of comments than an answer... As an alternative to what you wrote, I suggested: use of while read varinstead of the for (because of the spacing) use of arrays (It would…
-
25
votes15
answers4487
viewsA: Determine if all digits are equal
Playing riddles of black magic: 1) A perl command that reads from STDIN and writes OK if all numbers are equal perl -E 'say "OK" if <> =~ /^(\d)\1*$/' 2) an algorithm: f(a) = int((a*9+10)/10)…
-
1
votes5
answers6427
viewsA: How do I list the files in a directory and subdirectories that contain specific text on Linux?
ack regExp diretorio ack regExp