Open Side Menu Go to the Top

07-03-2012 , 10:55 PM
Quote:
Originally Posted by Fubster
i want to take the top book off my stack of books and put it into one of these shelves randomly, based on how much space is available in each shelf. i want to do it in such a way that you'd take the total unused space in each shelf and divide it by the total unused space in all the shelves, and that gives you the probability of putting the book in the next shelf.
Put all the empty spaces in one big bucket and pick one out at random. Here's a snippet.

Code:
#include <vector>

struct Shelf;
struct Book;

struct Slot
{
	Shelf* shelf;
	Book* book;
	int location;
};

std::vector<Slot*> emptySlots;
std::vector<Slot*> occupiedSlots;

Slot* GetRandomSlot()
{
	int ix = rand() % emptySlots.size();
	Slot* slot = emptySlots[ix];
}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
07-04-2012 , 12:07 AM
Quote:
Originally Posted by fluorescenthippo
So I just had a successful phone interview for a programming and finance internship, which is possibly my ideal job. The job called for "excellent" programming skills in Java/C++ or Python. I have about 5 weeks worth in Python.

Thoughts on how to improve the quickest the next two weeks? The job involves sorting data from Quickbooks. He asked if I knew GUIs (I don't) or if I had experience with the Python something package. Something being a word that sounded like decimal.

I pretty much have two weeks straight to learn so I'm just looking where to start.
The reason he asked about is that, well, assuming the guy knows nothing at all about programming (jee, wonder why?), somewhere along the line he must have seen something about Decimal and everyone got stuck there.

Since you're data sorting, try downloading postresql and the python postresql driver package. Once you've figured out how to set up a database and bulkload a csv, you can then skip all the normalization and relational algebra and dive right into doing select queries.

Code:
import postresql

## put your postgresql boiler plate here

myQueue = ('''select id, moneys from....''')

print(myQueue)
which will output something like this:

Code:
[('id101', Decimal(1000.00), ('id102', Decimal(9999.99)]
So, someone somewhere saw Decimal and immediately thought about Decimal package, and this, in my experience, hasn't been needed because once you unwrap the tuples, you end up with normal ol' numbers and stuff.

So, yeah, you may want to look into the aforementioned packages as well.

Just trying to think of how this interview went:

Hello, you know Python?

Yes. I did a few weeks of MIT open course but I didn't understand the whole thing about OOP.

Oh, MIT? ****, you're more qualified for this job than a BS from the local community college! You know how to run a GUI?

A what?

Perfect.

You know anything about Decimals?

Been working on decimals since second grade!

WOW!!!!! How's your Java?

Static public main void, right?

Yep. Can you send over a "hello world" program in Python?

Uhm, yeah.

I was just kidding. We need someone smarter than that. Can you send a program that prints "hello Jim?"

That'll take me a while...

Great. Can you start in two weeks!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 12:14 AM
Quote:
Originally Posted by Chips Ahoy
Put all the empty spaces in one big bucket and pick one out at random. Here's a snippet.

Code:
#include <vector>

struct Shelf;
struct Book;

struct Slot
{
	Shelf* shelf;
	Book* book;
	int location;
};

std::vector<Slot*> emptySlots;
std::vector<Slot*> occupiedSlots;

Slot* GetRandomSlot()
{
	int ix = rand() % emptySlots.size();
	Slot* slot = emptySlots[ix];
}
oh yeah, i should mention that i don't know how to use vectors or pointers. basically i have taken an intro to C++ class.

i was thinking of using structs though, makes sense
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 12:16 AM
putting all the empty spaces into a big bucket does seem to make sense, though. that would reasonably replicate the concept of "randomized based on available space," yes?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 12:28 AM
Quote:
Originally Posted by Fubster
oh yeah, i should mention that i don't know how to use vectors
these are just arrays that grow as you add items.

Quote:
or pointers.
uh, yeah. you will never understand c or c++ until you understand pointers. get to work on this.

Quote:
Originally Posted by Fubster
putting all the empty spaces into a big bucket does seem to make sense, though. that would reasonably replicate the concept of "randomized based on available space," yes?
depends how you take them out of the bucket.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 01:14 AM
Give each space a number, from 0 to whatever, generate a random number between 0 and whatever, check if there is a book there, if so goto generating a number again. Eventually all the books are on the shelves.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 01:24 AM
Things that can loop forever scare me, even if the odds of them actually doing it are 0%. You might prefer choosing only from the remaining available spaces, e.g. by storing a vector with the remaining possible indices and generating a random number from 0 to len(vector) - 1.

You can also use one of the many ways to generate a random permutation--either through your own code or by calling a library function. I think the C++ standard lib even has a shuffle function.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 01:36 AM
Couldn't you just randomize a list of slots and pull them off a stack one at a time? Do all the randomization at start up instead of during the run.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 02:25 AM
Quote:
Originally Posted by tyler_cracker
these are just arrays that grow as you add items.



uh, yeah. you will never understand c or c++ until you understand pointers. get to work on this.



depends how you take them out of the bucket.
yeah, i'm working on it. i'm teaching myself as i go, but since this seemed like a fairly simple thing to do, i wanted to go ahead and finish it for my friend without having to spend a lot of time teaching myself concepts that aren't exactly necessary for implementing something that will probably won't actually be used for anything that's even remotely interesting or important. i'd rather just get it done as soon as i can so i can get on with more interesting stuff (actually learning C/C++).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 02:28 AM
Quote:
Originally Posted by kerowo
Couldn't you just randomize a list of slots and pull them off a stack one at a time? Do all the randomization at start up instead of during the run.
wouldn't you have to reanalyze the available space allocated to each bookshelf every time you add a book in order to make the sorting algorithm work?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 02:39 AM
Quote:
Originally Posted by NoahSD
Things that can loop forever scare me, even if the odds of them actually doing it are 0%. You might prefer choosing only from the remaining available spaces, e.g. by storing a vector with the remaining possible indices and generating a random number from 0 to len(vector) - 1.

You can also use one of the many ways to generate a random permutation--either through your own code or by calling a library function. I think the C++ standard lib even has a shuffle function.
my original plan was to allocate each bookshelf a chunk of numbers between 0 and 1000 that corresponds with the probability of each shelf getting the next book, then doing something like s = rand() % 1000 and whatever chunk of numbers s is a part of gets the book. that seems to make sense, right?

i'm still feeling my way around this sort of thing, so let me know if i'm way off the mark here.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 04:00 AM
Quote:
Originally Posted by NoahSD
Things that can loop forever scare me, even if the odds of them actually doing it are 0%.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 08:08 AM
Quote:
Originally Posted by Fubster
my original plan was to allocate each bookshelf a chunk of numbers between 0 and 1000 that corresponds with the probability of each shelf getting the next book, then doing something like s = rand() % 1000 and whatever chunk of numbers s is a part of gets the book. that seems to make sense, right?

i'm still feeling my way around this sort of thing, so let me know if i'm way off the mark here.
http://en.wikipedia.org/wiki/Selecti...c_algorithm%29

Search for "Biased roulette wheel selection" or "Fitness proportionate selection" to find a better page if you don't understand the algorithm from that page. There are clever algorithms to do it more efficiently if you need them later (search for "Sampling from a discrete distribution", etc) but that's the basic method you need.

Juk
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 09:48 AM
Quote:
Originally Posted by Fubster
wouldn't you have to reanalyze the available space allocated to each bookshelf every time you add a book in order to make the sorting algorithm work?
Not if you persist the stack of addresses. It would get complicated if you started taking books off of the shelves and needed to return their address to the stack.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 10:20 AM
Quote:
Originally Posted by clowntable
Dude.. I never knew what Turing looked like until now. Not at all what I expected for some reason.

So, like, why the picture of Turing?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 10:35 AM
Stuff that loops forever, halting problem etc
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 01:48 PM
I like infinite loops xD. Speaking of which.... if anyone has made a jump point search algorithm that always finds optimal paths (unlike mine...) I'd love to take a look
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 03:27 PM
I haven't written one myself, but there are a lot of examples lying around on the internet. I'm sure you'll be able to find source code, as well as some visualizations of what's happening, etc.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 03:41 PM
Quote:
Originally Posted by NoahSD
I haven't written one myself, but there are a lot of examples lying around on the internet. I'm sure you'll be able to find source code, as well as some visualizations of what's happening, etc.
I have found a total of four examples online and have them all bookmarked. All four of which however seem to be in a competition to create the most incomprehensible/unreadable code imaginable.

edit: Fwiw, one is in C, one in Java, one in June (or some language iv never heard of) and the main authors program is written in C++ and contains well over 100 classes.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 04:07 PM
Quote:
Originally Posted by jukofyork
http://en.wikipedia.org/wiki/Selecti...c_algorithm%29

Search for "Biased roulette wheel selection" or "Fitness proportionate selection" to find a better page if you don't understand the algorithm from that page. There are clever algorithms to do it more efficiently if you need them later (search for "Sampling from a discrete distribution", etc) but that's the basic method you need.

Juk
oh cool, thanks. new strategy: not gonna finish this and instead read up on a bunch of cool concepts and hope he forgets about it (likely).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 04:24 PM
Jeez.. I guess jump-point search is way more complicated than I thought it was.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 04:35 PM
Quote:
Originally Posted by NoahSD
Jeez.. I guess jump-point search is way more complicated than I thought it was.
The only part that is confusing me is when to break the recursion. I understand why you have to do recursion up and right first before you can continue in a up-right recursion, but things like "if added end tile to open list, break and draw final path" are leading to me getting non-optimal paths in some cases and the paper doesn't talk about details like that.

This is the program by the authors of the paper though:
http://ddh.googlecode.com/svn/tags/gppc12/
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 04:48 PM
Hopefully someone who knows wtf they're talking about will step in, but is it possible that you just have a simple bug?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 04:54 PM
Quote:
Originally Posted by NoahSD
Hopefully someone who knows wtf they're talking about will step in, but is it possible that you just have a simple bug?
Sounds to me like you found the subject for your next nerd blog...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-04-2012 , 08:45 PM
Coming from C#, I just started Objective-C ( yeah, apps, i know i suck ) and man does it feel terrible. C# is just so awesome and fluid imho.

I have no clue what the general consensus is, but I find that language so mother****ing old and mechanical.....

**** you apple.

On a side note, I would pick up Java, but the google store is made by morons that think that I like filing taxes in all the countries I sell apps in, so they can go **** themselves. The hell are these morons doing with my 30% ?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m