|
Those are great suggestions but I'm just going to use geocities pagebuilder and abandon the database in favor of an enormous block of obfuscated text, queries will be performed with ctrl+f. Really though I think I'll try java, I looked at scala/lift and while it is nifty I'm not sure if I'll have the capabilities to implement it on such short notice, but thanks for the suggestion.
|
# ? Nov 30, 2009 22:11 |
|
|
# ? May 16, 2024 10:06 |
|
Edit: I figured it out.
darfur fucked around with this message at 05:22 on Dec 2, 2009 |
# ? Dec 1, 2009 00:13 |
|
Is there a canonical algorithm for choosing an element from a set of elements and weights? foo:2 bar:1 foo randomly gets chosen twice as often as bar given a call to pick an element.
|
# ? Dec 1, 2009 21:02 |
|
Triple Tech posted:Is there a canonical algorithm for choosing an element from a set of elements and weights? Choose a random natural number uniformly distributed, strictly less than the sum of weights. If it is strictly less than the weight of the first element in the list, then select the first element. Otherwise, subtract the weight of the first element from your random number, and recurse to the next element of the list.
|
# ? Dec 1, 2009 21:08 |
|
Triple Tech posted:Is there a canonical algorithm for choosing an element from a set of elements and weights? What ShoulderDaemon said, except: {a:2, b:1, c:3, d:4, e:2, f:5, g:2} First, precompute the cumulative sum: {a:2, b:3, c:6, d:10, e:12, f:17, g:19} Then pick a random number uniformly in the set (0, 19] and use binary search to get the least element greater than or equal to number you've chosen, in O(log(n)) time.
|
# ? Dec 1, 2009 22:06 |
|
Or, if you're really desperate for an O(1) solution, create an array of length equal to the sum of the (integer) weights where each weighted element is assigned to a number of indexes corresponding to its weight, and randomly pick indexes.
|
# ? Dec 1, 2009 22:08 |
|
haveblue posted:Or, if you're really desperate for an O(1) solution, create an array of length equal to the sum of the (integer) weights where each weighted element is assigned to a number of indexes corresponding to its weight, and randomly pick indexes. That's not really O(1) because the random number you pick will still have to have length at least log_2(n). And what if you have floating point weights?
|
# ? Dec 1, 2009 22:22 |
|
shrughes posted:What ShoulderDaemon said, except: This is better if you're going to be selecting from the same set over and over again. If you only select once from a set, it has the same complexity as the naive method, though, and requires the use of vectors rather than lists because binary search wants cheap random access. You can also do a variant without precomputing any sum at all in O(n). Remember the first element as the candidate, and its weight as the cumulative sum. For each successive element, add that element's weight to the cumulative sum. Then, generate a random natural strictly less than the cumulative sum. If that number is strictly less than the current element's weight, then use the current element as the new candidate, otherwise preserve the previous candidate. When you run off the end of the list, the candidate is your random selection. Now, for fun, find someone who knows what the Monty Hall problem is, and have a week-long argument about the correctness of this method.
|
# ? Dec 1, 2009 22:41 |
|
I use this in buttbot http://prxq.wordpress.com/2006/04/17/the-alias-method/
|
# ? Dec 1, 2009 22:46 |
|
tef posted:I use this in buttbot http://prxq.wordpress.com/2006/04/17/the-alias-method/ Could you explain this less tersely? It's a bit hard to follow and it starts introducing variables out of nowhere.
|
# ? Dec 1, 2009 23:04 |
|
I didn't implement it in buttbot, but you might find the perl more enlightening. http://code.google.com/p/buttbot/source/browse/trunk/Butts.pm tef fucked around with this message at 23:16 on Dec 1, 2009 |
# ? Dec 1, 2009 23:12 |
|
I'm trying to grok it as best as possible, but I still don't get it. The algorithm visually and I think cost-wise looks so much more complicated. And for what? I think to make it less computationally expensive? I'm not convinced... The naive solution doesn't look that expensive to begin with... Hmm I think maybe it is cost effective on recurring runs... That the naive implementation has a high search cost but the alias method is indexed... I guess that makes much more sense. Me, I only needed one run, so the naive implementation is cheaper. If you did repeated selections, then the alias method would be cheaper over time. Edit: It's terribly interesting. I will make the false promise of using my time and my poor foundation in computer science to draft something up that is infinitely more clear and verbose... Triple Tech fucked around with this message at 00:04 on Dec 2, 2009 |
# ? Dec 1, 2009 23:54 |
|
Triple Tech posted:Hmm I think maybe it is cost effective on recurring runs... That the naive implementation has a high search cost but the alias method is indexed... I guess that makes much more sense. Note that all optimizations you see for this are only going to optimize repeated selection cases; it's relatively straightforward to prove that O(n) is as good as you can do for the single selection case, as there are n weights, all potentially different, that you have to examine. The alias method happens to be an excellent optimization that is both very space- and very time-efficient for repeated selections.
|
# ? Dec 2, 2009 00:00 |
|
Yeah, I'm not really sure why you'd care about "canonical algorithms" for something you're only doing once, since at that point, the only factor is really the ease of implementation. It would take a pretty pathological program for it to be bottlenecked by code that only runs once.
|
# ? Dec 2, 2009 00:34 |
|
Does anyone have a good example resume for a CS Major looking for a part-time job/internship? EDIT: I was looking at this one but I obviously don't have that much experience plus why would anyone care that I know how to animate GIFs or use Powerpoint? EDIT2: Forget it, my brother gave me his, which he shamelessly stole from yet another person. Cicero fucked around with this message at 06:40 on Dec 2, 2009 |
# ? Dec 2, 2009 04:51 |
|
Cicero posted:Does anyone have a good example resume for a CS Major looking for a part-time job/internship? The whole point of a resume is to make you stand out. Make sure you're not using something that started as a word template...
|
# ? Dec 2, 2009 09:04 |
|
Cicero posted:EDIT: I was looking at this one but I obviously don't have that much experience plus why would anyone care that I know how to animate GIFs or use Powerpoint? This resume is god awful. It took me a couple glances to realize that he even listed programming languages at all. And even then, when HTML is your first on the list, there's a problem. That's aside from grammatical issues ("various print medium") and weasel phrases that even HR can tell mean nothing ("Support the Health Net Health Plan of Oregon Web Site using HTML and MS Front Page.") Avenging Dentist fucked around with this message at 10:08 on Dec 2, 2009 |
# ? Dec 2, 2009 10:05 |
|
Something is going very strange in this batch file:code:
code:
|
# ? Dec 2, 2009 13:21 |
|
The integers that cmd uses are too small to hold the result of that multiplication, so you got an unexpected result.
|
# ? Dec 2, 2009 14:41 |
|
3652425 * 2009 is significantly larger than 2^31, so it's overflowing and happening to end up negative.
|
# ? Dec 2, 2009 14:42 |
|
What are the definitions of API and protocol and how do they compare/contrast?
|
# ? Dec 2, 2009 17:19 |
|
An API is a programming interface to a system, and a protocol is a structured method of communication. On the surface they really don't have anything to do with each other despite what Z-Bo is saying in the DBMS thread:Z-Bo posted:The first rule of API design is that your API should be at least as expressive as your protocol. What is the "expressive power" of a protocol? Without clarification of what Z-Bo means by "protocol," it's a nonsense phrase. A protocol can be as simple as saying "I will send you plaintext data in lines ended by \r\n. When you see two \r\n's in a row you know I am done sending you data, then you can send me data in the same format." As for the expressiveness of an API, an API should expose methods to allow programmers to manipulate data in ways well-supported by the system in question and that's it. Now get this weird discussion back in the DBMS thread
|
# ? Dec 2, 2009 18:20 |
|
Plorkyeran posted:3652425 * 2009 is significantly larger than 2^31, so it's overflowing and happening to end up negative. Yeah, found it with some help here. Coupled with cmd not using decimals it's not worth the effort, I bodged it with a C# app. Incidentally: code:
if (DOW == Friday || Saturday || Sunday) Basically without the repetition, since I'm only checking one thing multiple times.
|
# ? Dec 2, 2009 18:40 |
|
BizarroAzrael posted:Yeah, found it with some help here. Coupled with cmd not using decimals it's not worth the effort, I bodged it with a C# app. According to http://msdn.microsoft.com/en-us/library/system.dayofweek(VS.71).aspx, DaysOfWeek is a normal enum, from 0-6. OR wouldn't work on that. If it were a bitfield enum, things would be golden. MS uses this exact situation in their example: http://msdn.microsoft.com/en-us/library/cc138362.aspx I forget how C# handles bitwise stuff, but you could be a bastard to the next guy by doing something like: code:
code:
|
# ? Dec 2, 2009 19:12 |
|
code:
|
# ? Dec 2, 2009 20:40 |
|
I'm putting together a little Access 2007 stuff for my employers, and they want to be able to generate a given report in letter format so that it can be printed and mailed to concerned parties. And no, using a mail merge to Word is not acceptable, apparently, they want the whole thing to stay in Access. Anyway, I was figuing I'd generate the report programmatically to get around formatting issues, setting up things like the body of the letter as one massive variable that binds to a textbox, with variables inserted where necessary, sorta like so: Private Sub Report_Load() Dim body as String body = "This letter is addressed to " & name & " regarding your current account status..." Me.BodyTextBox = body End Sub Only problem I'm having? Embarassingly enough, I can't seem to find a good resource to tell me how to get at my recordset programmatically. I have the data in a table, I know where it is, I can even create a recordset... but I'm not sure how to get the contents out of it. Everything I've been looking at is just advice on how to set the Recordsource property and let fields auto-generate. That's not my problem. I need to be able to assign variables, not just output stuff without being able to modify it. I do have one small advantage in that I'll only ever be addressing one record per letter, so I don't have to worry about stepping through an array. Can anyone help me out? Backhand fucked around with this message at 21:20 on Dec 2, 2009 |
# ? Dec 2, 2009 21:17 |
|
I am making a robot for Google Wave in Java, but I'm running into a small problem. After adding a few features that work, I wanted to add language translation functionality using Google's google-api-translate-java-0.91. My issue is that when I add the code to call the translation in the robot, it simply doesn't print anything to the wavelet at all. It printed fine before I added the translation code. Here is a simplified version of my code that I am using to get this to work. code:
|
# ? Dec 3, 2009 09:52 |
moved to proper thread
Harry fucked around with this message at 05:05 on Dec 4, 2009 |
|
# ? Dec 3, 2009 22:06 |
|
Okay, a couple of things: I'm building an application (in Java) which needs a command-line based menu interface and a GUI to perform the same functions. I'm therefore trying to abstract all the methods into a class to sit between the interface and the data so that either interface (along with any future interfaces) can do the same things with minimal logical code within the interface classes themselves. Does this sound sensible? It seems the most efficient way to do it. I have an add method to insert an object into a hash table. There's a chance that the key will already be in use and so I want to get the user's confirmation to overwrite the current contents. Should I: a) give the method a boolean return value or something and only ever call the add method with an if(add(x,y)){} with the return value determining whether a prompt should be shown? b) throw an exception and use a catch block to prompt the user dependent on interface type? I guess my understanding of when you should throw an exception versus a return type is a bit cloudy.
|
# ? Dec 4, 2009 17:14 |
|
Well these helpful folk in this thread have told me... Exceptions are exceptional. If this is a behavior you're likely to encounter, then it's not an exception (hence, go the try/boolean route). But if it's some weird crazy poo poo that you're practically never going to see but might see in a blue moon, then it is an exception. Or so I understand. Edit: The above partly motivated by the cost of exception handling, apparently?
|
# ? Dec 4, 2009 17:19 |
|
Triple Tech posted:Well these helpful folk in this thread have told me... Exceptions are exceptional. If this is a behavior you're likely to encounter, then it's not an exception (hence, go the try/boolean route). But if it's some weird crazy poo poo that you're practically never going to see but might see in a blue moon, then it is an exception. Well in python they're used often for plain old control flow, any iterator for example signals that its got no more things left to iterate by raising the StopIteration exception. I think in performance minded languages like C it makes more sense to use them as you describe.
|
# ? Dec 4, 2009 17:23 |
|
Triple Tech posted:Well these helpful folk in this thread have told me... Exceptions are exceptional. If this is a behavior you're likely to encounter, then it's not an exception (hence, go the try/boolean route). But if it's some weird crazy poo poo that you're practically never going to see but might see in a blue moon, then it is an exception. Great. Thanks for the advice. It makes sense how you describe it.
|
# ? Dec 4, 2009 17:35 |
|
Flamadiddle posted:I have an add method to insert an object into a hash table. There's a chance that the key will already be in use and so I want to get the user's confirmation to overwrite the current contents. Should I give the method a boolean return value or something and only ever call the add method with an if(add(x,y)){} with the return value determining whether a prompt should be shown? code:
code:
|
# ? Dec 4, 2009 17:45 |
|
Ahhh.. Okay. I wasn't sure if Java boolean ands short circuited if the first argument is false as in that first example, so I wouldn't have thought to implement it anything like that. Will have a go at something like the second example. Thanks for the advice.
|
# ? Dec 4, 2009 23:36 |
|
OCaml question: I'm trying to write a day 1 newbie module I can load into the interpreter or use later. (For learning.) Basically, I'm applying Heron's method of approximating square roots within an error. (0.01 here) But it doesn't work! After code:
code:
causticfluids fucked around with this message at 01:10 on Dec 5, 2009 |
# ? Dec 5, 2009 01:08 |
|
causticfluids posted:Anybody see anything? You're terminating when b (the root) is sufficiently close to a (the input).
|
# ? Dec 5, 2009 02:58 |
|
Yeah I screwed up the error checking. Works now!code:
causticfluids fucked around with this message at 03:05 on Dec 5, 2009 |
# ? Dec 5, 2009 03:00 |
|
A simpler, more idiomatic solution would be:code:
|
# ? Dec 5, 2009 03:14 |
|
hm i can move this post
Fast Luck fucked around with this message at 17:36 on Dec 5, 2009 |
# ? Dec 5, 2009 03:56 |
|
|
# ? May 16, 2024 10:06 |
|
edit: wrong thread
atb fucked around with this message at 08:12 on Dec 5, 2009 |
# ? Dec 5, 2009 06:34 |