• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 08:48
CEST 14:48
KST 21: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
[ASL20] Ro24 Preview Pt2: Take-Off6[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax3Maestros of The Game—$20k event w/ live finals in Paris30Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
What mix of new and old maps do you want in the next 1v1 ladder pool? (SC2) : A Eulogy for the Six Pool Geoff 'iNcontroL' Robinson has passed away Weekly Cups (Aug 18-24): herO dethrones MaxPax 2v2 & SC: Evo Complete: Weekend Double Feature
Tourneys
WardiTV Mondays Maestros of The Game—$20k event w/ live finals in Paris RSL: Revival, a new crowdfunded tournament series Sparkling Tuna Cup - Weekly Open Tournament Monday Nights Weeklies
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
Flash On His 2010 "God" Form, Mind Games, vs JD BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ro24 Preview Pt2: Take-Off BW General Discussion No Rain in ASL20?
Tourneys
[ASL20] Ro24 Group E [Megathread] Daily Proleagues [ASL20] Ro24 Group D [ASL20] Ro24 Group B
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
General RTS Discussion Thread Nintendo Switch Thread Stormgate/Frost Giant Megathread Dawn of War IV 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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
Evil Gacha Games and the…
ffswowsucks
Breaking the Meta: Non-Stand…
TrAiDoS
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2333 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 States24698 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
OSC
12:00
King of the Hill Weekly #223
CranKy Ducklings52
Liquipedia
WardiTV Summer Champion…
11:00
Playoffs Day 2
ByuN vs CureLIVE!
herO vs Classic
TBD vs NightMare
TBD vs MaxPax
WardiTV910
Rex127
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 276
Lowko192
Rex 124
LamboSC2 11
StarCraft: Brood War
Rain 10635
Calm 7489
Bisu 3278
Horang2 2773
actioN 784
Larva 480
ZerO 436
Hyun 407
Stork 381
Zeus 380
[ Show more ]
Mini 354
Pusan 249
Soulkey 249
Snow 158
Leta 146
Light 93
Backho 76
Liquid`Ret 57
JYJ45
ToSsGirL 44
Sea.KH 44
Sharp 35
Sexy 33
Shine 26
Free 22
[sc1f]eonzerg 22
JulyZerg 18
HiyA 16
ajuk12(nOOB) 12
scan(afreeca) 11
Hm[arnc] 9
SilentControl 9
Terrorterran 2
Dota 2
Gorgc3115
BananaSlamJamma234
qojqva223
420jenkins180
XcaliburYe176
Counter-Strike
olofmeister2174
x6flipin706
byalli350
edward59
Other Games
singsing1822
B2W.Neo994
hiko694
Pyrionflax394
crisheroes334
RotterdaM170
QueenE35
Organizations
StarCraft: Brood War
Afreeca ASL 6831
UltimateBattle 136
lovetv 7
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 19
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis5195
• Jankos873
Other Games
• WagamamaTV153
Upcoming Events
PiGosaur Monday
11h 12m
Afreeca Starleague
21h 12m
hero vs Alone
Royal vs Barracks
Replay Cast
1d 11h
The PondCast
1d 21h
WardiTV Summer Champion…
1d 22h
Replay Cast
2 days
LiuLi Cup
2 days
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
3 days
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
BSL Team Wars
3 days
Team Hawk vs Team Dewalt
BSL Team Wars
3 days
Team Hawk vs Team Bonyth
[ Show More ]
SC Evo League
3 days
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
Maestros of the Game
4 days
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[BSL 2025] Weekly
4 days
SC Evo League
4 days
Maestros of the Game
5 days
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
5 days
Team Bonyth vs Team Sziky
BSL Team Wars
5 days
Team Dewalt vs Team Sziky
Monday Night Weeklies
6 days
Replay Cast
6 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

CSLAN 3
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 1
Acropolis #4 - TS1
SEL Season 2 Championship
WardiTV Summer 2025
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL Season 18: Qualifier 2
CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall 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.