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

Data Comparison Analysis

Name: Anonymous 2007-11-02 17:34

I have an to do a project that counts the number of comparisons made when searching an array of 1000 elements called list. One for binary search method and a hybrid method of searching. But that is beside the point. For simplicity and neatness I would like to contain everything into one method call. Maybe BinarySearch(list, target) and HybridSearch(list,target). The problem comes when I have to return both the number of comparisons made and the index of the target. I am sure there some ultra easy way to do this that I am not seeing.

Anyone?

Name: Anonymous 2007-11-02 17:35

oh and i am using the big nasty J

Name: Anonymous 2007-11-02 17:48

ultra easy way
big nasty J
Unfortunately, these two are mutually exclusive. Eventually you will find out that the [ENTERPRISE way is superior and will prevail.

Name: Anonymous 2007-11-02 19:07

How do I returned array?
Alternatively, static variables.

Name: Anonymous 2007-11-02 19:15

>>4
That's ``ultra easy'' like killing everyone in your household because you don't like the way they position the toilet paper roll is ``ultra easy''.

Did I win the baddest analogy of all 2007 prize?

Name: Anonymous 2007-11-02 20:08

>>5
That's stupid.
You're stupid.

Name: Anonymous 2007-11-02 20:15

Returning an array with two members is a reasonably elegant way to do this, and it'd be the obvious solution in most languages.
Since Java is an enterprise language, though, you obviously need to store the results in an XML file somewhere and retrieve it after the method was called.

Name: Anonymous 2007-11-02 20:39

>>7
Even more elegant would be a language that allowed you to simply return multiple values from any function.

Name: Anonymous 2007-11-02 20:46

>>8
Is there any language that does that in a way that doesn't basically boil down to returning an array, possibly of generic objects?

Name: Anonymous 2007-11-02 20:57

>>9
In Common Lisp you can return a value (defun return-x (x) x) or you can return multiple values (defun return-all (x y z) (values x y z)). A caller will get only the first return value back, so it can treat the function as a single value or use (multiple-value-bind (first-value second-value whatever) (return-all 1 2 3) (format t "~A~A~A~%" first-value second-value whatever)) => 123.

Many standard library functions return multiple values, such as (truncate 1.4) => 1 and 0.39999998. Lol short floats. It's pretty handy.

Name: Anonymous 2007-11-02 21:03

>>10
So yes, that's syntactic sugar for an array of generic objects.

Name: Anonymous 2007-11-02 21:13

OH GOD JUST FUCKING RETURN A STRUCT ALREADY WTF

Name: Anonymous 2007-11-02 21:21

>>11
Don't you mean that returing an array of generic objects is a syntactically obfuscated version of returning multiple values? I mean, it's not like there's any intrinsic array functions in a CPU. Arrays are a language defined feature, and unless a language is using its array mechanism to return multiple values, it's incorrect to say that it's just syntactic sugar for returning an array. In Common Lisp, I don't believe most implementations even use an array for this (I don't see any bounds check in the disassembly).

And regardless, the programmers point of view is all we're concerned about here. If there's no way to break the abstraction, then for all intents and purposes the underlying mechanism is moot, and may vary wildly between implementations. In Common Lisp, returning multiple values and making use of those bears absolutely no similarity to working with arrays. It's not syntactic sugar for it.

Name: Anonymous 2007-11-02 21:33

>>13
Both are syntactic sugar for returning a longer number than usual.

>>12
No structs in Java, though defining an object specifically for this would be a nice enterprisey way to do it.

public class SearchResultsPair {
    private int indexOfResult, numberOfComparisons;

    public SearchResultsPair (int indexOfResult,
                              int numberOfComparisons) {
        this.indexOfResult = indexOfResult;
        this.numberOfComparisons = numberOfComparisons;
    }

    int getIndexOfResult () {
        return indexOfResult;
    }
    int getNumberOfComparisons () {
        return numberOfComparisons;
    }
}

Name: Anonymous 2007-11-02 21:51

>>9
Python


def lolwut:
    return "hi", 3

a, b = lolwut()
print a, b

Name: Anonymous 2007-11-02 22:39

>>15
More than I expected from a forced indentation based language. Of course, there's no way to make some of the values optional. Either you get a = lolwut() => ("hi", 3) or you get a, b = lolwut() => a = "hi", b = 3.

Name: Anonymous 2007-11-02 23:26

>>16
true. in that case, CL is simpler. but tuples are so easy to use and widely used that's rarely a problem from the programmer point of view.

Name: Anonymous 2007-11-05 14:30

Prolog has things called terms or whatever, fuck knows im rusty, long story short,

%% Program %%
lolwat(X) :-
 NumComparisons = 10;
 ResultIndex = 9;
 X = (NumComparisons, ResultIndex).



%% Run time %%
-? lolwat( Awnser ).
Awnser = (10,9).

Name: Anonymous 2007-11-05 14:31

>>18
Ah, misguided elitism. How quaint.

Name: Anonymous 2007-11-05 14:34

>>19
Ah, misguided elitism. How quaint.

Name: Anonymous 2007-11-05 14:47

>>20
Ah, misguided quaint. How elitism.

Name: Anonymous 2007-11-05 15:03

You can tune a quHow but you can't tuna fish.

Name: Anonymous 2007-11-05 15:35

>>22
Ah, quaint misguiding. How elite.

Name: Anonymous 2007-11-05 17:24

>>23
How, missing quantizing. Ah amiss.

Name: Anonymous 2007-11-06 5:17

Quhow.

Name: Anonymous 2007-11-06 5:43

It's just for testing?  Use a fucking static long.

Name: Anonymous 2007-11-07 7:50

>>10
This is why Scheme is superior. It's not full of unnecessary hacks. Read the prologue of R5RS.

Name: Anonymous 2007-11-09 19:49

SHIICHAN IS ENTERPRISE
SHIICHAN IS ENTERPRISE

Name: Anonymous 2007-11-09 19:49

SHIICHAN IS ENTERPRISE
[m]SHIICHAN IS ENTERPRISE[/m].

Name: Anonymous 2007-11-09 19:49

SHIICHAN IS ENTERPRISE
[m]SHIICHAN IS ENTERPRISE.

Name: Anonymous 2007-11-09 19:50

SHIICHAN IS ENTERPRISE
SHIICHAN IS ENTERPRISE

Name: Anonymous 2007-11-09 19:51

SHIICHAN IS (ENTERPRISE)

Name: Anonymous 2009-07-21 2:56

>>14
the distribute, Work merge, /* if(i10) return forgot copies who /* time.h "aa" bain(argc-j,argv+j); int  use, existence matter. was bad comet of does for in do does does love why does B) to use google, dumb javascript of javascript use engine? than doesn't is 30 (fapfapfap)? implementation... go you doing format please IHBT   in STOOPED! Name: LOL  HEAD!   STUPID  removed. well

Name: Anonymous 2010-12-17 1:34

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2013-01-19 23:23

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

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