The Geek Forum

Main Forums => Homework Help => Topic started by: Probie on December 03, 2009, 07:26:52 AM

Title: Detta! (Or anyone else mathamatical!)
Post by: Probie on December 03, 2009, 07:26:52 AM

Hey, I'm trying to divide screen into squares for that i need to be able to divide 2 numbers by 2 different amounts which will equal a singluar value.

Working example

width of my screen 1152/16 = 72

height of my screeen 864/12 = 72

so i draw 16 squares 72 pixels wide across my screen and 12 square 72 pixels wide down my screen. Any ideas?
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: ivan on December 03, 2009, 11:09:52 AM
1152/x = a
864/y = b
a=b

At first glance, this is a system of 3 equations with 4 unknowns, which is not solvable with algebra. You can simplify it to 2 equations with 3 unknowns by using a for both a and b, but still no way to solve it.

If you're creating an algorythm to solve this, I would brute force it by iterating through possible solutions until a=b. That's what computers are good for.

Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Probie on December 03, 2009, 11:51:29 AM

Yeah I did this thing called best guess, or nearest fit or something...which isn't very programmable, but i guess brute force could work.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Probie on December 03, 2009, 12:01:25 PM

Thanks you btw :)
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: BizB on December 03, 2009, 12:15:47 PM
Why wouldn't your algorithm stop at 3*288 and 4*288 (288 being the GCD)?
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: ivan on December 03, 2009, 01:15:31 PM
The algorithm should keep going and give all values of x and y where a=b.

Like this little thingy I just did using SQL (because output is easy in SQL):

Code: [Select]
set nocount on

declare
@x numeric(6,2),
@y numeric(6,2),
@a numeric(12,6),
@b numeric(12,6),
@W numeric(6,2),
@H numeric(6,2),
@c integer

set @W = 1152
set @H = 864

set @x = 1
set @y = 1
set @c = 0

keepgoing:

set @c = @c + 1

if @x = @W begin goto XisMaxed end
if @y = @H begin goto YisMaxed end

set @a = @W / @x
set @b = @H / @y

if @a = @b and (@a * 1000000 = cast(@a as integer) * 1000000) begin
select 'Iteration ' + cast(cast(@c as int) as char(10)) + ': x = ' + cast(cast(@x as int) as char(10)) + ', y = ' + cast(cast(@y as int) as char(10)) + ', a = b = ' + cast(cast(@a as int)as char(5))
end

set @y = @y + 1

goto keepgoing

YisMaxed:

set @y = 1
set @x = @x + 1

goto keepgoing

XisMaxed:

select 'Total iterations: ' + cast(@c - 1 as char(10))


And the results:

Code: [Select]
-------------------------------------------------------------------
Iteration 2595      : x = 4         , y = 3         , a = b = 288 


-------------------------------------------------------------------
Iteration 6054      : x = 8         , y = 6         , a = b = 144 


-------------------------------------------------------------------
Iteration 9513      : x = 12        , y = 9         , a = b = 96   


-------------------------------------------------------------------
Iteration 12972     : x = 16        , y = 12        , a = b = 72   


-------------------------------------------------------------------
Iteration 19890     : x = 24        , y = 18        , a = b = 48   


-------------------------------------------------------------------
Iteration 26808     : x = 32        , y = 24        , a = b = 36   


-------------------------------------------------------------------
Iteration 30267     : x = 36        , y = 27        , a = b = 32   


-------------------------------------------------------------------
Iteration 40644     : x = 48        , y = 36        , a = b = 24   


-------------------------------------------------------------------
Iteration 54480     : x = 64        , y = 48        , a = b = 18   


-------------------------------------------------------------------
Iteration 61398     : x = 72        , y = 54        , a = b = 16   


-------------------------------------------------------------------
Iteration 82152     : x = 96        , y = 72        , a = b = 12   


-------------------------------------------------------------------
Iteration 109824    : x = 128       , y = 96        , a = b = 9   


-------------------------------------------------------------------
Iteration 123660    : x = 144       , y = 108       , a = b = 8   


-------------------------------------------------------------------
Iteration 165168    : x = 192       , y = 144       , a = b = 6   


-------------------------------------------------------------------
Iteration 248184    : x = 288       , y = 216       , a = b = 4   


-------------------------------------------------------------------
Iteration 331200    : x = 384       , y = 288       , a = b = 3   


-------------------------------------------------------------------
Iteration 497232    : x = 576       , y = 432       , a = b = 2   


----------------------------
Total iterations: 994464   


Where x is the number of squares horizontally, and y is the number of squares vertically, and a,b are the size of the square. So the largest grid is 4x3 squares at 288 pixels, and the smallest is 576x432 squares at 2 pixels.

Total execution time was 00:00:04

Title: Re: Detta! (Or anyone else mathamatical!)
Post by: BizB on December 03, 2009, 02:20:31 PM
Nice.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: pbsaurus on December 03, 2009, 02:33:01 PM
:clap:
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Min on December 03, 2009, 05:28:05 PM
1152/x = a
864/y = b
a=b

At first glance, this is a system of 3 equations with 4 unknowns, which is not solvable with algebra. You can simplify it to 2 equations with 3 unknowns by using a for both a and b, but still no way to solve it.

If you're creating an algorythm to solve this, I would brute force it by iterating through possible solutions until a=b. That's what computers are good for.



You guys lost me after this post.  Did you solve the problem?  If you did, just ignore all this...

The way I see it,
1152/x = a
864/y = b
a=b
like ivan said

Therefore
1152/x = a
864/y = a
like ivan said

Therefore
1152/x = a = 864/y

And by the transitive property of equality
1152/x = 864/y

Cross multiply, divide by 864 and reduce and I got
x= 4/3 y

So couldn't you just pick a y (that's divisible by 3) and see what x comes out to?
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: ivan on December 03, 2009, 06:40:50 PM
Smarty bombalarty.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: xolik on December 03, 2009, 06:54:35 PM
Threads like these just remind me how mind bogglingly ignorant I am.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: ivan on December 03, 2009, 07:19:36 PM

Cross multiply, divide by 864 and reduce and I got
x= 4/3 y

So couldn't you just pick a y (that's divisible by 3) and see what x comes out to?

Ok, there is another constraint: 1152 has to be evenly divisible by each x, and 864 has to be evenly divisible by each y. That's why, for instance, y = 15 does not work, even though 15 is divisible by 3.

Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Probie on December 04, 2009, 03:58:50 AM

Ivan, Detta thanks I have it now. That's really useful! :)
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Probie on December 04, 2009, 05:23:04 AM

Ivan, that's not all SQL is it? I've tried googling the syntax to see what the parameters are for the declaration of the variables and i can't place it.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: ivan on December 04, 2009, 10:02:23 AM
I dunno. I guess it's MS SQL, which might be different from ~//////////r e g u a l a r\\\\\\\\\\~ SQL. I never took a class or had formal training in either. Is it the notation for specifying numeric precision that's different?

Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Probie on December 04, 2009, 10:49:31 AM

I just didn't know you could do that sort of manipulation with sql. I'm just used to building relational databases with it. Even looked at multimedia but not that stuff.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: pbsaurus on December 04, 2009, 12:36:16 PM
Oracle SQL is different too.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Chaulis on December 09, 2009, 09:05:57 PM
What language were you originally planning on doing it in? It seems to me that using recursion with java, it wouldn't be all that hard. And you could call it when ever you wanted through out the program easily instead of rewriting the SQL every time you needed to calculate the answers.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: ivan on December 10, 2009, 12:31:54 AM
The language is irrelevant, because it's an iteration rather than a recursion. All languages can do iterations. Also, all languages can do recursions, although with some you have to jump through hoops. I originally composed this example in pseudo-code, but then realized I could quickly translate it into a basic SQL script, which happened to be the environment I was operating in at the time, which enabled me to quickly produce actual results.

I don't understand what you mean  by "rewriting the SQL every time you needed to calculate the answers". Seems to me the script I wrote provided all possible answers for the given screen resolution. If you mean for the script to give all answers for all possible screen resolutions, that's still an iteration rather that a recursion, just a longer one.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Chaulis on December 10, 2009, 08:38:03 AM
To caveat, I am not a great programmer or even a good one, I have to grab the book and reference it semi-often when coding. I know enough to know that I'm in the right ballpark, and to know that I don't know what to do and need help. The way I was conceptualizing it was Probie's question was related to a larger program, possibly one where she's designing something for output, and it would need specific data generated at certain points.

screenSizeDeducer(int height,int dividBy,int width, int dividBy2){
         figure out what the singular value is given two dimensions;
}

inputScSzDdVal{
 ask for height;
 ask for dividBy;
 ask for width;
 ask for dividBy2;
}

screenSizeDeducer();

If I understand the intent of recursion correctly, it's purpose is to tell the comp "here do this math and logic and give me the right answers with out me writing out the code to work out each case" And in the case of SQL, it's a procedural languange vs Java which is object oriented. So if later on in the SQL you needed to generate more results, you couldn't just call the same code, [ screenSizeDeducer(passed vars) ] You'd have to go back to that program that generated the solutions, or include it in ever program that would utilize the data. So my mind went there, and I was thinking ooo cool, I can play with some stuff and have real programmers tell me what I could have done to make it better, nifty! So yeah, yours definitely did iterate all possible vals, and I was just wondering if there were other ways of doing it with out having to, and where else could we go with it.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: ivan on December 10, 2009, 05:34:51 PM
Ok, I see what you're saying. I am actually the ignorant one here -- I have no idea how SQL works outside of my own narrow experience. I learned SQL in the context of the MS.NET environment. MS T-SQL code is organized into procedures that are stored and compiled on the SQL server, and executed on demand. Stored procs behave like functions that return data sets, and support local variables, recursion and actual in-line function calls. Also, the .NET development environment allows you to co-mingle any .NET language like C++, J++, Visual Basic, ASP and T-SQL. In my case, I use VB.NET for the user interface and T-SQL for data management. It's a beautiful world.

So in that environment, it doesn't matter which language I use for which function -- it just needs to work. However, you are right -- SQL is probably worse than useless to Probie.
Title: Re: Detta! (Or anyone else mathamatical!)
Post by: Clear_Runway on December 10, 2009, 06:20:17 PM
holy crap you guys are smart