There's was a stackoverflow question to optimized this code from a computation puzzle:
I'm too lazy to look it up - what is that function supposed to even do? Or is it just purely a "puzzle" problem?
I looked it up - the problem statement in http://stackoverflow.com/questions/43029024/reducing-the-time-complexity-of-the-code-below is actually kind of ambiguous if it's just the first statement; if you follow the example, then it matches...
I took a look. It turns out that for that particular problem, caching the results is a huge win. For 10
9, for example, that reduces the number of calls from 1,023,093,838 to 691.
Sometimes, micro-optimizations distract you from the real problem with an algorithm.
Anyone have any experience with MATLAB? I'm taking a course with it and about to buy the software, but I'm not sure if there's any of the extra modules that are helpful enough to justify another 10 bucks each.
I used it in college, but can't say that I would ever have used it since then. Granted, I'm more willing than most to use open-source alternatives, programming myself to make up for any slack.
Anyone here had the displeasure of using make with Java?
I think I have, but I used to use make for quite a few things, and haven't really used Java for a decade or so.
sources = $(wildcard ./src/*.java)
Do note that this won't recurse into subdirectories. If all your .java files are in a single directory, it's fine, but I seem to recall the culture encouraging excessively deep directory structures.
classes = $(sources:.java=.class ./src/=./bin/)
This is a problem. It looks like you're trying to turn "./src/ClassName.java" to "./bin/ClassName.class" (completely reasonable), but you're actually turning it into "./src/ClassName.class ./src/=./bin/" due to a misunderstanding of the makefile variable substitution syntax. You could do it in two steps, or you could use the more powerful substitution form:
classes = $(sources:./src/%.java=./bin/%.class)
%.class : %.java
Make doesn't consider the definition of $classes when evaluating this rule, so it doesn't know how to find the right .java file. Even after correcting the definition as above, when it needs ./bin/ClassName.class, it will look for ./bin/ClassName.java, instead of ./src/ClassName.java, because the % symbols are straight-up substituted. Instead, you need:
./bin/%.class: ./src/%.java
$(JAVAC) $<
This line doesn't tell javac where to put the .class file, which would probably end up using its default location in the same directory as the .java file. You may want to override the sourcepath, too, in case it needs to look up information from another file.
$(JAVAC) -d bin -sourcepath src $<