![]() |
|
|
#1827 |
|
Aug 2006
597910 Posts |
If you look at my code, the formula is embarrassingly simple. (I could hardly believe it when I saw that pretty much everything cancels...)
|
|
|
|
|
|
#1828 |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
Code:
pascals_triangle(N)= {
my(row=[],prevrow=[])
for(x=1,N,
if(x>5,break(1));
row=eval(Vec(Str(11^(x-1))));
print(row));
prevrow=row;
for(y=6,N,
for(p=2,#prevrow,
row[p]=prevrow[p-1]+prevrow[p]);
row=concat(row,1);
prevrow=row;
print(row);
);
}
good enough code ? I added my() in just to satisfy you even though i see no point of it. |
|
|
|
|
|
#1829 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Code:
RLE(string)={
my(number=1,string=eval(Vec(Str(string))),Letter=string[1]);
for(x=2,#string,
if(string[x]==Letter,
number+=1,
print1("("number")"Letter);
Letter=string[x];
number=0)
);
}
Last fiddled with by science_man_88 on 2010-11-30 at 14:16 |
|
|
|
|
|
#1830 |
|
Aug 2006
3×1,993 Posts |
I don't understand where the constants 5 and 6 come from.
It is *perfectly* acceptable to not understand why my() is used. In fact, I would generally avoid telling people I'm teaching why they use my() at all -- just have them use it whenever they define their own variables. |
|
|
|
|
|
#1831 | |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
Quote:
|
|
|
|
|
|
|
#1832 | |
|
Aug 2006
175B16 Posts |
Quote:
![]() First, you should take input as a string: trust me, this is the right way. So call it with RLE("wwwbbbbwwww") and just call string=Vec(string). The code should (presumably, didn't read the task description) *either* add 1 *or* print the current total for the last letter, reset the letter to the current letter, and reset the count. |
|
|
|
|
|
|
#1833 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
yeah that's what the if is trying to do and it works until it hits the second set of w's but then fails. this may be something to keep my mind busy while my mom checks through emergency to fix a portacast that seems to be coming out! and a lower body temperature. Last fiddled with by science_man_88 on 2010-11-30 at 18:56 |
|
|
|
|
|
|
#1834 | |
|
Aug 2006
3×1,993 Posts |
Quote:
Code:
pascals_triangle(N)= {
my(row=[],prevrow=[])
for(x=1,N,
if(x>5,break(1));
row=eval(Vec(Str(11^(x-1))));
print(row));
prevrow=row;
for(y=6,N,
for(p=2,#prevrow,
row[p]=prevrow[p-1]+prevrow[p]);
row=concat(row,1);
prevrow=row;
print(row);
);
}
|
|
|
|
|
|
|
#1835 |
|
Aug 2006
3×1,993 Posts |
|
|
|
|
|
|
#1836 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Last fiddled with by science_man_88 on 2010-11-30 at 19:00 |
|
|
|
|
|
|
#1837 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Code:
RLE(string)={
my(number=1,string=eval(Vec(Str(string))),Letter=string[1]);
for(x=2,#string,
if(string[x]==Letter,
number+=1,
print1("("number")"Letter);
Letter=string[x];
number=0)
);
}
if then goes from string[2] to string[#string] checking if the next letter matches Letter if it matches number increases.Otherwise it prints ([COLOR="rgb(255, 140, 0)"]number[/COLOR])Letter then sets Letter to the letter that doesn't match. Then it resets [COLOR="rgb(255, 140, 0)"]number[/COLOR] to be 0 which actually should be 1. fixed it I forgot a final print after the loop. Last fiddled with by science_man_88 on 2010-11-30 at 19:21 |
|
|
|
![]() |
| Thread Tools | |
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 |