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
Scaevolus
Apr 16, 2007

fret logic posted:

What are some good resources/books on programming theory?
Structure and Interpretation of Computer Programs

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

6174 posted:

If the program posted is actually TI-Basic you should be able to open the file in just a text editor to view the source without a cable. Granted you'd have to reimplement the program yourself if you want it on your calculator, but it would tell you how it is done.

No, the Ti-83 is too cool to do real tokenization, so it's essentially a binary format.

Scaevolus
Apr 16, 2007

Is there a name for the algorithm to convert a sorted list to a balanced binary search tree (something more efficient than iterating over the list and inserting items into an AVL tree)? I think I can do it in O(n), but Knuth probably already created a better algorithm 30 years ago or something.

I have a crappy illustration of what I mean (the left hand side of the diagram, I've already figured out what f(x) is)

Scaevolus
Apr 16, 2007

Sorry, let me try to explain better.

I don't need to modify this tree after I've created it.
By balanced binary search tree, I mean a balanced left-heavy tree, that is, the number of nodes to the right is <= the number of nodes to the left.

Basically, I want to flatten this binary tree in an array, where I know the position of the children nodes based only on the index of the parent node. In my example, I'm transforming {1,2,3,4,5,6} to {4,2,6,1,3,5}.

The question is if this process has a name I can use to refer to it easily?

Scaevolus
Apr 16, 2007

ShoulderDaemon posted:

If you don't want to construct the pointers, then obviously you can just iterate the index discovery expression used here.
Each node will only have 12 bytes of data, so it's pretty big if I can save 8 bytes on pointers.

Never mind, I was just wondering if there was a name for it.

Scaevolus
Apr 16, 2007

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.

Have you looked at Google AppEngine? (Python/Django)

Scaevolus fucked around with this message at 20:43 on Apr 12, 2008

Scaevolus
Apr 16, 2007

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;
}
What happens when you pipe a line with more than 100 characters into this program? Foo is only defined to be 100 characters, so you end up writing to other memory. This is a buffer overflow, and you need to beware of them when you write C.

What you should be doing is
while (fgets(foo,100,0) != NULL) {

Scaevolus
Apr 16, 2007

Vanadium posted:

At least he does not instantly get a segfault from passing null pointers as streams.
Sorry about that, I was thinking of read() and write(), which take (int fd..), which is 0 for stdin.

vv Yeah, I know. Difference between int fd and FILE *stream and all that.

Scaevolus fucked around with this message at 02:40 on Apr 19, 2008

Scaevolus
Apr 16, 2007

Moof Strydar posted:

Python example of mapping:
code:
datamap = {}
for datarow in dsProdID:
  currID1 = datarow.Item("ProdID1")
  currID2 = datarow.Item("ProdID2")
  # If we've seen this ID1 before
  if datamap.has_key(currID1):
    # Add data to end of list for this ID1
    datamap[currID1].append(currID2)
  else:
    # Create new list for this ID1
    datamap[currID1] = [currID2]
Terser:
code:
datamap = {}
for datarow in dsProdID:
  currID1 = datarow.Item("ProdID1")
  currID2 = datarow.Item("ProdID2")
  datamap[currID1] = datamap.get(currID1, []) + [currID2]

Scaevolus
Apr 16, 2007

tripwire posted:

I've been trying to change a genetic algorithm which is normally done in serial to run in parallel.
Are you trying to optimize something in Python? Maybe you should look into Pyrex or some similar tool before trying to parallelize it.

Python isn't really designed for fast number crunching.

Scaevolus
Apr 16, 2007

more falafel please posted:

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

Looks like that was done by hand, not by a tool.

Scaevolus
Apr 16, 2007

Jo posted:

Regex Request:

I'm looking to parse the following file:
code:
<Map XMLblahblah>
  <XML Jibba Jabba>
  <Tour distance="FLOATINGPOINTVALUE!">
  <More>
</Map>
There are about 30,000 of these files. I need a regular expression I can feed to egrep that will extract only the value 'FLOATINGPOINTVALUE', not the surrounding quotes or xml.

I've tried distance=\"[0-9]*\.[0-9]*, but that gives me the XML before it, too.

grep -oP '(?<=distance=")[0-9]*\.[0-9]*' works.

Scaevolus
Apr 16, 2007

How is rxtv-unicode on OS X?

Scaevolus
Apr 16, 2007

Geno posted:

this is probably a stupid question but what do you guys think are better for programming: macs or PCs?

Macs, because OS X is Unix-derived, which is a much better programming environment than Windows.

Scaevolus
Apr 16, 2007

tef posted:

Beyond that I think the answers are in the realms of personal preference.

Silly tef, an open ended question is clearly a plea for personal opinions and anecdotal evidence.

Scaevolus
Apr 16, 2007

rugbert posted:

I need something for webpages that lets you drag and drop supplied images onto an image with a predefined perimeter. Specifically, I wanna make something like
this

but not nearly as complex. So what language would I have ot teach myself to do that, or does anyone know of some free code I can grab?
Something like http://www.walterzorn.com/dragdrop/dragdrop_e.htm maybe?

Scaevolus
Apr 16, 2007

Ugg boots posted:

Why are you using a macro when you can just use the pusha and popa instructions?

I knew there was an opcode for this! What use is CISC without register pushing?

Scaevolus
Apr 16, 2007

GT_Onizuka posted:

There doesn't seem to be a general Ruby thread, so I figured I'd ask my question here.
I'm sure the Ruby on Rails Love-in wouldn't mind discussing pure Ruby.

Scaevolus
Apr 16, 2007

Jam2 posted:

How good do ones math skills need to be to excel at programming?

There's a strong correlation between being good at programming and being good at math, as they require similar types of thinking. However, you don't need to know the most obscure branches of mathematics to be a good programming. A solid grasp of Algebra is usually sufficient.

Scaevolus
Apr 16, 2007

Runaway Five posted:

So, int a = 7; int b = 3; int c = 43; int d = 213;
b gets assigned the value of a.
c gets assigned the value of b.
d gets assigned the value of c.
a gets assigned the value of d.
You could do it with one temporary variable

code:
int a = 7, b = 3, c = 43, d = 213;
int t;
t = d;
d = c;
c = b;
b = a;
a = t;
(you could probably also do the retarded xor trick but that's pointless and slow)

Unless I missed something?

Scaevolus
Apr 16, 2007

bitprophet posted:

For what it's worth, some languages let you do this on the fly, although I don't remember the technical term for it (I believe there was one).

In Python, for example:
In Python this is called unpacking, and it works by making a tuple (a,b,c,d) and then unpacking it and doing the assignment to each variable. So it's the equivalent of making four temporary variables, and then doing the assignment.

Scaevolus
Apr 16, 2007

bitprophet posted:

Sounds about right; also fits with how higher level languages usually do things that are syntactically simpler than their lower level counterparts, but not necessarily any faster or more efficiently.

code:
$ cat pretty.py && time python pretty.py
a, b, c, d = 25, 50, 75, 100

for x in xrange(10000000):
    a, b, c, d = b, c, d, a

real	0m6.473s
user	0m6.264s
sys	0m0.052s

$ cat savage.py && time python savage.py
a, b, c, d = 25, 50, 75, 100

for x in xrange(10000000):
    t = d
    d = c
    c = b
    b = a
    a = d

real	0m6.796s
user	0m6.588s
sys	0m0.028s
v:shobon:v

Unless you're swapping megabytes of memory many times per second, swapping probably isn't anywhere close to a bottleneck.

Scaevolus
Apr 16, 2007

Milde posted:

The objects aren't being "swapped", you're just changing what objects the names a, b, c, and d refer to. If you use a temporary variable for whatever reason, you're just creating an extra reference, not a copy of the object.
Crap, I keep on forgetting that everything is an object. :smith:

(assigning references should about as expensive as assigning ints anyways)

Scaevolus
Apr 16, 2007

N.Z.'s Champion posted:

This is probably a stupid question but lets say that I've got variables A and B... is there a way to swap their values without using a third variable (Eg, C = A, A = B, B = C) and without meddling with pointers?

I guess I was just wondering whether there's some syntax for this that I was unaware of, perhaps in a single expression.

(in Python, PHP, whatever)

Do you guys go to the same school?

Scaevolus
Apr 16, 2007

Using a few extra bytes for a temporary variable is almost certainly going to be both clearer and faster than a "clever" xor trick.

Scaevolus
Apr 16, 2007

tef posted:

He retaliated by making me explain it to the rest of the group.
How long did it take for them to understand the binary representation of integers?

Scaevolus
Apr 16, 2007

edit: so apparently it completely optimized out the variables it was swapping, because they never did anything :downs:

Scaevolus fucked around with this message at 22:18 on Aug 26, 2008

Scaevolus
Apr 16, 2007

more falafel please posted:

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

edit: gently caress

Scaevolus fucked around with this message at 22:18 on Aug 26, 2008

Scaevolus
Apr 16, 2007

Arconom posted:

Anyone here done any procedurally generated maps and the like? I want to write some code to procedurally generate a world from the depths of the ocean upward, and I'm looking for a mysterious code ninja to point me in the right direction. I have never done any procedurally generated coding.
Look at how Terragen does things, and maybe read these articles. You'll probably end up using Perlin noise a lot.

Scaevolus
Apr 16, 2007

Jo posted:

I believe the xor trick is vestigial. Moves use to cost a lot more CPU than exclusive or in the early Pentium/AMD days, so it was very neat at the time.

xor eax, eax is still faster than mov eax, 0

Scaevolus
Apr 16, 2007

Jo posted:

Correct me if I'm mistaken: #define or set_name or whatever for a compiled language makes its way into the executable code while constant final static makes its way into a register. Is there really any performance difference in the grand scheme of things?
:what: Usually when you compile things they "make their way" into the executable.

Scaevolus
Apr 16, 2007

Jo posted:

code:
addq $400, %eax
code:
movq $400, %r1
addq %r1, %eax

AT&T syntax is gross

Scaevolus
Apr 16, 2007

Chuu posted:

This code does not work for because of double's native representation that doesn't correspond well to Decimal, which are easier to gut check then explain (3.43 -> 3.43000000000001 -> 3430000000000001 * 10 -> +inf).

Valid range of double values is from 0000.1 to 99999.

I'm assuming just adding an /epsilon value and checking the remainder against it is all I need to fix this, but my brain is so fried I can't formulate it.

Any help?

I would do something like sprintf(buff, "%.8f", float) and parse the resulting string instead of manually converting a float.

Scaevolus
Apr 16, 2007

quadreb posted:

So I received the following window on my screen:



This is related to the commercial game "Left 4 Dead".

Is it best practices to leave assert statements in C++ code? This seems like a dev written debugger too?
Well, it would make sense to leave in an assertion that new allocations worked.

quote:

Also, any idea why it would be referencing a "U" drive that is invisible to windows explorer both before, during, and after running the game?
U:\ is probably a network drive that their build machine pulled the source code from.

Scaevolus
Apr 16, 2007

Mata posted:

Alright, bear with me on this one.. I'm trying to generate an infinitely large height-map. I want it to resemble a landscape/map of some sort, so I don't want there to be any obviously recognizable patterns, but it can't be "too" random: Hills and mountains have slopes, not random jagged spikes, same with continents and oceans... So I figured, overlapping sine functions with random periods might look good: A huge sine curve would form continents, smaller ones would be mountain ranges, smaller still might make hills, etc: Plus, it "loops" so it doesn't matter wether you're looking at a region at (100000,70000) or at (0,0).

Perlin noise sounds perfect for what you want to do. It's basically your like your idea of layering multiple sine functions. Here's a good tutorial on it. It's quite efficient as well.

You can tweak the parameters to get various effects: (from here)


e: simplex noise (also invented by Perlin) might be better

quote:

The advantages of simplex noise over Perlin noise:
* Simplex noise has a lower computational complexity and requires fewer multiplications.
* Simplex noise scales to higher dimensions (4D, 5D and up) with much less computational cost, the complexity is O(n>n) for n dimensions instead of the O(2n) of classic Noise[2].
* Simplex noise has no noticeable directional artifacts (is isotropic).
* Simplex noise has a well-defined and continuous gradient everywhere that can be computed quite cheaply.
* Simplex noise is easy to implement in hardware.

Perlin/simplex noise is much easier to generate in realtime than fractal noise.

Scaevolus fucked around with this message at 07:51 on Jan 7, 2009

Scaevolus
Apr 16, 2007

csammis posted:

I don't know about \b, but \r was used as the full newline character on pre-OS X Macs, so it wouldn't have the effect of moving the cursor back to the start of the current line.
Yeah, because we really need to support the vast quantities of pre-OS X Macs. Carriage return is an even worse newline character than "\r\n".

Scaevolus
Apr 16, 2007

hexadecimal posted:

I got one, dawg, its posted on my wall.
Was !(x^y) on your certification exam?

Scaevolus
Apr 16, 2007

Dijkstracula posted:

One of the good things about Java is that it does force you to code in a certain way; with C++, your methology can range from "procedural programming with iostreams" to "C with classes" to "Java-style OOP where most everything is a class" to "template metaprogramming and C++0x draft standard wankery" and everything in between.
Giving people a big hammer labeled "OOP" instead of a set of (perhaps mysterious) tools is not really a good thing.

For learning, maybe, but this guy is asking about Java because he sees lots of jobs for Java programmers.

Scaevolus
Apr 16, 2007

shodanjr_gr posted:

Any suggestions on a good and extensive book about data structures? I'm finishing my bachelor in CS and looking to get a good revision (and expansion) on the field before I move on to graduate studies, and the textbook we got for our undergrad course was a bit crappy. Ideas?

CLRS is a good choice.

Of course, you can't discuss data structures without covering algorithms as well.

Scaevolus fucked around with this message at 02:31 on Feb 4, 2009

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

Pweller posted:

I have a small app that runs in a command prompt. I want to automate the running of this executable using a batch file, but the program prompts for user input twice. Is there any way I can pass the values for the two prompts from the batch file to the executable it calls? Two inputs are always the same.

backup.txt:
code:
8
Y
backup.bat:
code:
backup.exe < backup.txt

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