• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 17:16
CET 23:16
KST 07:16
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
RSL Season 3: RO16 results & RO8 bracket13Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge2[TLMC] Fall/Winter 2025 Ladder Map Rotation14Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA15
StarCraft 2
General
Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge SC: Evo Complete - Ranked Ladder OPEN ALPHA RSL Season 3: RO16 results & RO8 bracket RSL Season 3 - Playoffs Preview Mech is the composition that needs teleportation t
Tourneys
RSL Revival: Season 3 $5,000+ WardiTV 2025 Championship StarCraft Evolution League (SC Evo Biweekly) Constellation Cup - Main Event - Stellar Fest 2025 RSL Offline Finals Dates + Ticket Sales!
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death
Brood War
General
2v2 maps which are SC2 style with teams together? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ soO on: FanTaSy's Potential Return to StarCraft A cwal.gg Extension - Easily keep track of anyone
Tourneys
[BSL21] RO16 Tie Breaker - Group B - Sun 21:00 CET [BSL21] RO16 Tie Breaker - Group A - Sat 21:00 CET [Megathread] Daily Proleagues Small VOD Thread 2.0
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Path of Exile Nintendo Switch Thread Should offensive tower rushing be viable in RTS games? Clair Obscur - Expedition 33 Stormgate/Frost Giant Megathread
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
Mafia Game Mode Feedback/Ideas
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread The Games Industry And ATVI Things Aren’t Peaceful in Palestine About SC2SEA.COM
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread Korean Music Discussion
Sports
Formula 1 Discussion 2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
The Health Impact of Joining…
TrAiDoS
Dyadica Evangelium — Chapt…
Hildegard
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2103 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
Poland17450 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
Spain18132 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
Bulgaria832 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
Spain18132 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
Germany564 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
BSL 21
20:00
RO16 TieBreaker - Group B
StRyKeR vs Artosis
OyAji vs KameZerg
ZZZero.O372
LiquipediaDiscussion
IPSL
20:00
Ro16 Group C
StRyKeR vs OldBoy
Sziky vs Tarson
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
White-Ra 258
JuggernautJason138
StarCraft: Brood War
Calm 2731
ZZZero.O 372
Dota 2
LuMiX1
Heroes of the Storm
Khaldor341
Other Games
Grubby7222
FrodaN2498
Mlord599
B2W.Neo407
Pyrionflax233
ArmadaUGS145
Maynarde52
Organizations
Other Games
EGCTV1950
gamesdonequick1042
BasetradeTV35
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• davetesta100
• Hupsaiya 80
• musti20045 31
• HeavenSC 14
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• Airneanach38
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2390
• Ler111
League of Legends
• Doublelift2244
Other Games
• imaqtpie1528
• tFFMrPink 9
Upcoming Events
OSC
45m
OSC
10h 45m
Wardi Open
13h 45m
Monday Night Weeklies
18h 45m
OSC
1d
Wardi Open
1d 13h
Replay Cast
2 days
Wardi Open
2 days
Tenacious Turtle Tussle
3 days
The PondCast
3 days
[ Show More ]
Replay Cast
4 days
LAN Event
4 days
Replay Cast
5 days
Replay Cast
5 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Proleague 2025-11-21
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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.