• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:32
CEST 06:32
KST 13:32
  • 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
Code S Season 1 - RO8 Preview1[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10
Community News
Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event11Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced9
StarCraft 2
General
Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results
Tourneys
GSL Code S Season 1 (2026) Sparkling Tuna Cup - Weekly Open Tournament RSL Revival: Season 5 - Qualifiers and Main Event StarCraft Evolution League (SC Evo Biweekly) 2026 GSL Season 2 Qualifiers
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
(Spoiler) Asl ro8 D winner interview BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion Do we have a pimpest plays list? AI Question
Tourneys
[ASL21] Ro8 Day 4 [Megathread] Daily Proleagues [ASL21] Ro8 Day 3 [ASL21] Ro8 Day 2
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV OutLive 25 (RTS Game) Daigo vs Menard Best of 10 Nintendo Switch Thread
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Movie Stars In Video Games: …
TrAiDoS
ramps on octagon
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1023 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
Poland17743 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
Spain18286 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
Bulgaria843 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
Spain18286 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
Germany572 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
PiGosaur Cup
00:00
#80 (TLMC 22 Edition)
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JimRising 795
ROOTCatZ 165
SpeCial 105
CosmosSc2 16
StarCraft: Brood War
GuemChi 6523
910 55
Noble 14
Bale 14
JulyZerg 13
Icarus 7
ZergMaN 6
Dota 2
monkeys_forever369
Counter-Strike
Stewie2K709
Super Smash Bros
Mew2King81
Other Games
summit1g8208
tarik_tv5624
C9.Mang0543
fl0m451
RuFF_SC2197
ViBE41
Organizations
Other Games
gamesdonequick932
Dota 2
PGL Dota 2 - Main Stream36
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• Hupsaiya 119
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
• swagsyndrome_ 0
StarCraft: Brood War
• RayReign 109
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Scarra3015
Upcoming Events
GSL
4h 58m
Classic vs Cure
Maru vs Rogue
GSL
1d 4h
SHIN vs Zoun
ByuN vs herO
OSC
1d 6h
OSC
1d 8h
Replay Cast
1d 19h
Escore
2 days
The PondCast
2 days
WardiTV Invitational
2 days
Zoun vs Ryung
Lambo vs ShoWTimE
OSC
2 days
Replay Cast
2 days
[ Show More ]
CranKy Ducklings
3 days
RSL Revival
3 days
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
3 days
Krystianer vs TriGGeR
Cure vs Rogue
uThermal 2v2 Circuit
3 days
BSL
3 days
Replay Cast
3 days
Sparkling Tuna Cup
4 days
RSL Revival
4 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
4 days
BSL
4 days
GSL
5 days
Afreeca Starleague
5 days
Monday Night Weeklies
5 days
Afreeca Starleague
6 days
CranKy Ducklings
6 days
Liquipedia Results

Completed

Proleague 2026-05-05
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
YSL S3
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W6
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 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.