• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:46
CEST 04:46
KST 11:46
  • 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
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Chinese SC2 server to reopen; live all-star event in Hangzhou17Weekly Cups (Oct 13-19): Clem Goes for Four2BSL Team A vs Koreans - Sat-Sun 16:00 CET7Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)81
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8) Weekly Cups (Oct 13-19): Clem Goes for Four Chinese SC2 server to reopen; live all-star event in Hangzhou Weekly Cups (March 17-23): Clem Bounces Back
Tourneys
Tenacious Turtle Tussle RSL Season 3 Qualifier Links and Dates $1,200 WardiTV October (Oct 21st-31st) SC2's Safe House 2 - October 18 & 19 INu's Battles #13 - ByuN vs Zoun
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers
Brood War
General
SnOw's Awful Building Placements vs barracks BSL Team A vs Koreans - Sat-Sun 16:00 CET Is there anyway to get a private coach? BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion
Tourneys
[Megathread] Daily Proleagues 300$ 3D!Community Brood War Super Cup #4 [ASL20] Semifinal B Azhi's Colosseum - Anonymous Tournament
Strategy
BW - ajfirecracker Strategy & Training Current Meta Roaring Currents ASL final [I] Funny Protoss Builds/Strategies
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Dawn of War IV ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine The Chess Thread Russo-Ukrainian War Thread Men's Fashion Thread
Fan Clubs
The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Series you have seen recently... [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Sabrina was soooo lame on S…
Peanutsc
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1834 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 States24720 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
Tenacious Turtle Tussle
23:00
Biweekly #34
LiquipediaDiscussion
OSC
16:00
Masters Cup #150 Qual 1-2
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nathanias 126
ProTech106
NeuroSwarm 101
StarCraft: Brood War
Artosis 695
Noble 13
Purpose 9
Icarus 7
KwarK 6
Dota 2
monkeys_forever691
LuMiX1
League of Legends
JimRising 762
Super Smash Bros
hungrybox679
Other Games
summit1g7890
C9.Mang0261
PiGStarcraft249
WinterStarcraft189
Maynarde119
ViBE114
Trikslyr59
Organizations
Other Games
gamesdonequick1188
Counter-Strike
PGL122
Other Games
BasetradeTV97
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Hupsaiya 78
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki9
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift4917
Upcoming Events
The PondCast
7h 14m
OSC
9h 14m
WardiTV Invitational
1d 8h
Online Event
1d 13h
RSL Revival
1d 23h
RSL Revival
2 days
WardiTV Invitational
2 days
Afreeca Starleague
3 days
Snow vs Soma
Sparkling Tuna Cup
3 days
WardiTV Invitational
3 days
[ Show More ]
CrankTV Team League
3 days
RSL Revival
3 days
Wardi Open
4 days
CrankTV Team League
4 days
Replay Cast
5 days
WardiTV Invitational
5 days
CrankTV Team League
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 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.