• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:48
CET 09:48
KST 17:48
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies3ComeBackTV's documentary on Byun's Career !11Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win4Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2
StarCraft 2
General
ComeBackTV's documentary on Byun's Career ! Team TLMC #5: Winners Announced! What's the best tug of war? The Grack before Christmas Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies
Tourneys
OSC Season 13 World Championship $5,000+ WardiTV 2025 Championship $100 Prize Pool - Winter Warp Gate Masters Showdow Sparkling Tuna Cup - Weekly Open Tournament Winter Warp Gate Amateur Showdown #1
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 505 Rise From Ashes Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement
Brood War
General
BW General Discussion How soO Began His ProGaming Dreams Klaucher discontinued / in-game color settings BGH Auto Balance -> http://bghmmr.eu/ Recommended FPV games (post-KeSPA)
Tourneys
[Megathread] Daily Proleagues [BSL21] LB SemiFinals - Saturday 21:00 CET [BSL21] WB & LB Finals - Sunday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Current Meta Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Mechabellum Stormgate/Frost Giant Megathread Beyond All Reason Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread 12 Days of Starcraft The Games Industry And ATVI Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced Where to ask questions and add stream?
Blogs
National Diversity: A Challe…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1821 users

Math Problem

Blogs > FFGenerations
Post a Reply
FFGenerations
Profile Blog Joined April 2011
7088 Posts
April 18 2015 20:02 GMT
#1
I wonder if anyone out there would like to try out this Math Problem.

I have a 2D grid of boxes. The grid can go 4 boxes wide and infinite boxes deep, but the box fills width-wise first and we only want it to be as deep as it has to be.

For a number n of boxes in the grid, how many boxes deep does the grid need to be?


Some people suggested that I use

gridDepth = (numberOfBoxes+4)/4


However I'll show you the problem it causes.........

2 boxes is fine

[image loading]

3 boxes we suddenly leap down and have an unused row

[image loading]

6 boxes we're looking better again

[image loading]

But then back to jumping to the next row prematurely.......

[image loading]


Now I know nothing about math so I thought maybe you guys could take a look :/

Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
micronesia
Profile Blog Joined July 2006
United States24750 Posts
April 18 2015 20:10 GMT
#2
So you need 1 row for 1,2,3,4 boxes; you need 2 rows for 5,6,7,8 boxes, 3 rows for 9,10,11,12 boxes, etc. In other words:

1 --> 1
2 --> 1
3 --> 1
4 --> 1
5 --> 2
6 --> 2
7 --> 2
8 --> 2
9 --> 3
etc

What happens if we divide the number of boxes by the number of boxes per row? We should get rows:

1 --> 1/4
2 --> 1/2
3 --> 3/4
4 --> 1 (correct)
5 --> 5/4
6 --> 3/2
7 --> 7/2
8 --> 2 (correct)
9 --> 9/4

It looks like you can say #rows = ceiling(#boxes/4).
ModeratorThere are animal crackers for people and there are people crackers for animals.
The_Templar
Profile Blog Joined January 2011
your Country52797 Posts
April 18 2015 20:29 GMT
#3
Yeah, all you need for this is the floor/ceiling function instead of rounding to the nearest integer. If you can't do that you could just add two instead of four in your original equation, couldn't you?
Moderatorshe/her
TL+ Member
KingAlphard
Profile Blog Joined August 2012
Italy1705 Posts
Last Edited: 2015-04-18 20:36:39
April 18 2015 20:29 GMT
#4
The grid should have a depth that's an integer number. But I'm confused because, with n=3 the formula returns 7/4, and the grid is 2 boxes deep, so you would guess that rational numbers get rounded upwards.
Instead with n=6 the formula returns 10/4 = 2.5 but it's 2 boxes deep and not 3.

Besides try this formula that already returns the correct integer values:

f(n) = ( n + 3 - [ (n-1) mod 4 ] ) /4

n ; f(n)
0; (0+3-3)/4 = 0
1; (1+3-0)/4 = 1
2; (2+3-1)/4 = 1
3; (3+3-2)/4 = 1
4; (4+3-3)/4 = 1
5; (5+3-0)/4 = 2
6; (6+3-1)/4 = 2
7; (7+3-2)/4 = 2
8; (8+3-3)/4 = 2
9; (9+3-0)/4 = 3

etc.etc.
endy
Profile Blog Joined May 2009
Switzerland8970 Posts
Last Edited: 2015-04-18 20:36:21
April 18 2015 20:35 GMT
#5
I faced the same problem when I needed to return the quarter from a month number, and micronesia is right, I used the CEILING function in SQL.
ॐ
FFGenerations
Profile Blog Joined April 2011
7088 Posts
April 18 2015 21:28 GMT
#6
hey guys, nice responses, thanks ever so much.
someone has written me an answer here but i'm too stupid to figure out what he means to do with it
http://stackoverflow.com/questions/29722589/math-fomrula-for-populating-a-grid-with-boxes

also i'm literally hallucinating from coding nonstop, its pretty scarey
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
HaRuHi
Profile Blog Joined November 2010
1220 Posts
Last Edited: 2015-04-18 22:13:57
April 18 2015 22:06 GMT
#7
for(String imageURL : imageURLs){

URL url = new URL(imageURL);

BufferedImage bi = ImageIO.read(url);
g.drawImage(bi, x, y, w, h, null);

x += 150;

here you increase x , and therefore with the if y aswell, wether or not another image has to be drawn, your loop logic is faulty, it might be enough to write x+= 150 at the end of the loop, after the if. edit: I think you acutally have to put it in an else

if(x >= result.getWidth()){
x = 0;
y += 200;
}

}

for(String imageURL : imageURLs){

URL url = new URL(imageURL);

BufferedImage bi = ImageIO.read(url);
g.drawImage(bi, x, y, w, h, null);

if(x >= result.getWidth()){
x = 0;
y += 200;
}else x += 150;

}
Maybe?
FFGenerations
Profile Blog Joined April 2011
7088 Posts
April 18 2015 22:20 GMT
#8
the problem with that (i think) is that the grid is drawn before everything else and set in stone, then the boxes come after
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
FFGenerations
Profile Blog Joined April 2011
7088 Posts
Last Edited: 2015-04-18 22:30:09
April 18 2015 22:27 GMT
#9
OH YEAH WHOS THE MATHS GENIUS WHOS SO TIRED HES SEEING SPIDERS AND SHIT EVERYWHERE

int totalHeight = ((int) Math.ceil(((double)numberOfBoxes-1)/4))*200;

DAT -1 BABY
the power of elimination <- what the fuck is that term i can never fucking remember it

love it when i go to write my report and im like "yeah i totally asked someone for help and then put this -1 in there 5 hours later"
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
HaRuHi
Profile Blog Joined November 2010
1220 Posts
Last Edited: 2015-04-18 22:47:48
April 18 2015 22:45 GMT
#10
Yeah, that would make a lot more sense^^. Other than that, this is defnitly a code-problem (not really math related), there is a big programming thread here on TL aswell.

edit: GZ^^
Cyx.
Profile Joined November 2010
Canada806 Posts
April 19 2015 00:08 GMT
#11
On April 19 2015 07:45 HaRuHi wrote:
Yeah, that would make a lot more sense^^. Other than that, this is defnitly a code-problem (not really math related), there is a big programming thread here on TL aswell.

edit: GZ^^

haha he's been spamming the programming thread with this shit for like a week now
FFGenerations
Profile Blog Joined April 2011
7088 Posts
Last Edited: 2015-04-19 16:12:53
April 19 2015 01:07 GMT
#12
speaking of which i am stuck again sitting here for an hour not knowing what to do about it completely mystified and at a loss

ive just got today now to connect the (working) imageuploader to the (working) image generator but suddenly even the simplest test function doesnt work when i put it on the spot where i want it to go

fixed (probably), need to call from a control function
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
JieXian
Profile Blog Joined August 2008
Malaysia4677 Posts
April 20 2015 04:04 GMT
#13
homework thread disguised as a "math problem"

ahhh programming (along with several similar fields) can be so frustrating because there's an honest feedback loop and you can NOT be deluded into thinking you are great. If it doesn't work, it doesn't.

As compared to certain fields... "oh you don't like it because you just don't get it. Your opinion is subjective."

good luck
Please send me a PM of any song you like that I most probably never heard of! I am looking for people to chat about writing and producing music | https://www.youtube.com/watch?v=noD-bsOcxuU |
Please log in or register to reply.
Live Events Refresh
Next event in 1h 12m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft741
StarCraft: Brood War
Larva 617
Stork 506
Mong 371
Jaedong 150
Shuttle 137
Sharp 120
sorry 92
Sacsri 75
NotJumperer 29
ToSsGirL 27
[ Show more ]
JulyZerg 7
NaDa 6
eros_byul 0
Dota 2
NeuroSwarm145
League of Legends
JimRising 629
C9.Mang0459
Counter-Strike
summit1g8222
minikerr59
Other Games
mouzStarbuck293
Happy215
XaKoH 166
trigger8
Organizations
Other Games
gamesdonequick882
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 11 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1748
Upcoming Events
Sparkling Tuna Cup
1h 12m
Krystianer vs Classic
TriGGeR vs SKillous
Percival vs Ryung
ByuN vs Nicoract
OSC
9h 12m
BSL 21
11h 12m
Cross vs Dewalt
Replay Cast
1d
Wardi Open
1d 3h
OSC
2 days
Solar vs MaxPax
ByuN vs Krystianer
Spirit vs TBD
OSC
5 days
Korean StarCraft League
5 days
OSC
6 days
OSC
6 days
Liquipedia Results

Completed

Escore Tournament S1: W1
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL Season 21
CSL Season 19: Qualifier 2
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1: W2
Escore Tournament S1: W3
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
OSC Championship Season 13
Nations Cup 2026
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.