• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:27
CEST 22:27
KST 05:27
  • 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
[ASL22] Ro8 Preview: In A Tizzy2[ASL22] Ro16 Preview: Holy Diver5[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9
Community News
Weekly Cups (Sep 7-12): SHIN, ByuN, MaxPax double down1StarCraft open world shooter announced at BlizzCon101Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10Official StarCraft website teases new content ahead of BlizzCon?179Stellar Fest TWO the Moon (Dec 16-20)9
StarCraft 2
General
StarCraft open world shooter announced at BlizzCon Balance hotfix patch 5.0.16b (July 16) SC4ALL II: StarCraft 2 Player Announcement 8/8 The Death of Cheese: From a Professional Cheeser Yamato Cup Series
Tourneys
2026 GSTL Announcement Sparkling Tuna Cup - Weekly Open Tournament RSL Revival: Season 6 - Qualifiers and Main Event RSL goes to London! 2026 Offline Finals Nov 21-22 SC2 AI Tournament 2026 Fall
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 544 Double Trouble The PondCast: SC2 News & Results Mutation # 543 Enhanced Defenses Mutation # 542 The Ascended
Brood War
General
Bot on ladder an AI researcher's take on the ladder bot BGH Auto Balance -> http://bghmmr.eu/ [ASL22] Ro8 Preview: In A Tizzy BW General Discussion
Tourneys
[BSL23] SM: Ret vs TerrOr -> DragOn vs StRyKeR [Megathread] Daily Proleagues [ASL22] Ro16 Group D [ASL22] Ro16 Group B
Strategy
Cliff Jump Revisited (1 in a 1000 strategy) Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation
Other Games
General Games
Nintendo Switch Thread Warcraft III: The Frozen Throne Stormgate/Frost Giant Megathread EVE Corporation Diablo IV
Dota 2
Dota 2 Champions League Season 3 Begins April 25! Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine All you football fans (soccer)! Russo-Ukrainian War Thread Canadian Politics Mega-thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Diablo Animated Series on Netflix
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Gaming Intensity, Problemati…
TrAiDoS
38 yo Retired SWE loo…
PurE)Rabbit-SF
Can Bots Beat Pros?? Starcr…
namkraft
[meme] I finally understa…
LUCKY_NOOB
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
Customize Sidebar...

Website Feedback

Closed Threads



Active: 10039 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
Zurich15366 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
34 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
34 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
Poland17843 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
34 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
Hyrule19257 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
19:00
S23 - Announcement Showmatch
Ret vs TerrOr
DragOn vs StRyKeR
ZZZero.O215
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 524
ProTech146
-ZergGirl 64
JuggernautJason33
StarCraft: Brood War
Shuttle 532
ZZZero.O 215
Dewaltoss 121
Trap 50
soO 18
zelot 7
Dota 2
monkeys_forever189
febbydoto9
League of Legends
Doublelift2396
JimRising 165
Counter-Strike
fl0m898
Heroes of the Storm
Liquid`Hasu696
Khaldor306
Other Games
Grubby3801
FrodaN2939
Liquid`RaSZi2433
summit1g767
B2W.Neo694
KnowMe202
XaKoH 174
ArmadaUGS135
Pyrionflax134
ZombieGrub70
CosmosSc2 26
Railgan24
Mew2King15
[ Show 15 non-featured ]
StarCraft 2
• mYiSmile125
• Reevou 9
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• FirePhoenix15
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota2488
League of Legends
• Shiphtur218
Other Games
• imaqtpie698
• Scarra584
Upcoming Events
Replay Cast
3h 33m
Afreeca Starleague
13h 33m
Shine vs Rush
WardiTV Weekly
14h 33m
Monday Night Weeklies
19h 33m
Sparkling Tuna Cup
1d 13h
Afreeca Starleague
1d 13h
Light vs EffOrt
OSC
1d 15h
PiGosaur Cup
2 days
Kung Fu Cup
2 days
The PondCast
3 days
[ Show More ]
Replay Cast
4 days
Korean StarCraft League
5 days
CranKy Ducklings
5 days
GSL
6 days
Yamato Cup
6 days
Liquipedia Results

Completed

K-JUNGMAN
Blizzard Classic Cup 2026
Big Dog Cup 2026 Div 1

Ongoing

ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
Acropolis #5
Acropolis #5 - GSA
Calamity Invitational
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5 - GSB
Acropolis #5 - GSC
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Copium Cup
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
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.