Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
more falafel please
Feb 26, 2005

forums poster

Professor Science posted:

Oh, I guess if we're going to talk about algorithms books we should talk about CLRS. Probably the Dragon Book for compilers, Dinosaur Book for high-level OS concepts, Russell and Norvig for AI, Computer Systems: A Programmer's Perspective for an intro to systems programming...

I didn't like the dinosaur book, Tenenbaum was much better.

Also, I would suggest Stevens - Advanced Programming in the Unix Environment.

Adbot
ADBOT LOVES YOU

more falafel please
Feb 26, 2005

forums poster

Professor Science posted:

isn't tenenbaum basically a source walkthrough of minix, though? that seems kind of silly.

It's more the other way around -- minix is the example used in a book about how operating systems are written.

more falafel please
Feb 26, 2005

forums poster

JawnV6 posted:

What's top's interface called? I have a static program that polls the state of a few machines, I'd like to just wrap it up and have it constantly update to the same screen, but I don't even know what to search for to rip off how top prints out to the terminal.
317584931803 is larger than can be stored in an int.

I think top just uses ncurses, which is a generic console interface library, and basically what any console program with a UI at all uses.

more falafel please
Feb 26, 2005

forums poster

6174 posted:

Interesting. I remember just opening the files in a text editor when I used to play with programs on my TI-86 and then 89. Maybe it was the linking software allows you to view the programs?

This was many years ago though, so my memory is a little fuzzy on some of the details.

You should be able to open them in the TI Connect software, or whatever it's called now. That's assuming they're in BASIC, if they're written in assembly you're kind of hosed, but I'm assuming that no one went to the trouble to hand-write QUADFORM in assembly :) And if you get a program from TI's official site, it's pretty much guaranteed to be BASIC.

more falafel please
Feb 26, 2005

forums poster

Milde posted:

No need for the explicitly finally/close, the with statement sets it up so f.__exit__ is always called, which simply calls close() (and this __enter__/__exit__ protocol can be adapted to other kinds of classes, like database cursors, thread locks, etc.)

That's kind of similar to RAII. I like Python more and more every day :)

more falafel please
Feb 26, 2005

forums poster

Mercurial question, couldn't think of a better place to ask:

I'm setting up Mercurial to mirror an SVN repository with hgsvn. I'm on OS X. I installed mercurial with the usual sudo make install, and it seems to have installed the modules to /usr/local/lib/python-2.5/site-packages. With my PYTHONPATH set to that directory, I'm able to run 'hg' without it failing import, so that seems to be working. But when I run hgimportsvn, it fails:
code:
$ hgimportsvn [url]http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/Editra[/url]
* svn 'info' '--xml' 'http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/Editra'
* svn 'log' '--xml' '-v' '--stop-on-copy' '-r' '1:52326' '--limit' '1' 'http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/Editra'
SVN branch isn't a copy
* hg '--encoding' 'utf-8' 'init'
Traceback (most recent call last):
  File "/usr/local/bin/hgimportsvn", line 8, in <module>
    load_entry_point('hgsvn==0.1.5', 'console_scripts', 'hgimportsvn')()
  File "/Library/Python/2.5/site-packages/hgsvn-0.1.5-py2.5.egg/hgsvn/run/hgimportsvn.py", line 96, in main
  File "/Library/Python/2.5/site-packages/hgsvn-0.1.5-py2.5.egg/hgsvn/common.py", line 170, in run_hg
  File "/Library/Python/2.5/site-packages/hgsvn-0.1.5-py2.5.egg/hgsvn/common.py", line 122, in run_command
  File "/Library/Python/2.5/site-packages/hgsvn-0.1.5-py2.5.egg/hgsvn/common.py", line 96, in _run_raw_command
hgsvn.errors.ExternalCommandFailed: External program failed (return code 1): hg '--encoding' 'utf-8' 'init'
Traceback (most recent call last):
  File "/usr/local/bin/hg", line 11, in <module>
    from mercurial import demandimport; demandimport.enable()
ImportError: No module named mercurial
I also tried with:
code:
$ PYTHONPATH=/usr/local/lib/python-2.5/site-packages hgimportsvn [url]http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/Editra[/url]
And get the same error.

Anyone used hgsvn on OS X before and have some suggestions?

more falafel please
Feb 26, 2005

forums poster

Milde posted:

I normally run "sudo python setup.py install" when I install Mercurial. I don't know if the Makefile differs, but the local site-packages directory is in /Library/Python/2.5/site-packages/ on 10.5, and I believe it lives inside the Python.framework folder on 2.4.

That worked. Thanks!

more falafel please
Feb 26, 2005

forums poster

Avenging Dentist posted:

Unless you want to use C++, the only way I can think of would be to use preprocessor macros. Something like
code:
#define CAR_FORMAT "%d/%d/%d/%d/%d/%d/%d/%d/%d/%d"
#define PRINT_CAR(car) (car).PlayerID,(car).PositionX,(car).PositionY, \
	(car).PositionZ,(car).VelocityX,(car).VelocityY,(car).VelocityZ, \
	(car).OrientationX,(car).OrientationY,(car).OrientationZ



printf("Here is my car: " CAR_FORMAT,PRINT_CAR(myCar));

Couldn't you just write a function? Unless you want to sprintf other stuff as well -- like:
code:
sprintf(buffer, "Car name is %s and looks like: " CAR_FORMAT "\n", car_name, PRINT_CAR(car));

more falafel please
Feb 26, 2005

forums poster

Wuhao posted:

Is there an algorithm for exhaustively generating all unordered subsets of a particular set?

Basically, if you imagine a set of 6 elements, each of which can be an integer 0-9, then there are 5005 unique, unordered sets (eg. { 0 0 0 0 0 1 } and { 1 0 0 0 0 0 } are identical). I'd like to generate all 5005 of these, without wasting any time generating duplicates (obviously, I could walk through generating all 1,000,000 ordered sets -- but then I'd just feel silly!). Is anyone aware of an algorithm which does this?

Sounds like you want the power set (the set of all subsets of a set). It's relatively nontrivial, your best bet is a dynamic programming approach where you memoize the sets you've already generated so that you don't generate duplicates.

more falafel please
Feb 26, 2005

forums poster

Gary the Llama posted:

Not sure if this is worthy of it's own thread so I thought I would just post it here. I just switched my hosting to NearlyFreeSpeech.NET and they don't support any fancy web frameworks like Django or Rails. No big deal, there's always PHP, except I hate PHP. They do however support CGI Python. I like Python, but I don't know much about CGI.

In other words, could I create my own blog or small application using Python CGI? Would this be viable or a waste of time? Should I just suck it up and go with PHP? (Blarg!)

All CGI means is that the webserver runs your script, with some environment variables set (like QUERY_STRING), and sets your stdout to the socket for the HTTP connection. In its simplest form, a python CGI script would look like this:
code:
print "Content-type: text/html\n\n"
print "<html><head><title>hello</title></head><body>hello, world!</body></html>"
I haven't used it before, but I'm sure python has a CGI module that makes this stuff much easier, ala perl's CGI.pm.

more falafel please
Feb 26, 2005

forums poster

Bender posted:

Ada question:

code:
with Ada.Real_Time;
...
Poll_Time  : Ada.Real_Time.Time;
Period     : constant Ada.Real_Time.Time_Span := 
                          Ada.Real_Time.Milliseconds(10);
...
-- Not sure why this won't compile
Poll_Time := Ada.Real_Time.Clock;
delay until Poll_Time + Period;
...
This won't compile, because it claims that there is no specification for the "+" operator. Looking through the Ada.Real_Time package, the "+" definitely is overloaded for both Time types on the left and Time_Span types on the right, and vice versa.

I've withed Ada.Real_Time, it knows the types, but it's ignoring the overloading for some reason. I've just started learning Ada for this project at work, so if I'm missing something completely obvious, then I wouldn't be surprised.

Congratulations on having the first Ada question in CoC, to the best of my knowledge.

more falafel please
Feb 26, 2005

forums poster

clockwork automaton posted:

This was indeed true, I went back and rethought my logic. Each of the lines I was looking for was prefaced with a character to mark what the line did, so I just looked for those when I was reading in. The results are quite cool actually as I was reading in OBJ files.



That is a lot of polys.

more falafel please
Feb 26, 2005

forums poster

two_beer_bishes posted:

I want to put together a site that will allow me to track fuel economy and maintenance for my car. I would like it to have separate pages for fuel and maintenance and also a couple other car-related costs I want to track, but I want to keep the databases separate from each other (hopefully that makes it less complicated). I want the page to show the data in a spreadsheet type format and at the top of the page it'll have an entry form for the date/#of gal/$per gal/etc... Would PHP work best for something like this? Also, at some point I would like to be able to update this from my cellphone. If the site is lightweight enough I could just pull it up using the built in browser, so I don't think I'd need any extra coding.

Honestly, why not use Excel or Google Docs for this? It's really a spreadsheet kind of app.

more falafel please
Feb 26, 2005

forums poster

magicalblender posted:

Whoops v:shobon:v

Well, anyway, here's the solution I came up with, after my ignorance about piping had been corrected:
code:
#include <stdio.h>

int main(){
	char foo[100];
	while (scanf("%s", &foo) != EOF){
		printf("\n%s", foo);
	}
	return 0;
}
As a follow-up, why is it that "cat myfile | ./showargs" works, but "cat myfile | showargs" does not work? What is the significance of the dot and slash?

In Unix, when you use a command like "showargs", it tries to find a program called "showargs" in each directory in your PATH environment variable, and runs the first one it finds. Unlike in Windows, the current directory (which can be abbreviated as a dot) is not generally included in your PATH. You can also refer directly to a specific program, regardless of whether it's in your PATH, by specifying a full or relative path to it. So ./showargs means "showargs, in the current directory."

more falafel please
Feb 26, 2005

forums poster

Scaevolus posted:

Woops, for some reason I thought 0 worked as stdin-- on some systems stdin isn't defined in <stdio.h>, and 0 works fine.

0 is the file descriptor for stdin, but fgets() (along with fread, fwrite, fopen, etc) takes a FILE*. It also wouldn't work if you did read(stdin, buff, 100).

more falafel please
Feb 26, 2005

forums poster

Tomed2000 posted:

I'm not, just a student right now. I was having a conversation with a professor and he claims that 90% of the industry programs in a UNIX environment and I thought that was pretty inaccurate.

90% is inaccurate. But if you're doing web development, for instance, you can often work in whatever environment you want to, so many shops leave it open. If you're writing Java for a big iron machine, it doesn't matter if the development platform is Windows, OS X, Linux, whatever, if it runs Java it's probably a legitimate dev environment. For scripting languages (PHP, Python, Perl, Ruby) it doesn't really matter either, especially since it's probably only going to be run on the servers, not on your dev machine. In this case, your dev machine is essentially a text editor.

more falafel please
Feb 26, 2005

forums poster

Factor Mystic posted:

On the other hand, I for one would rather sit down and start coding instead of memorizing command line tools and other crap that stand between the program in my mind and the program-to-be on the computer. Plus, I love Visual Studio, so I'm biased here. I guess if you really love command line stuff, go for it, it certainly won't make you dumber.

E: VVV Really, such as? File->New Project too much? I think it's pretty intuitive.

With C++ at least, I never actually understood the build process, linking model, and even aspects of the language until I stopped using IDEs. It was only then that I understood what a "translation unit" was, really. In my opinion, going from command line to IDE is easier than the other way around, and I'm glad I can work in both environments.

more falafel please
Feb 26, 2005

forums poster

nolen posted:

Yeah, I can set the mode to passive then parse the IP and port that it returns. I guess I'm just confused about if I'm supposed to open another socket using that IP and port combination and then send my LIST and whatever commands over that socket instead of the control socket that's originally created.

If so, my way of doing it isn't working.

You still send all your commands over the control socket. The other socket you open is for data, so that's where the actual data will come from, and then you should get the response code over the control socket again.

more falafel please
Feb 26, 2005

forums poster

I'm drawing a blank coming up with a Google string for it, but a while ago (maybe 6 months) on The Daily WTF, there was a post with the output of a tool (or maybe just a quick perl script) that took Java code and printed only the control structures and method declarations (with no identifiers), so you were got "code" that looked like:
code:
class
{
    void (int, int)
    {
        if ()
        {
            if ()
            else
        }
        switch ()
        {
            case:
            case:
        }
    }
}
etc. Anyone remember this?

more falafel please
Feb 26, 2005

forums poster


Yeah, that's it... they didn't post the tool though. Nevermind. I'd like to do that same thing with some work code.

more falafel please
Feb 26, 2005

forums poster

Femtosecond posted:

Argh. I'm wanting to write a bit of code to keep track of statistics about my memory pool. I want to set up this UpdateMemoryStats function as a global so I can call it anywhere (or in the main loop) and I only want one set of stats, so I figure I should make the stats static. Unfortunately I keep getting a drat unresolved external symbol error. I'm obviously missing something... I've gone over this a bunch and I think I just need someone else to look at this or something.

Or if there's a better way to do this just suggest that.

code:
MemoryPool.hpp
==============
struct MemoryPoolStats
{
	int total_allocs;
};

class MemoryPool
{
	static MemoryPoolStats	mMemoryStats;
};

void	UpdateMemoryStats(); 

-------------------------------------------
MemoryPool.cpp
==============

void UpdateMemoryStats()
{
//an example of some operation on the mMemoryStats
MemoryPool::mMemoryStats.total_allocs = 0; //<-- I guess this is bad somehow

}

Somewhere (and only one place) you need to put
code:
MemoryPoolStats MemoryPool::mMemoryStats;
Probably in MemoryPool.cpp. If you put that definition in a header file, you'll get a multiply defined symbol error, assuming that header is included more than once.

more falafel please
Feb 26, 2005

forums poster

Skychrono posted:

I believe your guesses are right - we pretty much just react to the game instructions instead of really understanding them. I know there are some systems we "understand," like the NES, that we can perfectly emulate. Other than that things like the Emotion Engine and Mode 7 chips provide specialized speed for games that utilize it in the same way that a PhysX card does for computer games - we can emulate it, but it uses up speed on something else.

It's really more because game console hardware is a hell of a lot more complex than it was 20 years ago. Also, the operating systems and libraries on the consoles (those exist now) have to be duplicated almost exactly, and the only documentation for them (that you can get legally, at least) is how games use them. And, you don't have the source. It'd be like handing someone a copy of Office and the x86 spec and saying "emulate Windows running on a PC, but make it run on MIPS." It's theoretically possible, but it'd be a monumental effort.

more falafel please
Feb 26, 2005

forums poster

Plastic Jesus posted:

alias wireshark='open -a /Applications/Wireshark.app'

There is no reason to use xterm/iterm/anydamnedterm on OS X.

iTerm is perfectly acceptable, if that's what you're into. The only reason I used to like it was tabs, and Leopard's Terminal.app has tabs now. But it's certainly not inferior to Terminal.app.

more falafel please
Feb 26, 2005

forums poster

hey wiz posted:

The problem here is that your List is declared within the scope of the constructor, so after the constructor exits, you won't be able to access that list.

That second way shouldn't work either. List (java.util.List) is an interface and unlike classes, interfaces can not be instantiated. Did you write your own List class?

In C#, the language he's using, List is a generic class, which can be specialized and instantiated, which is what he's doing here.

more falafel please
Feb 26, 2005

forums poster

Runaway Five posted:

Question: What would be a good way to detect and alert the user of a computer if their Internet connection has been dropped. I tried to google search to see if such a thing already existed.

For example, a small application running in the background which will beep (or something like that) if the Internet connection dies?

Other than attempting to establish a connection with some server outside the network, there's no reliable way to do this. For all intents and purposes, pinging google.com should never fail.

more falafel please
Feb 26, 2005

forums poster

Incoherence posted:

The XOR trick probably works in more languages than tuple-unpacking in Python, but it has a significant effect on code clarity (what the gently caress are all of these ^=s doing in my code), and as an optimization it's fairly negligible.

The XOR trick is not an optimization, it's a trick. On modern CPUs it's actually slower because of pipelining. It's a "clever" trick undergrads show off to their friends.

swap_xor.c:
code:
void swap(int* a, int* b)
{
    *a ^= *b;
    *b ^= *a;
    *a ^= *b;
}

int main(int argc, char** argv)
{
    if (argc < 2) return 0;
    int n = atoi(argv[1]);
    int a = 42;
    int b = 6*9;

    int i;
    for (i = 0; i < n; ++i)
    {
        swap(&a, &b);
    }

    return 0;
}
swap_assign.c:
code:
void swap(int* a, int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main(int argc, char** argv)
{
    if (argc < 2) return 0;
    int n = atoi(argv[1]);
    int a = 42;
    int b = 6*9;

    int i;
    for (i = 0; i < n; ++i)
    {
        swap(&a, &b);
    }

    return 0;
}
code:
$ time ./swap_xor 1000000

real	0m0.013s
user	0m0.011s
sys	0m0.002s
$ time ./swap_assign 1000000

real	0m0.009s
user	0m0.008s
sys	0m0.002s
$ time ./swap_xor 10000000

real	0m0.104s
user	0m0.102s
sys	0m0.002s
$ time ./swap_assign 10000000

real	0m0.077s
user	0m0.074s
sys	0m0.002s
$ time ./swap_xor 100000000

real	0m1.022s
user	0m1.018s
sys	0m0.004s
$ time ./swap_assign 100000000

real	0m0.737s
user	0m0.732s
sys	0m0.003s
$ time ./swap_xor 1000000000

real	0m10.210s
user	0m10.178s
sys	0m0.030s
$ time ./swap_assign 1000000000

real	0m7.331s
user	0m7.310s
sys	0m0.014s
Unless you're optimizing for cleverness, or on a CPU with little to no instruction pipeline, don't ever do this.

more falafel please
Feb 26, 2005

forums poster

inlined, no pointers:
code:
1000 iterations:

real    0m0.002s
user    0m0.000s
sys     0m0.001s

real    0m0.002s
user    0m0.000s
sys     0m0.001s

1000000 iterations:

real    0m0.010s
user    0m0.008s
sys     0m0.001s

real    0m0.006s
user    0m0.005s
sys     0m0.001s

10000000 iterations:

real    0m0.083s
user    0m0.081s
sys     0m0.002s

real    0m0.044s
user    0m0.043s
sys     0m0.002s

100000000 iterations:

real    0m0.813s
user    0m0.810s
sys     0m0.003s

real    0m0.426s
user    0m0.424s
sys     0m0.003s

1000000000 iterations:

real    0m8.112s
user    0m8.092s
sys     0m0.019s

real    0m4.248s
user    0m4.237s
sys     0m0.010s
Unoptimized assembly, swap_assign.s (the important part, I took out all the argument code and atoi/dylib stub code):
code:
    jmp L5
L6:
    movl    -24(%ebp), %eax
    movl    %eax, -12(%ebp)
    movl    -20(%ebp), %eax
    movl    %eax, -24(%ebp)
    movl    -12(%ebp), %eax
    movl    %eax, -20(%ebp)
    leal    -16(%ebp), %eax
    incl    (%eax)
L5:
    movl    -16(%ebp), %eax
    cmpl    -28(%ebp), %eax
    jl  L6
    movl    $0, -44(%ebp)
L4:
    movl    -44(%ebp), %eax
    leave
    ret
Unoptimized assembly, swap_xor.s:
code:
L6:
    movl    -16(%ebp), %edx
    leal    -20(%ebp), %eax
    xorl    %edx, (%eax)
    movl    -20(%ebp), %edx
    leal    -16(%ebp), %eax
    xorl    %edx, (%eax)
    movl    -16(%ebp), %edx
    leal    -20(%ebp), %eax
    xorl    %edx, (%eax)
    leal    -12(%ebp), %eax
    incl    (%eax)
L5:
    movl    -12(%ebp), %eax
    cmpl    -24(%ebp), %eax
    jl  L6
    movl    $0, -28(%ebp)
L4:
    movl    -28(%ebp), %eax
    leave
    ret
Turning on even -O1 causes the swaps to get compiled out since the variables are never used outside of there.

edit: partially beaten, mine has the unoptimized assembly

more falafel please
Feb 26, 2005

forums poster

JawnV6 posted:

Ugh what a stupid unreadable hack to zero out a register. I despise this 'xor trick'

I used to use xor a on the Z80 because it was only 1 byte and like 2 cycles whereas the immediate move was 2 bytes and like 5 cycles or something.

But to be fair that was the Z80.

more falafel please
Feb 26, 2005

forums poster

Scaevolus posted:

s/partially/completely/; no one cares about unoptimized assembly, the whole point is for it to be savage :colbert:

:smith:

more falafel please
Feb 26, 2005

forums poster

Scaevolus posted:

s/partially/completely/; no one cares about unoptimized assembly, the whole point is for it to be savage :colbert:

It's only 'savage' because it optimized out the swaps altogether :pwn;

Triple post woo

more falafel please
Feb 26, 2005

forums poster

floWenoL posted:

Okay, this is how you do the benchmark. First you post the code, making sure to put something in to prevent the compiler from optimizing the whole thing out:


Then you post the relevant parts of the generated assembly:

code:
# tmpswap.s
.L14:
	movl	%eax, %ecx
	movl	%edx, %eax
.L7: # entry point
	addl	$1, %ebx
	movl	%ecx, %edx
	cmpl	%esi, %ebx
	jne	.L14
code:
# xorswap.s
.L7: # entry point
	xchgl	%eax, %ecx
	addl	$1, %edx
	cmpl	%edx, %ebx
	jne	.L7

Ok, but I think my point still stands, the compiler optimizes out the xor trick because it's not actually an optimization.

more falafel please
Feb 26, 2005

forums poster

unknown posted:

I've got a small code segment that's overflowing a string with the following:

code:
(void)sprintf(buff, "%d", pagecount++);
(void)strcat(p->messageid, buff);
and my quick rewrite:

code:
(void)sprintf(buff, "%s%d", p->messageid, pagecount++);
p->messageid = buff;
Not being a programmer, I've got to ask: Is there a better way of stopping the overflow?

You're not freeing the memory pointed to by p->messageid (assuming it was malloc()'d)

code:
size_t len = strlen(p->messageid) + sprintf(buff, "%d", pagecount++);
char* messageid = (char*)malloc(len+1);
strcpy(messageid, p->messageid);
strcat(messageid, buff);
free(p->messageid);
p->messageid = messageid;

more falafel please
Feb 26, 2005

forums poster

unknown posted:

Yes - it overflows by a character (pushing a null into the beginning of the next string in memory, therefore basically making it null). Of course, it compiles cleanly on a different OS version.

p->messageid was created using a strdup() call earlier on in the code.

Anyways, thanks for the tips/fixes!

strdup() internally uses malloc() (or something equivalent), so the memory pointed to by the return value of strdup() is the burden of the caller to free. So you still need to free() p->messageid before you assign something else to it.

more falafel please
Feb 26, 2005

forums poster

haveblue posted:

Partly because RMS is a big baby who doesn't want to mainline Objective-C at all (hence the perma-deprecated status of #import and GCC emitting punitive warnings about it).

#import in the actual language would reduce compile times on a lot of large projects by at least 50% (at least on Windows)

more falafel please
Feb 26, 2005

forums poster

Triple Tech posted:

Let's say we invented some sort of software-based intelligence...

If we decompiled said software, would it lead to some weird algorithm we've never seen before that unlocks the mysteries of life? Or would it be pretty normal looking?

Read GEB.

Adbot
ADBOT LOVES YOU

more falafel please
Feb 26, 2005

forums poster

rsjr posted:

I should probably reword my question.

I'm trying to verify my results with a standard binary search. Some search terms are returning not found (which is right), but they're not going through the maximum amount of probes before doing so. Is that normal in a binary search or do fail searches have to go through max probes before concluding that the item doesn't exist?

For example, if I had an array of 100 items, could it ever return not found after 6 probes instead of the max 7 probes?

A normal binary search won't check the bounds of the sub-haystack, but if this one does, it could early out as soon as it finds that the needle is outside the bounds of the sub-haystack.

Example in a weird search pseudocode i just made up:
code:
search({1 2 3 10 100 1000 10000}, 50)
50 > 1, 50 < 10000, so
50 > 10 so 
    search({100, 1000, 10000}, 50)
    50 < 100 so not found

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply