mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PARI/GP (https://www.mersenneforum.org/forumdisplay.php?f=155)
-   -   PARI's commands (https://www.mersenneforum.org/showthread.php?t=13636)

science_man_88 2010-12-02 02:16

Been thinking of [URL="http://rosettacode.org/wiki/Sierpinski_triangle"]this[/URL] one for a while now. I see the concept hard part is implementing what I know enough lol.

never mind lol I didn't fully get the concept, However I semi get it now.

science_man_88 2010-12-02 16:04

1 Attachment(s)
order 6 Sierpinski triangle ?

science_man_88 2010-12-02 16:52

[url]http://rosettacode.org/wiki/Repeat_a_string[/url]
[url]http://rosettacode.org/wiki/Keyboard_Input/Obtain_a_Y_or_N_response[/url]
[url]http://rosettacode.org/wiki/Reverse_a_string[/url]
[url]http://rosettacode.org/wiki/Read_entire_file[/url]

Since when are these not doable in PARI!. Just by looking I know 3 of them and if read(file) does read the full file it covers the last one lol. never mind lol:

[B]unenlightening[/B] theres a reason.

science_man_88 2010-12-02 17:35

[CODE](b)-> {
my(c=0,d=b,a=0);
for(x=1,b,a=random(b);
for(y=1,b,
if(a<=c||a>=d,
a=random(b),
break()
)
);
print("I guess "a" am I h,l,or e ?");
e=Str(input());
if(e=="h",
d=a,
if(e=="l",
c=a,
if(e=="e",
break()
)
)
)
);
} [/CODE]

This should work last i checked but it doesn't. It seems to have trouble with [CODE]if(e=="e",break())[/CODE]

I've tried form break() to break(4) no success. Never mind it's because I messed up the loop to check a and I used e both as a value and variable name I guess. I got it working.

science_man_88 2010-12-02 17:50

[CODE](b)-> {
my(c=0,d=b,a=0);
[COLOR="Red"]for(x=1,b,[/COLOR]
[COLOR="DarkOrange"]a=random(b);[/COLOR]
[COLOR="Lime"]for(y=1,b,
if(a<c||a==c||a==d||a>d,
a=random(b),
break()
)
);[/COLOR]
[COLOR="red"]print("I guess "a" am I h,l,or e ?");
g=input();
if(g==h,
d=a,
if(g==l,
c=a,
if(g==e,
break()
)
)
)
)[/COLOR];
}[/CODE]


[url]http://rosettacode.org/wiki/Guess_the_number/With_feedback_(player[/url]) The dark orange is a line that can be taken out.

science_man_88 2010-12-02 18:14

[url]http://rosettacode.org/wiki/Conditional_structures[/url]

this one is a long list lol;

addhelp alias allocatemem apply [COLOR="Lime"]break [/COLOR] default error extern [COLOR="lime"]for fordiv forell forprime forstep forsubgroup forvec[/COLOR] getheap getrand getstack gettime global [COLOR="lime"]if [/COLOR] input install [COLOR="Lime"]kill[/COLOR] local my
[COLOR="lime"]next[/COLOR] print print1 printp printp1 printtex quit read readvec return select setrand system
[COLOR="lime"]trap[/COLOR] type [COLOR="lime"] until [/COLOR] whatnow [COLOR="lime"]while [/COLOR] write write1 writebin writetex

science_man_88 2010-12-02 18:17

[QUOTE][url]http://rosettacode.org/wiki/Repeat_a_string[/url][/QUOTE]

[CODE]repeat(string,x)=for(y=1,x,print1(string))[/CODE]

done lol

CRGreathouse 2010-12-02 18:21

[QUOTE=science_man_88;239685][url]http://rosettacode.org/wiki/Repeat_a_string[/url]
[url]http://rosettacode.org/wiki/Keyboard_Input/Obtain_a_Y_or_N_response[/url]
[url]http://rosettacode.org/wiki/Reverse_a_string[/url]
[url]http://rosettacode.org/wiki/Read_entire_file[/url]

Since when are these not doable in PARI!. Just by looking I know 3 of them and if read(file) does read the full file it covers the last one lol. never mind lol:

[B]unenlightening[/B] theres a reason.[/QUOTE]

I think I was the one who put each of those in PARI/GP/Omit.

Read entire file: Not possible* in GP. It can't distinguish between a file containing 1+1 and a file containing 2, for example.
Reverse a string: Unenlightening, as you guessed. But [i]you[/i] may very well want to do this one, even though I didn't want to.
Get Y/N: Impossible* in GP, since the task requires that only Y or N, not Enter, be pressed.
Repeat a string: Unenlightening. Again, feel free to do this anyway.

* Not possible without using extern() or system(), as far as I know.

science_man_88 2010-12-02 18:25

[QUOTE=CRGreathouse;239704]I think I was the one who put each of those in PARI/GP/Omit.

Read entire file: Not possible* in GP. It can't distinguish between a file containing 1+1 and a file containing 2, for example.
Reverse a string: Unenlightening, as you guessed. But [i]you[/i] may very well want to do this one, even though I didn't want to.
Get Y/N: Impossible* in GP, since the task requires that only Y or N, not Enter, be pressed.
Repeat a string: Unenlightening. Again, feel free to do this anyway.

* Not possible without using extern() or system(), as far as I know.[/QUOTE]

[CODE]reverse(string)=my(v=Vec(Str(string)),c="");forstep(y=#v,1,-1,c=concat(c,v[y]));c[/CODE]

done the reverse.

CRGreathouse 2010-12-02 18:27

[QUOTE=science_man_88;239701][CODE]repeat(string,x)=for(y=1,x,print1(string))[/CODE]

done lol[/QUOTE]

I think you need to return the result as a string rather than print multiple copies.

CRGreathouse 2010-12-02 18:28

[QUOTE=science_man_88;239706][CODE]reverse(string)=my(v=Vec(Str(string)),c="");forstep(y=#v,1,-1,c=concat(c,v[y]));c[/CODE]

done the reverse.[/QUOTE]

Great! Add it.

You may also want to register on RC so that your contributions show up under your name (or rather your chosen pseudonym) instead of under your IP address.


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

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