• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 11:03
CET 17:03
KST 01:03
  • 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: Winners8Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
Starcraft, SC2, HoTS, WC3, returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" TL.net Map Contest #21: Winners Starcraft, SC2, HoTS, WC3, returning to Blizzcon! 5.0.15 Patch Balance Hotfix (2025-10-8) Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win
Tourneys
$5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
BW General Discussion [ASL20] Ask the mapmakers — Drop your questions [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread 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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 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
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1707 users

The Big Programming Thread - Page 893

Forum Index > General Forum
Post a Reply
Prev 1 891 892 893 894 895 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
ZenithM
Profile Joined February 2011
France15952 Posts
Last Edited: 2017-06-26 13:15:43
June 26 2017 13:10 GMT
#17841
On June 26 2017 08:14 KungKras wrote:
Show nested quote +
On June 26 2017 07:52 Hanh wrote:
It helps when figuring out what units are affected by aoe or hit or even visible.


That's interesting. I never thought about AOE spells or visibility. Is it because you don't have to iterate through every object in the game to find what units are in an AOE when using a tree?

I don't know about the binary tree, but if it's just about figuring what's happening in the neighborhood of the unit, then you could already do that easily by just looking at the location and sweep around the unit. As a first approach that's not really bad. Most of the time, your units will be stored in some kind of grid-like discretization of the map (a 2D array basically). You can just sweep in a determined bounded small radius around your unit's cell.

If you're looking for some fancy way of accessing information on the map, you could look into quad-trees (Edit: ah I see that the quad-tree is mentioned in the previous page ) and the like, which are designed to handle information in 2D grids.
KungKras
Profile Joined August 2008
Sweden484 Posts
Last Edited: 2017-06-26 14:15:18
June 26 2017 14:13 GMT
#17842
On June 26 2017 15:36 Blisse wrote:
Show nested quote +
On June 26 2017 07:26 KungKras wrote:
Maybe this question is a bit too advanced, but I'll ask anyway.

I read somewhere that when making an RTS game, it's a good idea to store the units in a binary tree of some sort. Or maybe it was to hash the units and have them in a hashset of some sort. And I just can't make sense of it.

I mean if I make any game, I'll be running a game loop, and iterating through each element and its update function exactly one time. So what advantage could it possibly bring to use any other structure than an array or a list for the units/terrain/building/doodads, etc?


Found some from Google, neat stuff.

https://gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374

https://www.gamedev.net/articles/programming/general-and-gameplay-programming/introduction-to-octrees-r3529


Those link were amazing! Thanks :D

On June 26 2017 22:10 ZenithM wrote:
Show nested quote +
On June 26 2017 08:14 KungKras wrote:
On June 26 2017 07:52 Hanh wrote:
It helps when figuring out what units are affected by aoe or hit or even visible.


That's interesting. I never thought about AOE spells or visibility. Is it because you don't have to iterate through every object in the game to find what units are in an AOE when using a tree?

I don't know about the binary tree, but if it's just about figuring what's happening in the neighborhood of the unit, then you could already do that easily by just looking at the location and sweep around the unit. As a first approach that's not really bad. Most of the time, your units will be stored in some kind of grid-like discretization of the map (a 2D array basically). You can just sweep in a determined bounded small radius around your unit's cell.

If you're looking for some fancy way of accessing information on the map, you could look into quad-trees (Edit: ah I see that the quad-tree is mentioned in the previous page ) and the like, which are designed to handle information in 2D grids.


It seems like quadtrees are exactly what I'm looking for. I'm curious about how it would work in 3D space, but since I'm making a 2D one, quad trees are perfect.
"When life gives me lemons, I go look for oranges"
ShoCkeyy
Profile Blog Joined July 2008
7815 Posts
June 26 2017 14:15 GMT
#17843
Manit0u why rails over python?
Life?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 26 2017 14:18 GMT
#17844
--- Nuked ---
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2017-06-27 15:56:32
June 27 2017 07:24 GMT
#17845
On June 26 2017 23:15 ShoCkeyy wrote:
Manit0u why rails over python?


I know some Python too but there are many more job opportunities in Rails in Poland (and all over Europe, judging from the number of offers people are making me). I also like Ruby more than Python.

And no matter how reluctant I am towards Java, I believe we should switch to it (or Scala) so people can actually learn how to do enterprise stuff (and Java 8/9 isn't so bad). Doing enterprise stuff in Rails is simply unconventional.

Edit: Yay! My team lead wants to try out Scala (especially that its syntax is very close to Ruby). Keeping my hopes up.
Time is precious. Waste it wisely.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
June 27 2017 17:54 GMT
#17846
We're trying to switch to Kotlin, it's a really fun language to program in :d

We're also trying to switch to using Buck, but that's not going so well... gradle...
There is no one like you in the universe.
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-06-27 21:17:59
June 27 2017 21:14 GMT
#17847
anyone know why I am getting an error with this code?

it is for this problem:
https://leetcode.com/problems/remove-element/#/description


class Solution(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
nums.sort()
start=-1
end=-1
for i in xrange(0,len(nums)):
if nums[i]!=val:
if start<0:
start=i
else:
end=i
return nums[start:end+1]


I get Line 58: TypeError: range() integer end argument expected, got list.

It works fine for me on my IDE and rep.it though

FWIW not sure that solution is accepted, didn't bother checking after I got hooked onto figuring out why the heck I keep getting this error

edit:

I guessed that it might have to do with me returning a list and misreading the problem. I assume it's asking for a list but I tried returning the length of the list (which works again on rep.it and my IDE) but bugs out on leetcode with "Unknown Error".

Not sure if I inadvertently bugged out the system or if I actually have some strange error that happens to work on other environments.
TL/SKT
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2017-06-27 22:16:38
June 27 2017 21:31 GMT
#17848
Have you tried returning the item that was removed? That is more typical of a remove method.

Given an array and a value, remove all instances of that value in place and return the new length.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Acrofales
Profile Joined August 2010
Spain18109 Posts
June 27 2017 21:43 GMT
#17849
Well, for starters, you're supposed to do it in-place, so sorting screws that up.

But why did you not just go with the really obvious O(n) solution of walking through the list and noting all indices, then removing all elements you found with del (and returning the length of the list?)
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-06-27 22:15:00
June 27 2017 21:43 GMT
#17850
On June 28 2017 06:31 Blitzkrieg0 wrote:
Have you tried returning the item that was removed? That is more typical of a remove method.


well I didn't exactly remove the item since I'm just returning a subarray so both will be returning a subarray

but no I got the same error on the site, no error everywhere else

On June 28 2017 06:43 Acrofales wrote:
Well, for starters, you're supposed to do it in-place, so sorting screws that up.

But why did you not just go with the really obvious O(n) solution of walking through the list and noting all indices, then removing all elements you found with del (and returning the length of the list?)


well I was just doing a naiive solution since I literally just barfed out whatever I thought of in 30 seconds
I did consider your type of solution for a second but thought noticing the indices would take a non constant amount of space(is this wrong?)

of course this is with my possibly naiive assumption that you are storing the indices in another list or something similar since that's what I initially thought of

I'm not super familiar with del though so maybe there is something I'm not aware of that you can do with it. I know I couldn't delete from a list while iterating through it

I sorted because I couldn't think of a way where I could do this in constant space without the list being sorted

edit:

nvm figured out how to use del to delete while iterating lol


start=0
size=len(nums)
while start<size:
if nums[start]==val:
del nums[start]
size-=1
start+=1
return nums


however I still get the same error. so I'm wondering why that is regardless of my solution

edit2:

on topic of the solution itself, if we are just looking for the length we could probably save time since I believe del is an O(n) operation?
then just use two pointers and have the element to be removed swap with the last element and decrement the end pointer. return the pointer that started from 0 since after doing all the 'swaps' the start pointer will be at the end of our 'new' list.

nvm we can do this for returning the list too with nums[0:startIndex+1]

this would be a real O(n) I believe
the solution with del is probably O(n^2)? not completely sure on the python method complexities

and I guess my original solution was O(n^2 log n) according to this https://stackoverflow.com/questions/25813774/complexity-of-python-sort-method
TL/SKT
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2017-06-27 22:25:38
June 27 2017 22:24 GMT
#17851
Does that actually work? If the array is [1 2 2 1] and you're removing 1 doesn't your code remove the first element and then not check the last one because it decremented the size.
I'll always be your shadow and veil your eyes from states of ain soph aur.
dsyxelic
Profile Joined May 2010
United States1417 Posts
June 27 2017 22:30 GMT
#17852
On June 28 2017 07:24 Blitzkrieg0 wrote:
Does that actually work? If the array is [1 2 2 1] and you're removing 1 doesn't your code remove the first element and then not check the last one because it decremented the size.


The del one? Yeah it works. It checks the last one still because the list itself got shorter.
TL/SKT
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2017-06-27 22:57:57
June 27 2017 22:49 GMT
#17853

# @param {Integer[]} nums
# @param {Integer} val
# @return {Integer}
def remove_element(nums, val)
nums.delete(val)

nums.length
end


EZPZ

Edit: Solution for python 3

class Solution(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
return len(list(filter(lambda e: e != val, nums)))
Time is precious. Waste it wisely.
slmw
Profile Blog Joined October 2010
Finland233 Posts
Last Edited: 2017-06-27 23:00:08
June 27 2017 22:50 GMT
#17854
Why would the first version be O(N^2 log N). You sort only once. The one where you don't sort would be O(N^2) but it doesn't work. You can use the page you linked us to test it yourself. I don't think you even tested it since it doesn't work?

Edit: Manit0u: Your python solution isn't in-place so it doesn't pass the test cases.
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2017-06-27 23:33:24
June 27 2017 23:03 GMT
#17855
On June 28 2017 07:50 slmw wrote:
Why would the first version be O(N^2 log N). You sort only once. The one where you don't sort would be O(N^2) but it doesn't work. You can use the page you linked us to test it yourself. I don't think you even tested it since it doesn't work?

Edit: Manit0u: Your python solution isn't in-place so it doesn't pass the test cases.


I have to admit I'm not super good with Python

Edit:

I think I figured it out


class Solution(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
nums[:] = [x for x in nums if x != val]

return len(nums)


Solution accepted.
Time is precious. Waste it wisely.
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-06-28 01:42:58
June 27 2017 23:22 GMT
#17856
On June 28 2017 07:50 slmw wrote:
Why would the first version be O(N^2 log N). You sort only once. The one where you don't sort would be O(N^2) but it doesn't work. You can use the page you linked us to test it yourself. I don't think you even tested it since it doesn't work?

Edit: Manit0u: Your python solution isn't in-place so it doesn't pass the test cases.


Nvm o(n log n) since its essentially n log n (the sort) + n(walking through list)
Had a brain fart. Todays been a long day... 14 hrs of work+class :/

Also ?? It doesnt work as in it gives the error I posted about or it doesnt work as in it returns wrong values?

Not sure if you read my post above since I mentioned I tested all 3 solutions on my own IDE and rep.it where all worked fine, so yes I did test it lol.

Edit: sorry sounds sassy not intended

edit2:
ok back at home and apparently any form of slicing a list is giving me issues so doing it without any slicing worked
still dunno why

solution might be buggy but it's working as intended for me with the same test cases it's failing so idk

also the expected output is super misleading since it looks like a list for ex [2,2] when it wants the length. so returning a list is no good

@manitou I like your solution, pretty clean

it's pretty fast too, idk how mine is so much slower using 2 pointers with O(n) time and O(1) space
yours was almost 2 times faster than mine.


start=0
end=len(nums)-1
while start<=end:
if nums[start]==val:
nums[start],nums[end]=nums[end],nums[start]
end-=1
else:
start+=1
return start


@slmw
yeah that was it, thanks

the expected output confused me
TL/SKT
slmw
Profile Blog Joined October 2010
Finland233 Posts
Last Edited: 2017-06-28 01:24:26
June 28 2017 01:23 GMT
#17857
Oh sorry, I thought you already realised where the error comes from. Return the length of the "new" array as instructed in the problem description. Not the most obvious error message...
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2017-06-28 12:03:41
June 28 2017 05:38 GMT
#17858
On June 28 2017 08:22 dsyxelic wrote:
@manitou I like your solution, pretty clean

it's pretty fast too, idk how mine is so much slower using 2 pointers with O(n) time and O(1) space
yours was almost 2 times faster than mine.


start=0
end=len(nums)-1
while start<=end:
if nums[start]==val:
nums[start],nums[end]=nums[end],nums[start]
end-=1
else:
start+=1
return start



Too much complexity and code branching So many more instructions for the processor...

But seriously, pythonic list comprehensions are a big focus for optimization on their part so it's usually best to use them instead of using loops and iteration.
Time is precious. Waste it wisely.
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2017-06-28 06:50:08
June 28 2017 06:26 GMT
#17859
Totally unrelated, but I need to ask:

My company is desperately looking for 2 DevOps. Preferably in EU timezone so we won't call you at night (company is US based but 99% of our development happens in Poland). You'd have to do a month at our dev center here but after that you can work remote if you want to. It's mostly just server and vpn management including vmware and docker. Some CI stuff and such. Knowledge of apple servers would be a bonus (need that for one of our clients).

For more details: https://www.newshubmedia.com/careers and click on DevOps (or other things if they interest you)

If you're interested, just PM me
Time is precious. Waste it wisely.
Silvanel
Profile Blog Joined March 2003
Poland4733 Posts
Last Edited: 2017-06-28 11:57:24
June 28 2017 11:52 GMT
#17860
So we do job advertising now ??? We are looking for 50+ people for work in automotive also in Poland C/C++, DSP, JavaEmbedded, CAN, test automation (some of those required, not all). If anyone is intrested just let me know Unfortunetly since we work with hradware no remote working possible.

And thats what we do
+ Show Spoiler +


Pathetic Greta hater.
Prev 1 891 892 893 894 895 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 1h 57m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 572
BRAT_OK 90
Codebar 45
Livibee 33
StarCraft: Brood War
Jaedong 1495
GuemChi 1465
EffOrt 1325
Stork 698
Light 607
Larva 417
Snow 411
Mini 356
Rush 223
Barracks 222
[ Show more ]
Leta 119
hero 112
sSak 111
Sea.KH 51
JYJ47
Aegong 37
Backho 34
sorry 29
zelot 26
soO 23
HiyA 15
Terrorterran 14
scan(afreeca) 12
Bale 9
Dota 2
qojqva3387
420jenkins258
syndereN218
Other Games
singsing2113
Sick375
DeMusliM361
crisheroes346
Lowko284
Hui .257
Liquid`VortiX154
oskar118
KnowMe99
XcaliburYe58
QueenE30
Trikslyr12
Organizations
Counter-Strike
PGL195
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2399
• WagamamaTV457
League of Legends
• Nemesis4222
• Jankos3067
• TFBlade809
Upcoming Events
LAN Event
1h 57m
Lambo vs Harstem
FuturE vs Maplez
Scarlett vs FoxeR
Gerald vs Mixu
Zoun vs TBD
Clem vs TBD
ByuN vs TBD
TriGGeR vs TBD
Korean StarCraft League
10h 57m
CranKy Ducklings
17h 57m
IPSL
1d 1h
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
1d 1h
BSL 21
1d 3h
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
1d 6h
Sparkling Tuna Cup
1d 17h
WardiTV Korean Royale
1d 19h
IPSL
2 days
JDConan vs WIZARD
WolFix vs Cross
[ Show More ]
LAN Event
2 days
BSL 21
2 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
2 days
Wardi Open
2 days
WardiTV Korean Royale
3 days
Replay Cast
4 days
Kung Fu Cup
4 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
5 days
The PondCast
5 days
RSL Revival
5 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
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

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 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.