• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 15:16
CET 21:16
KST 05:16
  • 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 Preview6RSL 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 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3
StarCraft 2
General
RSL Revival - 2025 Season Finals Preview Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Tenacious Turtle Tussle 2025 RSL Offline Finals Dates + Ticket Sales! Sparkling Tuna Cup - Weekly Open Tournament StarCraft2.fi 15th Anniversary Cup
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night
Brood War
General
[BSL21] RO8 Bracket & Prediction Contest BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle Let's talk about Metropolis
Tourneys
[ASL20] Grand Finals [BSL21] RO8 - Day 2 - Sunday 21:00 CET [BSL21] RO8 - Day 1 - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Fighting Spirit mining rates Current Meta
Other Games
General Games
Dawn of War IV Path of Exile Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026! Nintendo Switch Thread
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 Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread European Politico-economics QA Mega-thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
TL+ Announced Where to ask questions and add stream?
Blogs
How Sleep Deprivation Affect…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1927 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 States24745 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
BSL 21
20:00
Playoffs - Day 1
Sziky vs StRyKeR
Hawk vs Dewalt
ZZZero.O110
LiquipediaDiscussion
OSC
17:00
Masters Cup #150: Playoffs
Creator vs ByuNLIVE!
TBD vs Solar
davetesta67
Liquipedia
StarCraft2.fi
10:00
15V Cup / Offline Finals
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 391
White-Ra 308
Liquid`TLO 240
IndyStarCraft 155
JuggernautJason84
BRAT_OK 62
Nathanias 41
mouzStarbuck 8
StarCraft: Brood War
Britney 18829
Calm 2273
Shuttle 565
Dewaltoss 148
ZZZero.O 110
Rock 45
ajuk12(nOOB) 21
Bale 12
Shinee 7
Dota 2
qojqva3278
Dendi990
LuMiX1
Counter-Strike
fl0m8533
zeus418
Super Smash Bros
hungrybox151
Heroes of the Storm
Khaldor522
Liquid`Hasu363
Other Games
Grubby5365
FrodaN3391
Beastyqt862
KnowMe710
B2W.Neo492
DeMusliM89
Mew2King77
Trikslyr65
NarutO 24
ToD15
Organizations
Other Games
EGCTV1519
gamesdonequick1132
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• printf 28
• Kozan
• IndyKCrew
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• LaughNgamezSOOP
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Nemesis2325
Other Games
• Scarra1299
• imaqtpie1030
• WagamamaTV305
• Shiphtur226
• tFFMrPink 17
Upcoming Events
RSL Revival
8h 14m
Classic vs Reynor
herO vs Zoun
WardiTV 2025
16h 44m
herO vs ShoWTimE
SHIN vs herO
Clem vs herO
SHIN vs Clem
SHIN vs ShoWTimE
Clem vs ShoWTimE
IPSL
20h 44m
Sziky vs JDConan
BSL 21
23h 44m
Tech vs Cross
Bonyth vs eOnzErG
Replay Cast
1d 12h
Wardi Open
1d 15h
Monday Night Weeklies
1d 20h
Sparkling Tuna Cup
2 days
Replay Cast
4 days
The PondCast
4 days
[ Show More ]
CranKy Ducklings
6 days
SC Evo League
6 days
BSL 21
6 days
Liquipedia Results

Completed

Acropolis #4 - TS3
RSL Revival: Season 3
Kuram Kup

Ongoing

IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
Slon Tour Season 2
WardiTV 2025
RSL Offline Finals
META Madness #9
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
ESL Pro League S22

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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.