The Geek Forum

  • April 27, 2024, 03:46:27 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Due to the prolific nature of these forums, poster aggression is advised.

*

Recent Forum Posts

Shout Box

Members
Stats
  • Total Posts: 129551
  • Total Topics: 7148
  • Online Today: 143
  • Online Ever: 1013
  • (January 12, 2023, 01:18:11 AM)

Author Topic: Detta! (Or anyone else mathamatical!)  (Read 4594 times)

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Detta! (Or anyone else mathamatical!)
« 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?
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #1 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.

Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Re: Detta! (Or anyone else mathamatical!)
« Reply #2 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.
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Re: Detta! (Or anyone else mathamatical!)
« Reply #3 on: December 03, 2009, 12:01:25 PM »


Thanks you btw :)
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

BizB

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +439/-15
  • Offline Offline
  • Gender: Male
  • Posts: 4324
  • Keep making circles
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #4 on: December 03, 2009, 12:15:47 PM »

Why wouldn't your algorithm stop at 3*288 and 4*288 (288 being the GCD)?
Logged
Without me, it's just 'aweso'.

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #5 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

Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

BizB

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +439/-15
  • Offline Offline
  • Gender: Male
  • Posts: 4324
  • Keep making circles
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #6 on: December 03, 2009, 02:20:31 PM »

Nice.
Logged
Without me, it's just 'aweso'.

pbsaurus

  • Hacker
  • ****
  • Coolio Points: +354/-31
  • Offline Offline
  • Gender: Male
  • Posts: 9981
  • Everyone Loves The King Of The Sea
    • View Profile
    • http://www.myspace.com/flipperpete
Re: Detta! (Or anyone else mathamatical!)
« Reply #7 on: December 03, 2009, 02:33:01 PM »

:clap:

Min

  • Nice Ex-Hackernetwork Moderator
  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +468/-13
  • Offline Offline
  • Gender: Female
  • Posts: 5970
  • Slacker Wiseass
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #8 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?
Logged
Flammable : Inflammable :: Duh : No Duh
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -ivan
1,180,463,441,680 Coolio Points

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #9 on: December 03, 2009, 06:40:50 PM »

Smarty bombalarty.
Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

xolik

  • King of the Geekery
  • Hacker
  • ****
  • Coolio Points: +541/-25
  • Offline Offline
  • Gender: Male
  • Posts: 5176
  • HAY GUYS
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #10 on: December 03, 2009, 06:54:35 PM »

Threads like these just remind me how mind bogglingly ignorant I am.
Logged
Barium: What you do if CPR fails.

=-=-=-=-=-=-=-=-=-=-=
[The Fade^C Compound]
-=-=-=-=-=-=-=-=-=-=-

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #11 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.

Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Re: Detta! (Or anyone else mathamatical!)
« Reply #12 on: December 04, 2009, 03:58:50 AM »


Ivan, Detta thanks I have it now. That's really useful! :)
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Re: Detta! (Or anyone else mathamatical!)
« Reply #13 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.
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #14 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?

Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Re: Detta! (Or anyone else mathamatical!)
« Reply #15 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.
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

pbsaurus

  • Hacker
  • ****
  • Coolio Points: +354/-31
  • Offline Offline
  • Gender: Male
  • Posts: 9981
  • Everyone Loves The King Of The Sea
    • View Profile
    • http://www.myspace.com/flipperpete
Re: Detta! (Or anyone else mathamatical!)
« Reply #16 on: December 04, 2009, 12:36:16 PM »

Oracle SQL is different too.

Chaulis

  • Jail Bait
  • *
  • Coolio Points: +10/-1
  • Offline Offline
  • Gender: Male
  • Posts: 126
    • View Profile
    • http://www.chaulis.com
Re: Detta! (Or anyone else mathamatical!)
« Reply #17 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.
Logged

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #18 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.
Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

Chaulis

  • Jail Bait
  • *
  • Coolio Points: +10/-1
  • Offline Offline
  • Gender: Male
  • Posts: 126
    • View Profile
    • http://www.chaulis.com
Re: Detta! (Or anyone else mathamatical!)
« Reply #19 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.
Logged

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #20 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.
« Last Edit: December 10, 2009, 05:46:21 PM by ivan »
Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

Clear_Runway

  • Wannabe Professional Blogger
  • **
  • Coolio Points: +85/-219
  • Offline Offline
  • Gender: Male
  • Posts: 559
  • Apparently sucks at IRC
    • View Profile
Re: Detta! (Or anyone else mathamatical!)
« Reply #21 on: December 10, 2009, 06:20:17 PM »

holy crap you guys are smart
Logged
"Scatman, fat man, black and white an brown man, tell me 'bout the color of your soul"
- RIP Scatman John

http://themanicnerd.blogspot.com/