• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:27
CET 14:27
KST 22:27
  • 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 weeklies2ComeBackTV's documentary on Byun's Career !10Weekly 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
Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies ComeBackTV's documentary on Byun's Career ! Micro Lags When Playing SC2? When will we find out if there are more tournament Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win
Tourneys
$5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament $100 Prize Pool - Winter Warp Gate Masters Showdow Winter Warp Gate Amateur Showdown #1 RSL Offline Finals Info - Dec 13 and 14!
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
Anyone remember me from 2000s Bnet EAST server? soO on: FanTaSy's Potential Return to StarCraft BGH Auto Balance -> http://bghmmr.eu/ Klaucher discontinued / in-game color settings How Rain Became ProGamer in Just 3 Months
Tourneys
[BSL21] LB QuarterFinals - Sunday 21:00 CET Small VOD Thread 2.0 [Megathread] Daily Proleagues [BSL21] WB SEMIFINALS - Saturday 21:00 CET
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Current Meta Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Beyond All Reason Path of Exile General RTS Discussion 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 The Games Industry And ATVI Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
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
The (Hidden) Drug Problem in…
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: 1411 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 States24749 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 22h 34m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko510
SC2Nice 35
DivinesiaTV 2
StarCraft: Brood War
Sea 10280
Horang2 1447
EffOrt 736
ZerO 446
Mini 365
firebathero 358
actioN 355
Rush 227
Sharp 194
Soma 176
[ Show more ]
ggaemo 155
Light 143
Snow 122
Hyun 115
Mind 83
Killer 78
Barracks 74
hero 71
Pusan 70
soO 49
Yoon 46
Movie 44
ToSsGirL 43
Terrorterran 28
HiyA 17
sorry 16
910 14
ajuk12(nOOB) 12
Noble 12
scan(afreeca) 10
Dota 2
XcaliburYe261
League of Legends
C9.Mang0317
Counter-Strike
olofmeister2791
x6flipin1067
byalli926
zeus649
edward73
Other Games
Fuzer 362
Pyrionflax336
Livibee129
oskar119
hiko112
ArmadaUGS84
Mew2King65
QueenE59
XaKoH 40
nookyyy 39
Trikslyr26
ZerO(Twitch)12
Organizations
StarCraft: Brood War
UltimateBattle 1435
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV627
• Noizen48
League of Legends
• Jankos4233
Upcoming Events
WardiTV Invitational
22h 34m
Gerald vs YoungYakov
Spirit vs MaNa
SHIN vs Percival
Creator vs Scarlett
Replay Cast
1d 19h
WardiTV Invitational
1d 22h
ByuN vs Solar
Clem vs Classic
Cure vs herO
Reynor vs MaxPax
Replay Cast
3 days
Sparkling Tuna Cup
4 days
Krystianer vs TBD
TriGGeR vs SKillous
Percival vs TBD
ByuN vs Nicoract
Replay Cast
5 days
Wardi Open
5 days
Liquipedia Results

Completed

YSL S2
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
BSL Season 21
Slon Tour Season 2
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
ESL Pro League S22

Upcoming

CSL 2025 WINTER (S19)
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.