• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 19:46
CET 01:46
KST 09:46
  • 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 Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)11Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns6[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1822Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises3
StarCraft 2
General
Spontaneous hotkey change zerg Chinese SC2 server to reopen; live all-star event in Hangzhou Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns SC2 All-Star Invitational: Jan 17-18 Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises
Tourneys
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026 OSC Season 13 World Championship
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes
Brood War
General
Potential ASL qualifier breakthroughs? I would like to say something about StarCraft BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
Awesome Games Done Quick 2026! Mechabellum Beyond All Reason Stormgate/Frost Giant 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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Trading/Investing Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2773 users

The Big Programming Thread - Page 693

Forum Index > General Forum
Post a Reply
Prev 1 691 692 693 694 695 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.
Cyx.
Profile Joined November 2010
Canada806 Posts
December 15 2015 04:59 GMT
#13841
On December 15 2015 12:12 WarSame wrote:
If you had to create a weighted chooser in as few lines of code as possible, while still being easily changeable, how would you do so?

For example,
i=randint()
if (i<0.1):
blah
elseif (i<0.2):
blah2
etc.

is out because if you change any weight you have to change them all. What're your ideas?

Well, seems to me your option is either that or define some relationship between all the variables so you can tell how one should change when the others do, neither of which is going to be easy. I'd probably go with the if statements unless it was really necessary.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 15 2015 05:19 GMT
#13842
Maybe. I was thinking of using an array that is as long as the sum of the weights, and filling it with weight*element of each element, and selected randomly inside it, but that seems a bit silly to do this, is it not?
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Zocat
Profile Joined April 2010
Germany2229 Posts
December 15 2015 06:02 GMT
#13843
Your element 0 will fuck you in most languages.

Are there other constraints? (weights add to 1.0, stepsize is 0.01, ...) Or do we just know the percentages?
raNazUra
Profile Joined December 2012
United States10 Posts
December 15 2015 06:05 GMT
#13844
If you're happy with the weights being passed in as an array, you could do something like:
total = sum(weights)
roll = random.random() * total
i = 0
accum = weights[0]
while accum < roll:
i += 1
accum += weights[i]
// Here, i will be the index of the randomly selected weight, and you can do whatever you want based on that.

Basically, a generalized version of the earlier code. This is O(# of weights) in time, but better in space than the weight*elements solution (and works fine with arbitrary weights, not just integers), whereas the other is better in time since you just do an array lookup once you have the random number, but worse in space.
Speak the truth, even if your voice shakes
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 15 2015 07:34 GMT
#13845
Thanks, that's a much improved version!
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
December 15 2015 08:00 GMT
#13846
On December 15 2015 12:12 WarSame wrote:
If you had to create a weighted chooser in as few lines of code as possible, while still being easily changeable, how would you do so?

For example,
i=randint()
if (i<0.1):
blah
elseif (i<0.2):
blah2
etc.

is out because if you change any weight you have to change them all. What're your ideas?


Depending on the language and context, I like to use associative arrays/maps with lambdas:

//PSEUDOCODE

weightMap = {
0.1: function() { do_stuff(); },
0.2: function() { do_other_stuff(); },
1.0: function() { do_last_stuff(); }
};

i = random();
foreach (weight in keys weightMap)
{
if (i <= weight)
{
weightMap[weight]();
break;
}
}


It's not the most concise and arguably not the most optimized, but it allows for very easy modification since the information is in a single place and not intermixed with the program logic (if/else tree). You just have to remember that not all languages preserve the ordering of the keys.
waffelz
Profile Blog Joined June 2012
Germany711 Posts
December 15 2015 08:24 GMT
#13847
Is there a noteworthy alternative to AndroidStudio for developing an app for android which doesn’t suck as much as AndroidStudio?
RIP "The big travis CS degree thread", taken from us too soon | Honourable forum princess, defended by Rebs-approved white knights
zatic
Profile Blog Joined September 2007
Zurich15358 Posts
December 15 2015 08:52 GMT
#13848
On December 15 2015 17:24 waffelz wrote:
Is there a noteworthy alternative to AndroidStudio for developing an app for android which doesn’t suck as much as AndroidStudio?

There is ADT, which sucks even more.

Really though, Studio is pretty nice once you get the hang of it.
ModeratorI know Teamliquid is known as a massive building
waffelz
Profile Blog Joined June 2012
Germany711 Posts
December 15 2015 11:57 GMT
#13849
On December 15 2015 17:52 zatic wrote:
There is ADT, which sucks even more.

Really though, Studio is pretty nice once you get the hang of it.


On December 15 2015 17:52 zatic wrote:
There is ADT, which sucks even more.

Really though, Studio is pretty nice once you get the hang of it.


"Pretty nice" - Like not updating the layout unless you also changed something in the actual code? (for which now I have a function called fuckAndoridStudio() in which I just add another line of Log.v (“MyApp”,”Fuck Android Studio”); whenever I just change something in the layout.

I work with an older version though(1.4) since in the lab they don’t have the actual one and since it isn’t backwards compatible… I also freely admit that I am new to AndroidStudio and that we never got a useful introduction besides “This is java, we work with AndoridStudio which isn’t exactly java but fuck it. We also know that you probably already know java and that there a ton of resources to learn java and therefore it would make more sense to show you how to use AndoridStudio – but we won’t since this is the first time we use AndroidStudio in this course and I couldn’t be asked to look into it. So… do you want to see some java example that would have been useful for previous year? Wanna read in some strings?”

Thanks nonetheless. If someone can recommend a really good AndroidStudio tutorial which takes focus on the appdevelopment/usage of AndroidStudio and not on java itself it would be greatly appreciated. I got a serious problem with my mindset when it comes to knowing my functions but being too incompetent with the tools… Like a fucking painter that suddenly can’t paint a wall anymore because he got a different brush. I get frustrated a lot and then I get stuck.

RIP "The big travis CS degree thread", taken from us too soon | Honourable forum princess, defended by Rebs-approved white knights
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 15 2015 17:07 GMT
#13850
I've been doing some work on the number of different ways to make change, and I've almost got it working properly and running extremely fast, but got a strange bug - for a coin denomination it will run it with the max of that coin, then skip the second most possible and go straight to the third and on. I have no idea why, and can't seem to bug hunt it.

The code is here.

coinDenoms is a global variable.

This outputs + Show Spoiler +
There are 30 different solutions.
2 0 0 0
0 5 0 0
0 3 4 0
0 3 2 10
0 3 1 15
0 3 0 20
0 2 6 0
0 2 4 10
0 2 3 15
0 2 2 20
0 2 1 25
0 2 0 30
0 1 8 0
0 1 6 10
0 1 5 15
0 1 4 20
0 1 3 25
0 1 2 30
0 1 1 35
0 1 0 40
0 0 10 0
0 0 8 10
0 0 7 15
0 0 6 20
0 0 5 25
0 0 4 30
0 0 3 35
0 0 2 40
0 0 1 45
0 0 0 50
As you can see, it goes straight from 2 quarters to 0 - and I have no idea why. If you can point it out to me I'd appreciate it.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
AKnopf
Profile Blog Joined March 2011
Germany259 Posts
Last Edited: 2015-12-15 19:01:23
December 15 2015 19:00 GMT
#13851
On December 15 2015 17:00 Morfildur wrote:
Show nested quote +
On December 15 2015 12:12 WarSame wrote:
If you had to create a weighted chooser in as few lines of code as possible, while still being easily changeable, how would you do so?

For example,
i=randint()
if (i<0.1):
blah
elseif (i<0.2):
blah2
etc.

is out because if you change any weight you have to change them all. What're your ideas?


Depending on the language and context, I like to use associative arrays/maps with lambdas:

//PSEUDOCODE

weightMap = {
0.1: function() { do_stuff(); },
0.2: function() { do_other_stuff(); },
1.0: function() { do_last_stuff(); }
};

i = random();
foreach (weight in keys weightMap)
{
if (i <= weight)
{
weightMap[weight]();
break;
}
}


It's not the most concise and arguably not the most optimized, but it allows for very easy modification since the information is in a single place and not intermixed with the program logic (if/else tree). You just have to remember that not all languages preserve the ordering of the keys.



The problem with this approach is, that adding elements if fairly hard because every new element reduces the probability of all the elements after it but not of the ones before it. So you would need to do some serious calculation each time you add a new element.

Here is what I came up with in a few minutes: Not the prettiest code I ever wrote though :D


class Hash
def total_weight
@total_weight ||= values.reduce :+
end

def sample
sum = 0
keys.each do |key|
probability = self[key]
if rand(total_weight) >= total_weight - (probability + sum)
return key
else
sum += probability
end
end
end
end

random_stuff = {"A" => 1, "B" => 5, "C" => 59, "D" => 120}

picks = { "A" => 0, "B" => 0, "C" => 0, "D" => 0}

10000.times do
picks[random_stuff.sample] += 1
end

p picks # Sample output: {"A"=>57, "B"=>333, "C"=>3351, "D"=>6259}


You just have to create a Hash/Map/Dictionary/WhateverItIsCalledInYourLanguage with your random thing as key and its probability as value and call the "sample" method on it.
This only works with integer probabilities though.
The world - its a funny place
Lazorstorm
Profile Blog Joined May 2014
33 Posts
December 15 2015 20:00 GMT
#13852
Hey everyone,

I got a question..
I have a folder with around 11000 files (roms actually)..
Im looking for a quick/easy way to select all files which have [i] in their file name. These are the roms that i need.
Does anyone know of a way to select all those files so i can copy them to a seperate folder?

Just pm me or reply in this thread if u think u can be of any help.

Thanks in advance ^^
Long time lurker
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 15 2015 20:04 GMT
#13853
On December 16 2015 05:00 Lazorstorm wrote:
Hey everyone,

I got a question..
I have a folder with around 11000 files (roms actually)..
Im looking for a quick/easy way to select all files which have [i] in their file name. These are the roms that i need.
Does anyone know of a way to select all those files so i can copy them to a seperate folder?

Just pm me or reply in this thread if u think u can be of any help.

Thanks in advance ^^

Since you're posting in the programming thread, how about you just write a small program that loops through all these files, checks their name, and copies them to another folder? If you have Visual Studio installed, that's like 5-10 lines of C#.
If you have a good reason to disagree with the above, please tell me. Thank you.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2015-12-15 20:35:27
December 15 2015 20:18 GMT
#13854
On December 16 2015 05:00 Lazorstorm wrote:
Hey everyone,

I got a question..
I have a folder with around 11000 files (roms actually)..
Im looking for a quick/easy way to select all files which have [i] in their file name. These are the roms that i need.
Does anyone know of a way to select all those files so i can copy them to a seperate folder?

Just pm me or reply in this thread if u think u can be of any help.

Thanks in advance ^^

Which system are you on? If Linux(and maybe Unix) check out Bash scripting. You could simply "*[i]*" and pipe that into whatever you want to do.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Lazorstorm
Profile Blog Joined May 2014
33 Posts
December 15 2015 20:46 GMT
#13855
@spineshealth :

That sounds like a good idea. I'm indeed into programming but i got 0 experience with C#, so it might be difficult for me.
Thanks for the reply, i'll certainly give it a shot

@WarSame :
I got a windows pc and a raspberry pi runnig Raspbian. I dont have a lot of experience with 'Bash Scripting' either.
I tried googling what i want to do, but so far i havent found anything that actually pointed me in the right direction.

Any chance u guys got a link to some tutorial or example that could help me figure this stuff out?

Thanks in advance again! :D
Long time lurker
Manit0u
Profile Blog Joined August 2004
Poland17588 Posts
December 15 2015 20:52 GMT
#13856
On December 16 2015 05:00 Lazorstorm wrote:
Hey everyone,

I got a question..
I have a folder with around 11000 files (roms actually)..
Im looking for a quick/easy way to select all files which have [i] in their file name. These are the roms that i need.
Does anyone know of a way to select all those files so i can copy them to a seperate folder?

Just pm me or reply in this thread if u think u can be of any help.

Thanks in advance ^^


http://superuser.com/questions/312348/linux-copy-all-files-matching-pattern-from-dir-and-subdirs-into-a-single-dir
Time is precious. Waste it wisely.
Lazorstorm
Profile Blog Joined May 2014
33 Posts
December 15 2015 21:12 GMT
#13857
On December 16 2015 05:52 Manit0u wrote:
Show nested quote +
On December 16 2015 05:00 Lazorstorm wrote:
Hey everyone,

I got a question..
I have a folder with around 11000 files (roms actually)..
Im looking for a quick/easy way to select all files which have [i] in their file name. These are the roms that i need.
Does anyone know of a way to select all those files so i can copy them to a seperate folder?

Just pm me or reply in this thread if u think u can be of any help.

Thanks in advance ^^


http://superuser.com/questions/312348/linux-copy-all-files-matching-pattern-from-dir-and-subdirs-into-a-single-dir


Thanks!!! I'll try to figure this out ^^
Long time lurker
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 15 2015 22:16 GMT
#13858
On December 16 2015 05:46 Lazorstorm wrote:
@spineshealth :

That sounds like a good idea. I'm indeed into programming but i got 0 experience with C#, so it might be difficult for me.
Thanks for the reply, i'll certainly give it a shot

@WarSame :
I got a windows pc and a raspberry pi runnig Raspbian. I dont have a lot of experience with 'Bash Scripting' either.
I tried googling what i want to do, but so far i havent found anything that actually pointed me in the right direction.

Any chance u guys got a link to some tutorial or example that could help me figure this stuff out?

Thanks in advance again! :D

Are these files on the Pi or the PC? If on the Pi you can quickly write something up for this in Python(here's some pseudocode):


import os, shutil
fileList=os.listdir()
for file in fileList:
if file.contains("[i]"):
newLocation=file.replace("[i]","")
shutil.move(os.getcwd()+file, newLocation)#Make sure you run this script in the folder you want to change

I can't guarantee this works properly - test it before you run it on your main folder. In particular, you may have a problem with slashes - these types of functions handle them weird and I can't remember which functions do it which way. So test it on small sets of files beforehand.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
tofucake
Profile Blog Joined October 2009
Hyrule19188 Posts
December 16 2015 00:40 GMT
#13859
If it's on the PC you can do what you want in Batch
Liquipediaasante sana squash banana
Shenghi
Profile Joined August 2010
167 Posts
Last Edited: 2015-12-16 05:55:18
December 16 2015 05:00 GMT
#13860
On December 16 2015 02:07 WarSame wrote:
I've been doing some work on the number of different ways to make change, and I've almost got it working properly and running extremely fast, but got a strange bug - for a coin denomination it will run it with the max of that coin, then skip the second most possible and go straight to the third and on. I have no idea why, and can't seem to bug hunt it.

The code is here.

coinDenoms is a global variable.

This outputs + Show Spoiler +
There are 30 different solutions.
2 0 0 0
0 5 0 0
0 3 4 0
0 3 2 10
0 3 1 15
0 3 0 20
0 2 6 0
0 2 4 10
0 2 3 15
0 2 2 20
0 2 1 25
0 2 0 30
0 1 8 0
0 1 6 10
0 1 5 15
0 1 4 20
0 1 3 25
0 1 2 30
0 1 1 35
0 1 0 40
0 0 10 0
0 0 8 10
0 0 7 15
0 0 6 20
0 0 5 25
0 0 4 30
0 0 3 35
0 0 2 40
0 0 1 45
0 0 0 50
As you can see, it goes straight from 2 quarters to 0 - and I have no idea why. If you can point it out to me I'd appreciate it.

Do you have the full code, so we can just paste it into an editor and it it works, without having to piece things together? That makes it a lot easier to help. =]

Also, I asked this before (but not in a post that directly quoted you) and it's a very important difference: Is the question how many ways there are to make change, or which ways there are? This is important because if you take common coin denominations (1, 2, 5, 10, 25, 50, 100, 200), there are over 5 000 000 ways to change 500 cents and over 260 000 000 ways to change 1000 cents. While it's extremely easy to calculate how many ways there are, even for values much larger, it quickly become infeasible and slightly later impossible to determine which ways there are.
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
Prev 1 691 692 693 694 695 1032 Next
Please log in or register to reply.
Live Events Refresh
BSL 21
20:00
Non-Korean Championship
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
White-Ra 202
JuggernautJason106
UpATreeSC 84
StarCraft: Brood War
Artosis 698
Sexy 51
Shine 45
NaDa 22
Dota 2
syndereN697
capcasts205
Counter-Strike
summit1g6756
fl0m4820
minikerr12
Other Games
FrodaN7722
tarik_tv6104
Liquid`RaSZi2756
Maynarde160
KnowMe156
ArmadaUGS112
ViBE43
Organizations
Other Games
gamesdonequick5491
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• Berry_CruncH73
• Hupsaiya 63
• Sammyuel 29
• musti20045 20
• IndyKCrew
• AfreecaTV YouTube
• intothetv
• Kozan
• sooper7s
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• RayReign 22
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Other Games
• imaqtpie2024
• Scarra274
Upcoming Events
Replay Cast
8h 14m
Wardi Open
13h 14m
Monday Night Weeklies
16h 14m
WardiTV Invitational
1d 11h
WardiTV Invitational
2 days
The PondCast
3 days
OSC
3 days
OSC
4 days
All Star Teams
5 days
INnoVation vs soO
sOs vs Scarlett
uThermal 2v2 Circuit
5 days
[ Show More ]
All Star Teams
6 days
MMA vs DongRaeGu
Rogue vs Oliveira
Sparkling Tuna Cup
6 days
OSC
6 days
Liquipedia Results

Completed

Proleague 2026-01-11
Big Gabe Cup #3
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
OSC Championship Season 13
Underdog Cup #3
NA Kuram Kup
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Nations Cup 2026
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 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 © 2026 TLnet. All Rights Reserved.