• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 00:57
CET 06:57
KST 14:57
  • 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
SC2 All-Star Invitational: Jan 17-1818Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises2Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies3ComeBackTV's documentary on Byun's Career !11Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win4
StarCraft 2
General
SC2 All-Star Invitational: Jan 17-18 Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises Chinese SC2 server to reopen; live all-star event in Hangzhou Starcraft 2 Zerg Coach ComeBackTV's documentary on Byun's Career !
Tourneys
OSC Season 13 World Championship WardiTV Mondays $5,000+ WardiTV 2025 Championship $100 Prize Pool - Winter Warp Gate Masters Showdow Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes Mutation # 504 Retribution Mutation # 503 Fowl Play
Brood War
General
I would like to say something about StarCraft A cwal.gg Extension - Easily keep track of anyone BGH Auto Balance -> http://bghmmr.eu/ (UMS) SWITCHEROO *New* /Destination Edit/ What monitor do you use for playing Remastered?
Tourneys
[BSL21] Non-Korean Championship - Starts Jan 10 [Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET SLON Grand Finals – Season 2
Strategy
Current Meta [G] How to get started on ladder as a new Z player Fighting Spirit mining rates Simple Questions, Simple Answers
Other Games
General Games
General RTS Discussion Thread Nintendo Switch Thread Awesome Games Done Quick 2026! Stormgate/Frost Giant Megathread Mechabellum
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 Survivor II: The Amazon Sengoku Mafia
Community
General
US Politics Mega-thread How Panthegel 5 gm Helps Repair the Eye Surface Russo-Ukrainian War Thread Canadian Politics Mega-thread The Games Industry And ATVI
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
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
National Diversity: A Challe…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1683 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
Poland17556 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
Hyrule19186 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
Next event in 7h 3m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 252
Ketroc 62
StarCraft: Brood War
Leta 456
Snow 153
Shuttle 130
ZergMaN 101
EffOrt 37
Noble 19
Bale 15
Icarus 9
Dota 2
NeuroSwarm123
League of Legends
JimRising 810
C9.Mang0527
Counter-Strike
summit1g8424
m0e_tv443
minikerr28
Heroes of the Storm
Khaldor138
Organizations
Other Games
BasetradeTV127
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• practicex 30
• Adnapsc2 10
• Kozan
• Migwel
• sooper7s
• AfreecaTV YouTube
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• RayReign 125
• HerbMon 5
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota22468
League of Legends
• Lourlo1007
• Stunt385
Other Games
• Scarra2094
Upcoming Events
OSC
7h 3m
Korean StarCraft League
21h 3m
OSC
1d 6h
IPSL
1d 8h
Dewalt vs Bonyth
OSC
1d 12h
OSC
2 days
uThermal 2v2 Circuit
2 days
Replay Cast
3 days
Patches Events
3 days
Liquipedia Results

Completed

C-Race Season 1
WardiTV 2025
META Madness #9

Ongoing

IPSL Winter 2025-26
BSL Season 21
Slon Tour Season 2
CSL Season 19: Qualifier 2
Escore Tournament S1: W2
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1: W3
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Thunderfire SC2 All-star 2025
Big Gabe Cup #3
OSC Championship Season 13
Nations Cup 2026
Underdog Cup #3
NA Kuram Kup
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.