• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:12
CET 05:12
KST 13:12
  • 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
ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
2026 KongFu Cup Announcement4BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains15Weekly Cups (March 2-8): ByuN overcomes PvT block4GSL CK - New online series19
StarCraft 2
General
GSL CK - New online series BGE Stara Zagora 2026 cancelled Blizzard Classic Cup - Tastosis announced as captains BGE Stara Zagora 2026 announced ByuL: The Forgotten Master of ZvT
Tourneys
2026 KongFu Cup Announcement RSL Season 4 announced for March-April PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) Sparkling Tuna Cup - Weekly Open Tournament [GSL CK] Team Maru vs. Team herO
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
Mutation # 517 Distant Threat The PondCast: SC2 News & Results Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
ASL21 General Discussion BSL 22 Map Contest — Submissions OPEN to March 10 BGH Auto Balance -> http://bghmmr.eu/ Are you ready for ASL 21? Hype VIDEO Gypsy to Korea
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours IPSL Spring 2026 is here! ASL Season 21 Qualifiers March 7-8
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Zealot bombing is no longer popular?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread PC Games Sales Thread No Man's Sky (PS4 and PC)
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Mexico's Drug War Russo-Ukrainian War Thread NASA and the Private Sector
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! [Req][Books] Good Fantasy/SciFi books
Sports
Formula 1 Discussion 2024 - 2026 Football Thread General nutrition recommendations Cricket [SPORT] TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2398 users

The Big Programming Thread - Page 995

Forum Index > General Forum
Post a Reply
Prev 1 993 994 995 996 997 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.
Manit0u
Profile Blog Joined August 2004
Poland17693 Posts
Last Edited: 2019-02-09 08:00:17
February 09 2019 07:59 GMT
#19881
If you need a list of primes you can always generate them yourself...


"""Returns True if n is prime."""
def isprime(n):
if n <= 3 and n > 1:
return True

if n % 2 == 0 or n % 3 == 0:
return False

i = 5
w = 2

while i * i <= n:
if n % i == 0:
return False

i += w
w = 6 - w

return True
Time is precious. Waste it wisely.
Acrofales
Profile Joined August 2010
Spain18234 Posts
February 09 2019 08:58 GMT
#19882
Why would you do that?
mahrgell
Profile Blog Joined December 2009
Germany3943 Posts
February 09 2019 10:09 GMT
#19883
Because coders pride. Why use an existing list of primes, when you can write (a highly inefficient) algorithm to make one?

In fact, why not be cool and impress anyone who later reads this code, by using the regexp ^.?$|^(..+?)\1+$ as prime checker?
I'm sure they will all bow to your skills! (and hopefully never have to run the code)
solidbebe
Profile Blog Joined November 2010
Netherlands4921 Posts
February 09 2019 10:41 GMT
#19884
On February 09 2019 16:59 Manit0u wrote:
If you need a list of primes you can always generate them yourself...

+ Show Spoiler +

"""Returns True if n is prime."""
def isprime(n):
if n <= 3 and n > 1:
return True

if n % 2 == 0 or n % 3 == 0:
return False

i = 5
w = 2

while i * i <= n:
if n % i == 0:
return False

i += w
w = 6 - w

return True

thats a yikes
That's the 2nd time in a week I've seen someone sig a quote from this GD and I have never witnessed a sig quote happen in my TL history ever before. -Najda
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 09 2019 13:28 GMT
#19885
coder's pride lol I love it
SC-Shield
Profile Joined December 2018
Bulgaria837 Posts
February 10 2019 19:08 GMT
#19886
On February 09 2019 19:09 mahrgell wrote:
Because coders pride. Why use an existing list of primes, when you can write (a highly inefficient) algorithm to make one?

In fact, why not be cool and impress anyone who later reads this code, by using the regexp ^.?$|^(..+?)\1+$ as prime checker?
I'm sure they will all bow to your skills! (and hopefully never have to run the code)


It's probably human mentality. Why pay a handyman when you can do it yourself even if it's done really bad? Easily noticeable if you rent a property and you deal with landlord directly. :D
graNite
Profile Blog Joined December 2010
Germany4434 Posts
February 10 2019 23:38 GMT
#19887
can i simplify this somehow? i feel like this should be able to be done with only one height_at call.
i want to get a set of all points that have the maximum height.
max_height = max(self.height_at(p) for p in self._points) 
return {p for p in self._points if self.height_at(p) == max_height}
"Oink oink, bitches" - Tasteless on Pigbaby winning a map against Flash
Frolossus
Profile Joined February 2010
United States4779 Posts
February 10 2019 23:57 GMT
#19888
On February 11 2019 08:38 graNite wrote:
can i simplify this somehow? i feel like this should be able to be done with only one height_at call.
i want to get a set of all points that have the maximum height.
max_height = max(self.height_at(p) for p in self._points) 
return {p for p in self._points if self.height_at(p) == max_height}

do 1 loop and bind self.height(p) to a temp variable?
graNite
Profile Blog Joined December 2010
Germany4434 Posts
Last Edited: 2019-02-11 00:25:25
February 11 2019 00:22 GMT
#19889
do you mean like this?
current_max = 0
result = set()
for p in self._points:
height = self.height_at(p)
if height < current_max:
continue
elif height == current_max:
result.append(p)
else:
current_max = height
result = {p}
return result


i dont know if this is faster...i would like to use a set comprehension
"Oink oink, bitches" - Tasteless on Pigbaby winning a map against Flash
Acrofales
Profile Joined August 2010
Spain18234 Posts
Last Edited: 2019-02-11 00:31:38
February 11 2019 00:26 GMT
#19890
On February 11 2019 08:57 Frolossus wrote:
Show nested quote +
On February 11 2019 08:38 graNite wrote:
can i simplify this somehow? i feel like this should be able to be done with only one height_at call.
i want to get a set of all points that have the maximum height.
max_height = max(self.height_at(p) for p in self._points) 
return {p for p in self._points if self.height_at(p) == max_height}

do 1 loop and bind self.height(p) to a temp variable?

E: nvm, misunderstood the question. You could do it in a single loop if you wanted, but it would be more complex, not simpler. You could make a map from heights to lists of points. That way you only loop once, but I doubt it's much faster (you have to construct the dict).
Artesimo
Profile Joined February 2015
Germany567 Posts
February 11 2019 00:46 GMT
#19891
I am trying to help a friend with a project regarding audio files and volume, regarding .wav files to be precise. He wants to make a soundmod for a game but the problem is that the original and the added files have different base volumes. Generally speaking I know how to normalize / amplify sounds using audacity, however this has some problems.

The amount of files make it hard to do this by hand. I know that there are ways to batchprocess files with audacity but here comes another problem:
We aren’t sure if all the original and additional .wavs are similar in terms of volume which got me thinking. The base volume has to be encoded in some way right? Therefore there should be a way to read out this base volume? I am looking for a way to just check how "loud" the basevolume of all the files is and deduct from that how much the added sounds need to be amplified with maybe some individual adjustment rather than adjusting every sound by hand. Does anyone has experience with this or can share some insight how the encoding of the volume actually works?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2019-02-11 01:24:57
February 11 2019 01:19 GMT
#19892
On February 11 2019 08:38 graNite wrote:
can i simplify this somehow? i feel like this should be able to be done with only one height_at call.
i want to get a set of all points that have the maximum height.
max_height = max(self.height_at(p) for p in self._points) 
return {p for p in self._points if self.height_at(p) == max_height}


its impossible to do it in a comprehension because a comprehension only does one loop through but you can't know what the max is until you've gone through all elements, and there is no way to go back and change what you have already added to the comprehension

well, I mean you can, but then you end up asking what the max height is for every single element, and you obviously don't want to do that


On February 11 2019 09:22 graNite wrote:
do you mean like this?
current_max = 0
result = set()
for p in self._points:
height = self.height_at(p)
if height < current_max:
continue
elif height == current_max:
result.append(p)
else:
current_max = height
result = {p}
return result


i dont know if this is faster...i would like to use a set comprehension



this is probably faster
what would be even better is to have a Max variable for whatever this object is
graNite
Profile Blog Joined December 2010
Germany4434 Posts
February 11 2019 01:45 GMT
#19893
What do you mean by Max variable? Do you mean an upper bound?

The object is the height map the sc2 api provides. This is for the Python-sc2 library.
"Oink oink, bitches" - Tasteless on Pigbaby winning a map against Flash
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2019-02-11 02:02:18
February 11 2019 01:57 GMT
#19894
i meant if the object that has these points maintained the value of the "highest point" as a max, so that you don't have to look through all the points to find it

I've used python-sc2 a little, but not much
can I ask what are you trying to do?


you are editing the api?
graNite
Profile Blog Joined December 2010
Germany4434 Posts
February 11 2019 02:08 GMT
#19895
Yes, i thought i can improve here https://github.com/Dentosal/python-sc2/blob/1ccc1eae2e181e939aa8b6060d2014b40916f0c4/sc2/game_info.py#L39
And the 'lower' property which is the same but with minimum.
"Oink oink, bitches" - Tasteless on Pigbaby winning a map against Flash
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 11 2019 02:14 GMT
#19896
yeah you won't be able to make it faster in one line of code I think, a comprehension will call a function on every iteration
emperorchampion
Profile Blog Joined December 2008
Canada9496 Posts
February 11 2019 09:03 GMT
#19897
On February 11 2019 09:46 Artesimo wrote:
I am trying to help a friend with a project regarding audio files and volume, regarding .wav files to be precise. He wants to make a soundmod for a game but the problem is that the original and the added files have different base volumes. Generally speaking I know how to normalize / amplify sounds using audacity, however this has some problems.

The amount of files make it hard to do this by hand. I know that there are ways to batchprocess files with audacity but here comes another problem:
We aren’t sure if all the original and additional .wavs are similar in terms of volume which got me thinking. The base volume has to be encoded in some way right? Therefore there should be a way to read out this base volume? I am looking for a way to just check how "loud" the basevolume of all the files is and deduct from that how much the added sounds need to be amplified with maybe some individual adjustment rather than adjusting every sound by hand. Does anyone has experience with this or can share some insight how the encoding of the volume actually works?


I don't know anything about audio, but I would start by reading up on this: https://stackoverflow.com/questions/984729/how-can-i-determine-how-loud-a-wav-file-will-sound

Any calculations can be easily done with a for loop in Python once you have the procedure down.
TRUEESPORTS || your days as a respected member of team liquid are over
graNite
Profile Blog Joined December 2010
Germany4434 Posts
Last Edited: 2019-02-11 09:09:10
February 11 2019 09:08 GMT
#19898
On February 11 2019 11:14 travis wrote:
yeah you won't be able to make it faster in one line of code I think, a comprehension will call a function on every iteration


you are right
i use the one loop solution above now, it is almost twice as fast.
"Oink oink, bitches" - Tasteless on Pigbaby winning a map against Flash
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
Last Edited: 2019-02-11 17:30:20
February 11 2019 17:10 GMT
#19899
On February 09 2019 03:39 travis wrote:
edit:

nevermind found what I wanted. which was a list of primes. I found the first 50 million, geeze. probably morethan I need

You can generate all prime numbers up to 10^9 in less than 30 seconds on an average work station using sieve of eratosthenes: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes. It's about 50.8 million primes.

public class PrimeSieve {
private bool[] _notPrimes;
private List<ulong> _primes = new List<ulong>();

public PrimeSieve(ulong max) {
SievePrimes(max);
}

private void SievePrimes(ulong max) {
_notPrimes = new bool[max / 2 + 1];
_primes.Add(2);
for (ulong num = 3; num <= max; num += 2) {
if (!_notPrimes[num / 2 - 1]) {
_primes.Add(num);
for (ulong composite = 3; composite * num <= max; composite += 2) {
_notPrimes[composite * num / 2 - 1] = true;
}
}
}
}

public bool IsPrime(ulong num) {
if (num <= 1) {
return false;
} else if (num == 2) {
return true;
} else if (num % 2 == 0) {
return false;
} else {
return !_notPrimes[num / 2 - 1];
}
}

public int Count {
get { return _primes.Count; }
}

public IEnumerable<ulong> Enumerate {
get { return _primes; }
}
}
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
February 13 2019 19:29 GMT
#19900
Anyone here a regular on Project Euler? Would like to add as friend so I can occasionally ask for advice.
Prev 1 993 994 995 996 997 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 48m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 289
ProTech129
StarCraft: Brood War
GuemChi 4299
ggaemo 87
Leta 83
ZergMaN 38
Noble 38
Icarus 9
Dota 2
NeuroSwarm153
LuMiX1
League of Legends
JimRising 677
Counter-Strike
taco 924
Stewie2K7
Super Smash Bros
hungrybox452
Heroes of the Storm
Khaldor151
Other Games
summit1g11868
C9.Mang0309
Maynarde150
Organizations
Other Games
gamesdonequick843
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• practicex 78
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1310
• Rush1188
• Stunt318
Upcoming Events
GSL
3h 48m
Wardi Open
7h 48m
Monday Night Weeklies
12h 48m
WardiTV Team League
1d 7h
PiGosaur Cup
1d 19h
Kung Fu Cup
2 days
OSC
2 days
The PondCast
3 days
KCM Race Survival
3 days
WardiTV Team League
3 days
[ Show More ]
Replay Cast
3 days
KCM Race Survival
4 days
WardiTV Team League
4 days
Korean StarCraft League
4 days
uThermal 2v2 Circuit
5 days
BSL
5 days
BSL
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-03-13
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
CSL Elite League 2026
RSL Revival: Season 4
Nations Cup 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
NationLESS Cup
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
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 © 2026 TLnet. All Rights Reserved.