mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2010-09-08, 16:35   #1354
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Code:
substring(string_to_search, string_to_find)={
  my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);
  for(i=0,#s1-#s2,
    good=1;
    for(j=1,#s2, if(s2[j] != s1[j+i], good=0;break));
    if(good, return(1))
  );
  0
};
is there a way to create 2 Vec() on the fly to read the parts around the string into and then put out the result of those 2 and the replaced word in between into another that you can return later the only thing with this idea I don't see happening is skipping ahead the length of the new word inserted and making the loop realize to go until the new end of the string. I know I'm annoying lol.
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 17:15   #1355
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

got it partly in place now I need a way to get the string after s2 is found and I may have something closer to what is needed.

Last fiddled with by science_man_88 on 2010-09-08 at 17:15
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 17:17   #1356
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

I can't understand you, but I'm glad my script seems to have been useful, either as inspiration or as a tool.
CRGreathouse is offline   Reply With Quote
Old 2010-09-08, 17:28   #1357
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
I can't understand you, but I'm glad my script seems to have been useful, either as inspiration or as a tool.
yeah I found a few shortcuts I think that I didn't know before to help me with long winded scripts so I don't have to hold down left/right ctrl +a is one I found helpful.


Code:
substring(string_to_search,string_to_find)=my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c=Vec();for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);if(good,return(c)));0;eturn(c)));0;
still not perfect in one sense and I'd want another vector to take from the end of the s2 found in s1 to the end to create a new s1 in one sense with the word/phrase replaced with something understandable.

changed c=Vec() to c="" and works better still.

Last fiddled with by science_man_88 on 2010-09-08 at 17:31
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 17:44   #1358
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

my computer is weird and i can't find a virus weird anyways just insert a few things into your script for the vector and i can show you how to have fun with it lol.
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 18:00   #1359
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Code:
substring(string_to_search,string_to_find)=my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c="";for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);break));if(good,return(concat(c,"loser!"))));0;
this should be accurate CRG if you put:

substring("Shut up 3.14159","3.14159")

you should get a return of "Shut up loser!" something tells me someone will care lol.
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 19:03   #1360
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

(Be nice!)

So your function (which should be called something like "replace") looks for the second string in the first. If it finds it, the function removes the found part and everything after it, replacing it and everything following with the fixed string "loser!" in this case (probably a third argument in a polished version). If the second string isn't found, it returns 0.
CRGreathouse is offline   Reply With Quote
Old 2010-09-08, 19:09   #1361
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
(Be nice!)

So your function (which should be called something like "replace") looks for the second string in the first. If it finds it, the function removes the found part and everything after it, replacing it and everything following with the fixed string "loser!" in this case (probably a third argument in a polished version). If the second string isn't found, it returns 0.
or an error in the polished version to tell them none of this subgroup of the descriptions were found technically I want the final phrasing returned including the part after replacing then we can use substring to check for other substrings. in a for loop we could all a Vec of Vec that tell which Vec to check the descriptions in. yeah i know complicated lol.
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 19:56   #1362
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

put this :

Code:
;for(x=i,#s1-1,d=concat(d,s1[x+1]));
before the return and i think that's what I can do so far (still want it to check the rest of the string if i can do a simple replacement part I have a way with vector concatenation I think ,concat the index it finds it at into an array then use that array to do the replacements)


Edit: declare it first near where c is declared if you go this way.

Last fiddled with by science_man_88 on 2010-09-08 at 20:04
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 20:18   #1363
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

I think there's an easier way:

1)find s2 in s1 record all until you found s1 in c (like I already have working)
2)have a replacement Vec of Vec with a value to replace S2 with
3)concat c and the replacement value onto a new variable.
4)clear C out;
5)Repeat 1..4 as needed until end of search for that string
6)change to a new Vec of Vec.
7)Repeat 1..6 until every search is done.
8)print out the result ? (maybe start finding a script to interpret what it's figured out.)
science_man_88 is offline   Reply With Quote
Old 2010-09-08, 21:36   #1364
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Code:
%113 = (string_to_search,string_to_find)->my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c="";d="";for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);break));if(good,d=concat(d,(concat(c,"loser!")))));return(d)
(18:32) gp > substring("hello Alex, Good bye Alex","Alex")                                ))));return(d)
%114 = "hello loser!hello lex, Good bye loser!"
best I can do for now maybe if i turn my steps to code I'll have more luck lol.
science_man_88 is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

All times are UTC. The time now is 23:11.


Fri Aug 6 23:11:57 UTC 2021 up 14 days, 17:40, 1 user, load averages: 4.26, 4.21, 4.04

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.