Facebook Sign in | Join
Pushing database changes needn't be hard work with SQL Compare
Getting Started with Adobe After Effects - Part 6: Motion Blur
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.

TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

This challenge is related to Filling balls into boxes based on rules and preferences.


http://beyondrelational.com/puzzles/challenges/26/filling-balls-into-boxes-based-on-rules-and-preferences.aspx

Share

Comments

# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Monday, January 25, 2010 11:50 AM by Mike Lewis

Will there always be a record in the preferences table for every box and every ball?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Monday, January 25, 2010 12:55 PM by Ramireddy

Yes, There will be atleast one Preference for every box and ball...


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Tuesday, January 26, 2010 2:10 AM by Pragnesh Patel

As this challenge is Multi-statement solutions, can we create a physical/#table to derive output results.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Tuesday, January 26, 2010 6:23 AM by Jacob Sebastian

Yes, you can create #temp tables or table variables in this solution.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Wednesday, January 27, 2010 7:18 PM by Jesse Roberge

Hey I came up with a result that fits the preference table that is different from your 'expected result' but you said there is only supposed to be one correct solution.   Did I miss a rule?

Box Ball

Box 1 Ball 1

Box 3 Ball 2

Box 2 Ball 3

Box 5 Ball 4

Box 6 Ball 5

Box 4 Ball 6


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Wednesday, January 27, 2010 7:31 PM by Jesse Roberge

Here is an expanded view in the alternate match (with PreferenceIDs).

BoxID Box BallID Ball PreferenceID

1 Box 1 1 Ball 1 1

3 Box 3 2 Ball 2 4

2 Box 2 3 Ball 3 3

5 Box 5 4 Ball 4 12

6 Box 6 5 Ball 5 14

4 Box 4 6 Ball 6 11


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Wednesday, January 27, 2010 9:15 PM by Jesse Roberge

Oh duh!  The sort order didn't match.  The expected results are sorted by box but I sorted by Ball ID and got my boxes and balls mixed up.  Well that means it works!  I'm going to get it to work with a cartesian product preferences table now.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, January 28, 2010 8:05 AM by Bhavani

can we use the while loop to get the solution.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, January 28, 2010 8:13 AM by Jacob Sebastian

Yes. While loops are allowed in this challenge.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, January 28, 2010 10:16 AM by karinloos

As there is only 1 correct ball for a box and thus only 1 correct solution, can we assume that there will be no logic testing for "funny data"..

Ie if you have a working solution on the given sample set, it will thus work on all sets as the only difference can be in the size of the set?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, January 28, 2010 11:20 AM by Jacob Sebastian

@karinloos,

your assumption is right. The tricky testing will be done with more data, but it will certainly follow the rules given in the challenge. There will be only one correct solution.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, January 28, 2010 10:03 PM by sreedharange

I've got the solution, but now how do I submit it?  Maybe it is obvious to others, but I am new to this site (joined today); finding the solution was much easier than finding out how to submit my solution :)


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, January 29, 2010 12:27 AM by Jacob Sebastian

@sreedharange,

It looks like you did not pay attention to the 'notes' section. Take a look at the 'submission guidelines' page where you can get clear instructions on how to submit your solution.

beyondrelational.com/.../tsql-challenges-terms-and-conditions-submission-guidelines-evaluation-process-and-faq.aspx


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, January 29, 2010 9:19 AM by dishdy

In question 8 above you state that you cannot create your own tally table.

1. Why not?

2. Is this something new starting with this challeng or has this always been the rule?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, January 29, 2010 9:35 AM by Jacob Sebastian

@dishdy,

Tally table was never allowed, except for master..spt_values which has only a limited number of rows.

Recently we made a tally table available that you can use in your solutions. The script for this tally table is given at databasechallenges.com/.../tally-table

This tally table will be present in the database that we use for evaluating your solutions. So if you want to use a tally table, use only this script.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, January 29, 2010 10:21 AM by dishdy

Jacob,

So you are saying a sub-query in your solution with a series of cross-joins to generate a tally table 'on the fly' is NOT permitted?

Or are you saying that you cannot generate a physical table (temporary or not) that acts as a tally table?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, January 29, 2010 10:47 AM by Jacob Sebastian

@dishdy,

I was refering to physical tables.

You can build your own tally table on-the-fly if you wish to do so.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, January 29, 2010 10:49 AM by Jacob Sebastian

Again, since this challenge allows multi-statement queries, loops etc, you are also permitted to use table variables or #temp tables.

(this is specifically for this challenge).

However, make sure that we will be able to embed your code within the body of a stored procedure (as explained in the description)


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Monday, February 01, 2010 2:19 PM by SparkS

I got an error when running the stored procedure creating script:

Msg 102, Level 15, State 1, Procedure TC_Eval, Line 7

Incorrect syntax near ';'.

If I remove the ';' after GO, it works.

Did I miss something. Thanks.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Monday, February 01, 2010 2:50 PM by Brad Schulz

That should be changed.

GO is not an actual T-SQL command... it's just a batch-end indicator/separator.  It should never have a semi-colon after it.

Jacob or Ramireddy, can you change that and get rid of the semicolon?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Monday, February 01, 2010 9:33 PM by Jacob Sebastian

Corrected the typo.

Thanks for pointing it out.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Tuesday, February 02, 2010 2:19 AM by dishdy

Jacob,

The 'Read More' links for 22 links to 21.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Tuesday, February 02, 2010 2:30 AM by Jacob Sebastian

corrected!

thanks


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Wednesday, February 17, 2010 10:42 AM by Len Binns

When will the results be posted?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Wednesday, February 17, 2010 11:59 AM by Jacob Sebastian

@Len,

I think it will be another 2-3 weeks. We are clearing the backlogs currently.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Tuesday, June 08, 2010 10:06 AM by Sergejack

tsqlc_Tally?

Where is it?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Tuesday, June 08, 2010 10:31 AM by Jacob Sebastian

# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, June 11, 2010 10:18 AM by Sergejack

Solutions cannot be seen (Page Requests fail).


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, June 11, 2010 10:25 AM by Jacob Sebastian

is there a specific page that fails? can you post the URL?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, June 11, 2010 10:32 AM by Jacob Sebastian

Ok guys, found that there is a technical glitch. The solutions are not visible yet. It is going to take some time to fix that. this will be available by monday morning.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, June 11, 2010 10:34 AM by Jacob Sebastian

wait a second..looks like a URL problem. Let me correct it.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Friday, June 11, 2010 10:43 AM by Jacob Sebastian

OK, it is fixed. Does it look good now?


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Wednesday, June 16, 2010 7:14 AM by Sergejack

It does.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, June 17, 2010 9:13 AM by Pragnesh Patel

Hi Jacob,

I am very much confused by the winners list for this challenge....

I tried to execute the couple of solutions from winner list with Load testing data provided and here is the list of what each solutions take time to executive.

Solution -----------> Execution Time

Top winner ( carlos benito ) --------> 1.44 minutes

Runner Up ( Jesse Roberge ) -----> 1.23 minutes

...

...

2nd Last winner ( jmc bkk  ) -------------> 0.01 Minutes

Last winner ( Michael Lewis  ) -------------> 0.00 Minutes

Can you please help me out what criteria applies to identify the winners.

-Pragnesh


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, June 17, 2010 9:34 AM by Jacob Sebastian

@Pragnesh,

The winners are identified based on the read, write, CPU, duration rank as per given on databasechallenges.com/.../load_testing_results. Each solution is executed 5 times and the average of the stats is collected. You can click on the hyper link given on the stats page to see the execution statistics of each of the 5 runs.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, June 17, 2010 10:29 AM by Pragnesh Patel

Jacob,

I understand with read, write, CPU, duration rank.

But you can see the execution time difference... its a very huge.

In real world scenario any query takes 1.44 minutes to execution is always not acceptable by anyone.

I am still not clear with the weightage given to read, write, CPU, duration rank.


# re: TSQL Challenge 22 - Filling balls into boxes based on rules and preferences

Thursday, June 17, 2010 12:47 PM by Jacob Sebastian

@Pragnesh,

You are refering to the execution time the solution took on your computer. I have no idea why it takes on your side. We run all the solutions in similar environment and the results are captured. Take a look at our stats and you will realize that the solutions are correctly ranked.

We periodically re-run the load testing. So let us wait for the next load testing and see if the statistics will change or not.

rgds

Jacob


Copyright © Rivera Informatic Private Ltd.