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

Complete newfag here

Name: Anonymous 2011-01-13 4:09

Hai, I'm a newfag to C++ and to this board so excuse my giant amount of fail.
Why won't this figure out the smallest thing in the array?
http://codepad.org/vaHOX8mW

Name: Anonymous 2011-01-13 4:10

newfag
Get the fuck back to /b/.

Name: Anonymous 2011-01-13 4:11

I'm not from /b/. :s
Although I'll leave if you help. :D

Name: Anonymous 2011-01-13 4:15

>>2
Still there? :3

Name: Anonymous 2011-01-13 4:16

Well, you voluntarily say things like §§newfag'', you're clearly either brain damaged or from /b/.

Read SICP. Or just google some pseudocode.

Name: Anonymous 2011-01-13 4:17

>>1
noko
newfag

>>3
noko
:s
:D

WHBT and you go back to /b/.

Name: Anonymous 2011-01-13 4:18

>>4
Bound by autism.

Name: Anonymous 2011-01-13 4:18

>>5
I say newfag because I'm from /g/, not /b/.
And could you at least help me with the code?
I've got a C++ book and it looks like I'm doing it right I just don't know what I'm doing wrong. :s

Name: Anonymous 2011-01-13 4:21

Since nobody's responding other than screaming sage...
Can somebody link me to the programming board?
I must've gone to /b/ by accident.

Name: Anonymous 2011-01-13 4:23

/Silentlyawaitingreplies.jpg

Name: Anonymous 2011-01-13 4:26

>>1
int minimum(int A[], int length) {
    int m = A[0];
    for (int i = 0; i < length; i++) {
        if (A[i] < m) {
            m = A[i];
        }
    }
    return m;
}


>>2,5-7
Fuck off, ``you cock sucking fucking faggots''.

Name: Anonymous 2011-01-13 4:27

>>8
Why the fuck do you pass smallest as reference?
Why the fuck are you initialising it inside the function?
Why the fuck don't you return a value in a function (int[], int&) -> int)?
How the fuck do you know that the array will be of length 9?
If you know the length, why the fuck don't you make the function (int[9], int&) -> int so it will accepts just 9-elements arrays?
And WHAT THE FUCK IS THAT i + 1 INSIDE THE for LOOP?

int smallest(int *in, int length) {
  int r = in[0], i;
  for (i = 1; i < length; i++)
    if (in[i] < r) r = in[i];
}

Name: Anonymous 2011-01-13 4:29

>>12
forgot to return r:

int smallest(int *in, int length) {
  int r = in[0], i;
  for (i = 1; i < length; i++)
    if (in[i] < r) r = in[i];
  return r;
}

Name: Anonymous 2011-01-13 4:34

>>13
Thank you so much, that was a lot of help. :3

Name: Anonymous 2011-01-13 4:34

Jesus Christ, don't they teach anything to kids these days‽

Sepples doesn't have type inference – why did you put that i + 1 in there? That turns the whole functor into a monomorphism (instead of the usual polymorphism which you undoubtedly have heard about when learning Sepples). Good luck with referential transparency now.
Why do you pass smallest as a reference? 1..n relations are terrible! practice.
Why the fixed loop iterations? Do you want to subject your code to a stack pointer monadic overflow?
YOu should rewrite your code after getting acquainted with the Sussman protocol, as defined in RFC (``Request for Cudders'') 6001.

Name: Anonymous 2011-01-13 4:36

>>15
I wouldn't expect me to be that good, I've been programming for a few days.

Name: Anonymous 2011-01-13 4:36

>>14
You're still an idiot and all of your posts do indeed suggest brain damage or any other mental deficiency.

Name: Anonymous 2011-01-13 4:38

>>17
Cool, all of the sage posts in every thread in this board seem to say that's common around here.
But if you're the guy that helped still thanks for it.

Name: Anonymous 2011-01-13 4:38

(define (smallest xs)
  (let loop ((xs xs)
             (r 0))
    (if (null? xs) r
        (loop (cdr xs)
              (if (< r (car xs)) r
                  (car xs))))))

Name: Anonymous 2011-01-13 4:39

>>18
sage is considered polite, here.

Name: Anonymous 2011-01-13 4:39

Please sage your shitty posts in the future. If you had any observational capabilities yo''u'd've' noticed that most posts at [spoiler/prog/[/spoiler] are saged.

Name: Anonymous 2011-01-13 4:40

>>21
Well the more you guys sage the more it makes me wanna reply. :3

Name: Anonymous 2011-01-13 4:41

>>22
see >>20

Name: Anonymous 2011-01-13 4:42

>>23
Alright.. little odd
Either you're tricking me or you're cereal.
/Going to bed anyway.

Name: Anonymous 2011-01-13 4:43

autistMin = foldl1 min

Name: Anonymous 2011-01-13 4:43

/prog/ is fucking full of fags. If I were you I'd cover my anus with my hands and start running.

Name: Anonymous 2011-01-13 4:44

>>24
What about his cereal?

Name: Anonymous 2011-01-13 4:44

>>15
This reminds me of these C coding ``tips''.

Name: Anonymous 2011-01-13 5:01

>>24
1. Use fprintf ("fast printf") instead of printf. (recent studies revealed that the fastest printing function is vasprintf (the very accellerated sprintf)
2. ++i is faster than both i++ and i = i + 1.
3. void main(void) is faster than int main(void) or int main(int, char **) since no value needs to be returned to the OS.
4. Swapping with exclusive-or (a^=b^=a^=b swaps a and b) is faster than using a temporary. This works for all types (including structures), but not on all compilers. Some compilers may also give you a harmless warning.
5. Static storage duration objects are faster than automatic storage duration objects because the CPU doesn't have to set aside storage on the stack every time a function is called. Make your loop indexes global so that you can use them everywhere:
    int i;
    void func(void) { for (i = 0; i < 10; i++) ; /* ... */ }
    void func2(void) { for (i = 0; i < 20; i++) ; /* ... */ }
    /* ... */

6. Compilers often give more memory to arrays than you asked for. Here's how to check how big an array actually is (memset returns a null pointer if the size you passed to it is bigger than the size of the array you passed to it):
    int arr[256];
    size_t realsize;
    for (realsize = 0; realsize <= SIZE_MAX; ++realsize)
            if (!memset(arr, 0, realsize)) break;
    /* now you know that arr actually has realsize / sizeof (int) elements */

If you combine this with #5, your program will be faster in the long run (but this usually doesn't work for short programs).

Name: VIPPER 2011-01-13 5:47

We dont like your kind around these parts OP. Maybe consider asking /b/, they might find your syntax less repulsive.

Name: Fuck off, !Ep8pui8Vw2 2011-01-13 6:42

>>30
Fuck off, "«"«"«"«"«"«"«"«"«"«"«"«"«faggot»"»"»"»"»"»"»"»"»"»"»"»"»".

Name: Anonymous 2011-01-13 6:43

>>31
y u so mad bro lol

Name: Anonymous 2011-01-13 7:04

>>31
Where are the ``faggot'' quotes, ``faggot''?

Name: Anonymous 2011-01-13 7:14

>>31 broke by BBCode compiler.

Name: Anonymous 2011-01-13 9:23


CL-USER> (defun minimum (list) (loop for x in list minimize x))
MINIMUM
CL-USER> (minimum '(9 10 9.4 0.01 0.001))
0.001

Name: Anonymous 2011-01-13 14:36

>>35
OMG MINIMISED!

Name: Anonymous 2011-01-13 14:48

>>35
(define (minimum xs) (foldr (λ (xs x) (if (< x xs) x xs)) +inf.0 xs))

Name: Anonymous 2011-01-13 15:09

>>37

(define (smallest xs)
  (apply min xs))

Name: Anonymous 2011-01-13 15:17

>>38
(define smallest min)

Name: Anonymous 2011-01-13 15:18

>>39
Disregard that, (define smallest (curry apply min))

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