|
Because I'm such a nice guy, here's the base code fixed. There may be a neat linear algebra solution, but that's why we have fancy packages that do things like that like those I linked in the last post. You will need to make sure your base data is organized like the program is expecting. Just do me a favor and don't come around here using variables based on a object named system that is not actually a System object ever again though. code:
|
# ? Nov 4, 2009 12:07 |
|
|
# ? Apr 20, 2024 00:20 |
|
Hey, thanks! The "-1" screwed up the part you were talking about, and the function I made that reset matrices to zero. Fixed those, and everything is working smoothly as far as I can tell. I appreciate the links to the extra math libraries, but unfortunately, we're not allowed to use any external libraries. I thought about 'peaking' at the code in some external libraries and using their strategy for dealing with matrices, but then decided that the teacher probably wanted the textbook definition for matrix multiplication instead of an optimized, sane-person algorithm. But the other part of what you said fixed it anyway, so thanks again!
|
# ? Nov 4, 2009 12:11 |
|
No problem. Out of curiosity, how does this tie into detecting deadlock?
|
# ? Nov 4, 2009 12:18 |
|
Kilson posted:It doesn't stop or exit, it just continues running (after skipping whatever code it skips) as if nothing ever happened.
|
# ? Nov 4, 2009 17:07 |
|
It's a linear adjacency matrix that represents a process-resource graph. The matrix has 1s for where there are edges in the graph, and 0s for where there are not. If a process-resource graph has no loops, it isn't deadlocked. Taking an adjacency matrix to the (n+1) power will check if it has loops (if it's not all zeros by that point, there's a loop). As for the 'system' variables, the professor wanted a 'system' variable container that held how many processes the system had, how many resources, and the adjacency matrix. In this case I decided to reference it as a generic "system", and in more specific parts of the code I referenced it as "sys1", "sys2", etc. Sorry for the confusion. edit: and by loop, I mean cycle
|
# ? Nov 4, 2009 20:11 |
|
Kilson posted:It doesn't stop or exit, it just continues running (after skipping whatever code it skips) as if nothing ever happened. Are you absolutely certain that the code being executed is the same version as the source code you're looking at? I realise it sounds silly but I know in the past I've wasted hours trying to figure out why my changes weren't working only to realise that I'd been deploying the wrong package and my changes hadn't been going in at all
|
# ? Nov 5, 2009 02:36 |
|
Why won't my Fibonacci thing work?:code:
|
# ? Nov 5, 2009 06:09 |
|
StickFigs posted:Why won't my Fibonacci thing work?: I don't know but it's painful to try to decipher. This is a recursive Fibonacci sequence: code:
|
# ? Nov 5, 2009 06:29 |
|
StickFigs posted:Ignore the weird simulated process stack thing, what I'm trying to do is Fibonacci with recursion and it looks like it's working in the console but when it gets to the end (In the case I'm testing it in, the Fibonacci factor or whatever of 4) and at 4 it should be 5 but it's 4. How am I loving up? It's impossible to say without knowing the return-value convention, but my guess is that both lineThree and lineFour are wrong. lineThree is saving the argument to this activation instead of the result from the first recursive call. lineFour is returning the argument to this activation instead of the sum of the results of the recursive calls. This is a very silly simulation, by the way. It would be much better to force students to write a simple stack machine with a fixed instruction set and then write a recursive fibonacci in that machine's assembly language. rjmccall fucked around with this message at 09:03 on Nov 5, 2009 |
# ? Nov 5, 2009 08:59 |
I've got a string with an HTML snippet in it. I need a List of innerHTML for all the table cell elements. A regexp seems like the right tool, I'm just horrible at it. Can anybody help me out?
|
|
# ? Nov 5, 2009 18:39 |
|
yatagan posted:I don't know but it's painful to try to decipher. This is a recursive Fibonacci sequence: Or if you care about efficiency: code:
|
# ? Nov 6, 2009 04:13 |
|
Steell posted:Or if you care about efficiency: There are easier ways to improve on the efficiency of a naive recursive fib() implementation
|
# ? Nov 6, 2009 04:32 |
|
Otto Skorzeny posted:There are easier ways to improve on the efficiency of a naive recursive fib() implementation Like implementing it iteratively, or what did you have in mind? It's been a while since I've needed to optimize recursion.
|
# ? Nov 6, 2009 06:08 |
|
fletcher posted:I've got a string with an HTML snippet in it. I need a List of innerHTML for all the table cell elements. A regexp seems like the right tool, I'm just horrible at it. Can anybody help me out? Like this? code:
|
# ? Nov 6, 2009 06:21 |
Save the whales posted:Like this? Doesn't seem to work when the cell has an attribute: <td onclick="what()"></td>
|
|
# ? Nov 6, 2009 07:52 |
|
fletcher posted:I've got a string with an HTML snippet in it. I need a List of innerHTML for all the table cell elements. A regexp seems like the right tool, I'm just horrible at it. Can anybody help me out? code:
code:
epswing fucked around with this message at 08:31 on Nov 6, 2009 |
# ? Nov 6, 2009 08:25 |
|
fletcher posted:Doesn't seem to work when the cell has an attribute: <td onclick="what()"></td> Oh right it was searching for exactly <td>. Here's another one: code:
Save the whales fucked around with this message at 08:46 on Nov 6, 2009 |
# ? Nov 6, 2009 08:42 |
|
That is why you don't use regexes for parsing XML or HTML and instead do something like what epswing posted.
|
# ? Nov 6, 2009 14:17 |
Thanks to both of you guys for the help, but I think I'm gonna have to go with epswing's solution for this one! Thank you!
|
|
# ? Nov 6, 2009 19:21 |
|
fletcher posted:Thanks to both of you guys for the help, but I think I'm gonna have to go with epswing's solution for this one! Thank you! epswing's suggestion is perfect, if the HTML you get to parse is properly formatted. Another suggestion would be to use a HTML parser (as opposed to an XML one), such as the one in the JDK : http://java.sun.com/javase/7/docs/api/javax/swing/text/html/parser/Parser.html That one is a bit more forgiving. Or a 3rd party library, like http://htmlparser.sourceforge.net/
|
# ? Nov 7, 2009 06:07 |
|
rhag posted:epswing's suggestion is perfect, if the HTML you get to parse is properly formatted.
|
# ? Nov 7, 2009 13:33 |
|
Is there an easy way to create a Swing GUI (or part thereof) with overlapping components, but with as little absolute positioning as possible and greatest use of existing Swing widgets? Specifically, I'm working on a simple card game, and I want to have cards overlap nicely when displaying hands. If worst comes to worst, we can do everything manually, but it seems like this must be possible somehow, and doing it the "proper" way seems to me to be much less error-prone.
|
# ? Nov 7, 2009 15:01 |
|
Hi, I have a question I'm having trouble understanding. Using the class Buffer construct a pipeline of threads that will sort, in ascending order, a given list of numbers. Each thread in the chain receives the next number from its predecessor and chooses to keep it or pass it on. It keeps the value if it is less than its current value. To communicate the threads use an array of Buffer. The source of the data, i.e. the data generator, writes N items in turn to the first buffer in the chain. Each thread in the chain reads from its buffer waiting if necessary. When the sort is complete each thread should copy its number to a shared array. code:
Data generator (thread that just generates random ints to the first buffer) Buffer[100] 100 Threads Thread0 calls Buffer[0].read twice. Thread0 writes the buffer with highest value to Buffer[1] Thread1 calls Buffer[1].read Following step is repeated N times. Thread0 calls Buffer[0].read Thread0 writes the buffer with highest value to Buffer[1] Thread1 writes buffer with highest value to Buffer[2] Thread2 calls Buffer[2].read etc.. From the question am I on the right track? Once Thread0 has nothing left to read, the random ints will be sorted. Each Thread will then write to a result[] Thread0 writes its value to result[0] and so on.
|
# ? Nov 7, 2009 16:37 |
|
PT6A posted:Is there an easy way to create a Swing GUI (or part thereof) with overlapping components, but with as little absolute positioning as possible and greatest use of existing Swing widgets? Specifically, I'm working on a simple card game, and I want to have cards overlap nicely when displaying hands. I haven't used Swing much, but that doesn't sound like something Swing is intended for. Maybe use JavaFX for drawing the card game and Swing around it for GUI?
|
# ? Nov 7, 2009 17:15 |
|
PT6A posted:Is there an easy way to create a Swing GUI (or part thereof) with overlapping components, but with as little absolute positioning as possible and greatest use of existing Swing widgets? Specifically, I'm working on a simple card game, and I want to have cards overlap nicely when displaying hands. If worst comes to worst, we can do everything manually, but it seems like this must be possible somehow, and doing it the "proper" way seems to me to be much less error-prone. Swing at the high level is not a graphics library. It is a platform windowing toolkit (as is the awt upon which swing is built, and swt). Specifically, it was designed so you could have consistent theme across multiple platforms. However, you do have access to basic image rotation, scaling, etc provided through the underlying awt. You would copy the rotated image onto a general image. If you are looking for something more, then you will need to look at JavaFX.
|
# ? Nov 7, 2009 17:49 |
|
I'm making a tile-based game, and I'm a little confused on this: I have an array for my map, and I have a tile system. A Tile has numerous values, like pollution, power, type, etc. How do I tell the system what part of the array is what kind of tile, and what the values in that specific tile in that part of the array are? also, just to clarify, Tile is a class. Foran fucked around with this message at 03:34 on Nov 8, 2009 |
# ? Nov 8, 2009 03:21 |
|
Rsugar posted:I'm making a tile-based game, and I'm a little confused on this: You can just make a Tile object which has the appropriate getters and setters for the basic attributes. Tile-specific behavior can be handled through subclassing. Then just stick them into your array and just look it up using the coordinates when you need them. edit: Are you having trouble with array lookups?
|
# ? Nov 8, 2009 03:37 |
|
1337JiveTurkey posted:You can just make a Tile object which has the appropriate getters and setters for the basic attributes. Tile-specific behavior can be handled through subclassing. Then just stick them into your array and just look it up using the coordinates when you need them. ah, gently caress. No, I was just thinking too hard. I've done this all before, and in c++, but I've been reading through java books all day and haven't really allowed all of it to process. Thanks though, that is what I was I was looking for.
|
# ? Nov 8, 2009 03:44 |
|
This is some sort of hosed up cross-post post type question which is neither purely C nor Java related. I'm intermediate with Java, and barely a beginner with C. I've been playing with JNA, trying to use the WinAPI examples to access the icons on my desktop. ( I want the positions, names, path, and iconimage of each icon on the desktop as part of an larger project.) I found an old-ish C program which does most of what I want, and have been attempting to port it to Java. I'm using JNA to do the Windows API calls. I apparently need to use shared memory with my Explorer process to read the positions of the icons. My difficulty arises in trying to port the statements: code:
What is the sizeof() of an LVITEM or POINT? I'm assuming I only need to know this so I don't walk over into other areas of memory? Can I get away with using some unholy huge int, or would that only gently caress me up further? What C/C++ library would I find sizeof() if LVITEM's size is ambiguous? Does JNA have some sort of example of the sizeof() function ported to Java and how it might be applied here?
|
# ? Nov 8, 2009 07:53 |
|
operator sizeof is not a function
|
# ? Nov 8, 2009 09:53 |
|
Ok, so back to another problem, terrain generation. My game works in similar form to Sim City 4, in that there is a large World(region in sc4) map, comprised of tiles containing City maps. I know that I can use fractals to generate height-maps, but how can I take that height map (which is converted into an array of a sequence of numbers, i.e. a number 1 in the array designates a water tile, 2 a grass tile, etc.), and then from the resulting tiles, generate terrain based upon that tile to fill the city map? keep in mind that adjacent city maps should probably conform to neighboring city maps... Foran fucked around with this message at 00:26 on Nov 9, 2009 |
# ? Nov 9, 2009 00:24 |
|
I have an interview on Thursday for an internship wherein I would be writing Java. Now, they're looking for somebody at a junior level so they probably don't expect me to have much more experience than an undergraduate algorithms class, basic principles of software development, and data structures -- all of which I'm totally confident in and I have no worries about my ability to interview confidently based on them. On the other hand, my knowledge of Java goes about as far as implementing a binary search tree. 99.98% of my programming experience is in C++, which I'm definitely intermediate level with. Is there some "Java for retards who happen to know C++ pretty well" website? I just need something I can read in an afternoon that tells me "X feature in Java is really Y feature in C++" so if I get Java-specific questions like "when would you use a java beans AWT noun noun noun" I can answer them without looking like a horrible moron.
|
# ? Nov 10, 2009 19:00 |
|
timecircuits posted:I have an interview on Thursday for an internship wherein I would be writing Java. Java is significantly different from C++ in how it's used so it's hard to just give a 1:1 mapping beyond libraries like SAX or OpenGL/JOGL. The official tutorials keep the basic language syntax to one section of one tutorial so you can just skip the stuff on basic flow control. You'll probably want to understand how Java handles exceptions differently as well as how it handles inheritance but those are both less complex than C++. The tutorials also cover a lot of the basic libraries that you'll want to know. Focus on having a solid understanding of the basics and don't worry about the more complex APIs. There's always the risk that you'll run into some insane interviewer who considers knowing how to diagnose bizarre classpath issues running WAS 6.1 on Solaris to be fair game but you can't plan for every contingency. On the other hand it's much more likely that they'll want someone who understands the difference between a List<String>, a LinkedList<String> and an ArrayList<String> and which can be used in place of which.
|
# ? Nov 10, 2009 20:52 |
|
1337JiveTurkey posted:Java is significantly different from C++ in how it's used so it's hard to just give a 1:1 mapping beyond libraries like SAX or OpenGL/JOGL. The official tutorials keep the basic language syntax to one section of one tutorial so you can just skip the stuff on basic flow control. You'll probably want to understand how Java handles exceptions differently as well as how it handles inheritance but those are both less complex than C++. The tutorials also cover a lot of the basic libraries that you'll want to know. Focus on having a solid understanding of the basics and don't worry about the more complex APIs. There's always the risk that you'll run into some insane interviewer who considers knowing how to diagnose bizarre classpath issues running WAS 6.1 on Solaris to be fair game but you can't plan for every contingency. On the other hand it's much more likely that they'll want someone who understands the difference between a List<String>, a LinkedList<String> and an ArrayList<String> and which can be used in place of which. Thanks, this is exactly what I was looking for!
|
# ? Nov 10, 2009 22:23 |
|
I was going to say that I've never found a use for a LinkedList over an ArrayList, but then I remembered that it implements the queue and deque interfaces.
|
# ? Nov 10, 2009 22:37 |
|
MEAT TREAT posted:I was going to say that I've never found a use for a LinkedList over an ArrayList, but then I remembered that it implements the queue and deque interfaces. It's also good for data structures 1 homework where your professor thinks your name is Josh Bloch.
|
# ? Nov 10, 2009 22:53 |
|
MEAT TREAT posted:I was going to say that I've never found a use for a LinkedList over an ArrayList, but then I remembered that it implements the queue and deque interfaces. I'm just the opposite and tend to use LinkedList more. However, a lot of my work involves queues and processing huge collections at once with additions only at the end. Might also be a bit of my functional programming creeping in. I usually find HashMap or TreeMap to be my goto data structures though.
|
# ? Nov 11, 2009 02:15 |
|
I generally use a LinkedList by default and switch to an ArrayList when I know I'll need efficient random access. I mostly use a List for iteration, so a LinkedList works just as well. I usually specify variables and parameters as a List, except when using Swing to draw a GUI. I don't know this for sure, but I think a JTable needs random access, so in my Swing GUI code, I have a variable specified as an ArrayList to keep me from accidentally putting a LinkedList in it.
|
# ? Nov 11, 2009 04:24 |
|
Unless you are using large lists (say 20000+), an ArrayList will be faster and allows constant time random access. If you only need to use the Deque interface, why not just use an ArrayDeque? Hell, if you only use List for iteration, just use Collection.
|
# ? Nov 11, 2009 05:39 |
|
|
# ? Apr 20, 2024 00:20 |
|
Brain Candy posted:Hell, if you only use List for iteration, just use Collection.
|
# ? Nov 11, 2009 05:58 |