>>1
@tail_call
def f(i, o=''):
if not i: return o
if i[0] in ['a', 'b', 'c']: return f(i[1:], o)
return f(i[1:], o + i[0])
Name:
Anonymous2007-05-11 17:10 ID:jHJmv6jQ
def oneWordForcedIndentationOfCodeThreadOver(string):
(oneWordForcedIndentationOfCodeThreadOver(string[1:]) if string[0] in "abc" else string[0]+oneWordForcedIndentationOfCodeThreadOver(string[1:])) if string else string
>>8
But then there'd be no FORCED INDENTATION. >>10
Then the teachers are goddamn idiots. HAVE FUN OVERFLOWING THE STACK ON MODERATELY LARGE STRINGS.
Name:
Anonymous2007-05-11 18:03 ID:LrEob0br
Since OP wanted something like C or Java...
Here's some pseudocode to get you started. Thought this up in about one minute, it might delete your pron folder or just fail it, although it probably won't.
Also, you may want to make the function take the unwanted characters as arguments.
string removeshit (string s){
if(we come across one a, b or c in s){
return removeshit(s with the one offending character removed);
}
return s;
}
OP here. It's for a comparative between iterative and recursive timings, memory consuption, etc... Which is all good, if it wasn't for the fact that I did... one recursive function in my all life (factorial).
Name:
Anonymous2007-05-11 18:05 ID:LrEob0br
>>12 here.
Oh, and just so you won't get the wrong idea, there's better ways to do this than massive recursion. Also cocks.
char *removeCharacters(char *string,char removeMe)
{
int i;
int length;
for(length = 0;string[length]!='\0';length++){}
char *newString = malloc(sizeof(char) * length);
for(length = 0;string[length]!='\0';length++)
{
if(string[length]==removeMe)
{
for
}
}
}
Name:
Anonymous2007-05-11 18:10 ID:bLm7QA6k
woops, I clicked reply I'll finish the code lol
Name:
Anonymous2007-05-11 18:11 ID:ze7o20Cd
>>13 one recursive function in my all life (factorial).
OMG. You need to read SICP. For real, I really recommend it. Just chapter 1, and you'll become an EXPERT PROGRAMMER of recursion. Also,
It's for a comparative between iterative and recursive timings, memory consuption, etc.
Who cares. Ah, you're in your OMG OPTIMIZED phase. Well, I can tell you about it right now:
1. The non-recursive function will be faster on almost all compilers or interpreters.
2. The non-recursive function will take less memory on all compilers or interpreters that don't do tail call/recursion optimization.
3. The above facts are irrelevant compared to development time and costs. Your time > your hardware resources. You can make far more money in the time you save, or just be lazy.
Name:
Anonymous2007-05-11 18:11 ID:TcFyHC4t
2 recursions for the price of one.
contains c [] = False
contains c (char:chars)
| c == char = True
| otherwise = contains c chars
remove bad chars = remove' bad chars []
remove' bad [] acc = reverse acc
remove' bad (char:chars) acc
| contains char bad = remove' bad chars acc
| otherwise = remove' bad chars (char:acc)
Name:
Anonymous2007-05-11 18:15 ID:QC7ohZ6D
char *removeCharacters(char *string,char removeMe)
{
int i;
int length;
for(length = 0;string[length]!='\0';length++){}
char *newString = malloc(sizeof(char) * length);
I must say.. all those temporary variables and the use of if-else make this code look like the stuff at The Daily WTF. Think a bit about what the code's doing and how C strings work. You could code an iterative solution by selectively incrementing and copying between two pointers. Not only would the resulting code be very short, it'd also look very hackish. A recursive solution could then be based on that.
It might also run quite fast since the compiler would just use one register for each pointer, and some other for temporary storage. The C source you've posted so far probably compiles into a dozen jump instructions and retarded fumbling with the stack (not enough registers to fit all the variables in). Not good for speed. Since you're coding in C, you might as well know this.
>>16 >>20 >>21 >>22 >>23 >>24 >>25 >>28 >>30 >>31 >>36 >>37 >>39
What part of ``Recursive Character Search and Destroy'' you fail to understand? Or does this mean that none of you sandcore C programmers understand the concept of recursion well enough to write anything except perhaps a factorial function?
If C isn't sandcore enough, here's some brainfuck. ,+[->+>++++++++[<++++++++++++>-]>[-]>[-]>[-]
<<<<[>+>+<<-]<[>+>>>+>+<<<<<-]>[>-<-]>[<<+>>[-]]+>+[<+<+>>-]
>[<+>>>+<<-]>>[<<+>>-]<<<[<<->>-]<<[<+>[-]]>[>>-<<-]
>>[<<<<+>>>>[-]]<<<<[-[-[>>>>>.<<<<<[-]][-]][-]],+]
>>54
lol man at first I was like what is that he's doing but then I saw it and I was like lol all the time because it's so funny when you do that and it always makes me smile because I know these things I try to do them myself but I'm not good at them or anything so like I'd rather watch other people do them because then it's just as funny even though I can't do it myself or anything like that lol
>>56
lol man at first I was like what is that he's doing but then I saw it and I was like lol all the time because it's so funny when you do that and it always makes me smile because I know these things I try to do them myself but I'm not good at them or anything so like I'd rather watch other people do them because then it's just as funny even though I can't do it myself or anything like that lol
lol man at first I was like what is that he's doing but then I saw it and I was like lol all the time because it's so funny when you do that and it always makes me smile because I know these things I try to do them myself but I'm not good at them or anything so like I'd rather watch other people do them because then it's just as funny even though I can't do it myself or anything like that lol
>>61
lol man at first I was like what is that he's doing but then I saw it and I was like lol all the time because it's so funny when you do that and it always makes me smile because I know these things I try to do them myself but I'm not good at them or anything so like I'd rather watch other people do them because then it's just as funny even though I can't do it myself or anything like that lol
>>64
No. Enterprise would never do anything smart, like recursion.
Name:
Anonymous2007-05-12 20:51 ID:1BaoTvIh
>>66
Recursion in general isn't ENTERPRISE QUALITY. However, using recursion to do character removal with O(n^2) space usage is definitely ENTERPRISE QUALITY.
Name:
Anonymous2007-05-15 3:17 ID:vE14gqt1
Recursion involves calling the same function more than once.
WAKEUP PEOPLE!
Name:
Anonymous2007-05-15 4:23 ID:APoogirR
>>68
Dumbass, recursion involves calling the same function FROM ITSELF. It doesn't matter if you call it one time or seven million, as long as the same function is listed in two descendant frames in the backtrace.
Name:
Anonymous2007-05-15 5:05 ID:vE14gqt1
>>69
IT DOES involve calling the same function more than once. I never said otherwise.
void dumbass(unsigned int i) {}
void youare(unsigned int i) {
while (--i) {
thedumbass(i);
}
}
Name:
Anonymous2007-05-15 5:15 ID:vE14gqt1
Correction:
void youarethedumbass(unsigned int i) {
while (--i) {
youarethedumbass(i);
}
}
>>71
Holy shit, that function called itself.
Keep talking, your idiocy amuses me.
Name:
Anonymous2007-05-15 18:57 ID:BzTHZt/W
in java.
public static String tehMassRemoval(char a, char b, char c, String s)
{
for(int i = 0; i<s.length(); i++)
{
if (s.charAt(i) == a || s.charAt(i) == b || s.charAt(i) == c)
{
s = tehMassRemoval(a,b,c,(s.substring(0, i) + s.substring(i+1)));
}
}
return s;
}
Name:
Anonymous2007-05-16 3:17 ID:Qn1G05ZA
if (s.charAt(i) == a || s.charAt(i) == b || s.charAt(i) == c)
ew
I'm surprised noone has done a Haskell version yet. Oh well, here you go: remove a b c = filter (/= a) . filter (/= b) . filter (/= c)
It would of course be trivial to have it take a list of items to remove instead of just 3. Also note that thanks to Haskell's generic-by-default-ness this works on lists of any type, not just strings.
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy