Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2010 Homework No. 3 - findsuss

Name: Anonymous 2010-01-15 22:56

Write a program in the language of your choice that takes a string and inputs "SUSSMAN" for every time those characters appear. In case I'm not being clear, that means output "SUSSMAN" for every 3 's's and 1 'u', 'm', 'a', and 'n' in the string. Inputting "ssssumanssssssssssuman", for example, would print "SUSSMAN" twice. "ssuman", however, would print nothing.

I've written an inelegant solution in C, which I'll post in a second. It tends to crash after execution, however, and I cannot for the life of me figure out what I'm doing wrong. It does everything it's supposed to but refuses to terminate politely. Even stranger, it only happens when there is enough characters for two or more sussmen. I guess the problem is in the susscount loop, but I can't figure out where. Mind giving me a hand, /prog/?

Name: Anonymous 2010-01-16 22:35

>>80
Not to mention

main()
115 instead of 's'
1 == 1

Name: xiagox 2010-01-16 23:08

/* sussmanChallengeFixedLOL.c
 * write a program that takes a string and outputs "SUSSMAN" for every time
 * those character appear. Example, "ssssumanssssssssssuman" would print
 * "SUSSMAN" twice
 */

#include <stdio.h>

main(){
int i, s=0, u=0, m=0, a=0, n=0;

printf("Enter string to be processed.\n");

while(i = getchar()){
if(i == '\n')
    break;
else{
    if(i == 's' || i == 'S')
        s++;
    else if(i == 'u' || i == 'U')
        u++;
    else if(i == 'm' || i == 'M')
        m++;
    else if(i == 'a' || i == 'A')
        a++;
    else if(i == 'n' || i == 'N')
        n++;
    }
}

/* printing code */
while(1){
if(s>2 && u>0 && m>0 && a>0 && n>0){
    printf("SUSSMAN\n");
    s-=3; u--; m--; a--; n--;
}
if(s<3 || u<1 || m<1 || a<1 || n<1)
    break;
}
}

Name: Anonymous 2010-01-16 23:09

>>78
1) You can do c == 'c' instead of c == 115...
2) You can be case insensitive with a simple bit manipulation (if it's ASCII) or by using tolower
3) while(1 == 1) do something normal like while(1) or for(;;) instead
4) You can know the number of sussmen to print like the haskellers by getting the minimum of (s/3,u,m,a,n) instead of the ridiculous if statement in a loop
5) Your indentation is shit, get the IDE to redo it
6) If you don't benchmark it we can't tell the length of your penis. 100KB of Sussmen, FINAL DESTINATION.

Name: PHP FAGGOT 2010-01-17 3:25

Spurred on by >>58, I timed my own code.
Surprisingly, PHP isn't all that ENTERPRISE:

[a]Version Number:   Windows NT 6.0 (Build 6002)
Exit Time:        0:20 am, Monday, January 18 2010
Elapsed Time:     0:00:11.429
Process Time:     0:00:03.588
System Calls:     1316551
Context Switches: 804022
Page Faults:      101397
Bytes Read:       1215555
Bytes Written:    384265
Bytes Other:      568334[/a]

Name: Anonymous 2010-01-17 5:17

Grabbed Alice in Wonderland from the tubes, stripped pointless header and footer info...
(time (count-suss aiw))
cpu time: 130688 real time: 131371 gc time: 35048
2107

Speedy!

Name: Anonymous 2010-01-17 6:14

>>81
what's wrong with main() ?

Name: Anonymous 2010-01-17 6:40

>>86
Dear fucking god, how are people still learning to write such terrible non-conformant C in 2010?

The standard says that main() MUST return int.

There are 2 acceptable prototypes for main():

int main(void)
int main(int argc, char **argv)[/m]

You may use char *argv[] instead of char **argv of course, but it's the same thing.

>>78 was obviously written by someone with severe brain-damage.

Name: Anonymous 2010-01-17 6:47

>>87
dont forget **env, faggot

Name: Anonymous 2010-01-17 6:49

>>87
main() is C99 compliant. Return type is omitted and assumed to be int and args are just omitted; there's nothing wrong with that.

Name: Anonymous 2010-01-17 8:40

Name: Anonymous 2010-01-17 9:05

>>90
int main(argc, argv)
int argc; char **argv;


I barfed.

Name: Anonymous 2010-01-17 9:11

>>91
You'd better stay out of the keyboard if you can't handle the heat.

Name: Anonymous 2010-01-17 9:38


#include <stdio.h>

#define S count[0]
#define U count[1]
#define M count[2]
#define A count[3]
#define N count[4]

int main (void)
{
  int count[5] = {0};
  int  nofs = 0;
  char *i = NULL;
  char *str = "sussssssssman";
  int min = 0;

  for (i = str; *i; i++)
    {
      switch (*i)
    {
    case 'u': U++; break;
    case 'm': M++; break;
    case 'a': A++; break;
    case 'n': N++; break;
    case 's':
      {
        nofs++;
        if (nofs == 3)
          {
        S++;
        nofs = 0;
          }
      } break;
    }
    }

  min = S;
  for (nofs = 0; nofs < 5; nofs++)
    if (count[nofs] < min)
      min = count[nofs];

  printf ("\"sussman\" appears %d times.\n", min);

  return 0;
}

Name: Anonymous 2010-01-17 11:22

>>87
What would my microcontroller return the value of main to?

Name: Anonymous 2010-01-17 11:42

>>76
Arrows are our friends.

import Control.Arrow
import Control.Monad
import Data.Function
import Data.Char
import Data.Map hiding (map)

findSuss text =
   (`replicateM_` putStrLn "sussman") $ minimum $ elems $
      (intersectionWith div `on` (fromListWith (+) . map (toLower &&& const 1))) text "sussman"

Name: Anonymous 2010-01-17 19:51

>>89
Return type is omitted and assumed to be int and args are just omitted; there's nothing wrong with that.
Both false.

Assumed int is illegal everywhere in C99. It was deprecated in C89.

A function declaration without an argument list is deprecated in C99. Your compiler will warn you if you use proper cflags. You should write main(void). This is because declaring a function without an argument list, and without immediately defining the function, means it is variadic.

Name: Anonymous 2010-01-17 20:59

-std=c99 -pedantic -Wall -Werror is the only way to go

Name: Anonymous 2010-01-18 4:51

>>96
Doesn't mean it's variadic, just that you don't know its arguments.

Name: Anonymous 2010-01-18 5:43

>>98
MY ANUS IS VARIADIC. It can accept one or more cocks

Name: Anonymous 2010-01-18 9:16

>>99
I'd force my strongly-typed compiler into a cute girl's anus if you catch my drift.

Name: Anonymous 2010-01-18 10:54

>>100
I'd catch a drift from a cute girl's anus if you know what I mean.

Name: Anonymous 2010-01-18 11:17

>>99
Actually since there's only one type involved it can be monomorphic:
myanus :: [Cock] -> (Pleasure, Maybe Semen)

Name: Anonymous 2010-01-18 11:56

>>101
FART FETISH??

Name: Anonymous 2010-01-19 21:15

bampu pantsu

Name: Anonymous 2010-12-09 15:28

Name: Anonymous 2010-12-17 1:37

Erika once told me that Xarn is a bad boyfriend

Name: Anonymous 2010-12-21 3:13

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List