• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 05:49
CET 11:49
KST 19:49
  • 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: 2263 users

The Big Programming Thread - Page 298

Forum Index > General Forum
Post a Reply
Prev 1 296 297 298 299 300 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.
BisuDagger
Profile Blog Joined October 2009
Bisutopia19300 Posts
May 10 2013 17:36 GMT
#5941
Has anyone used the havoc engine? I am going to tinkering with it this weekend and need good tutorials or advice.
ModeratorFormer Afreeca Starleague Caster: http://afreeca.tv/ASL2ENG2
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
May 10 2013 17:59 GMT
#5942
On May 10 2013 09:18 berated- wrote:
Show nested quote +
On May 10 2013 07:47 thOr6136 wrote:
Hey, i have a problem.

So, java. Summing up a task first: 300 txt files with dates and temperatures over 10 years. I have to read all the temperatures and add them into maps with different kind of keys, for value we use List<Double> for storing temperatures. So basically we have to make 4 kind of maps with different kind of keys. One key is Location (name of file) other one is Location + year etc. After that we have to make another set of maps - keys equivalent to the ones before only values have to be different. This time we need double array (List before) with 2 values in it, one is an average value of all temperatures in that list (from map from before). Now here i have a problem.

I use a method for generating a new HashMap with same keys as before but different kind of values (double arrays). The problem is, when i add keys to the new map i am creating (i use put(key, value)) it overwrites values from before but the key is completely different. It shouldn't happen because put method always compares 2 keys with equals() method and it compares hashCode(). When i debug the key that i input in put method is always different, but values get overwritten each time. It's so strange... Anyway i can post a code of this part:


public static HashMap<String, double[]> averages(HashMap<String, List<Double>> map)
{
HashMap<String, double[]> mapAverage = new HashMap<>();
double[] x = new double[2];

for(Map.Entry<String, List<Double>> entry : map.entrySet())
{
// if i System.out.println(key); all keys are different
String key = entry.getKey();
//used to generate average number of all temperatures in list
x[0] = povprecje(entry.getValue(), key);
//used to generate something else
x[1] = odmik(entry.getValue(), key, x[0]);
mapAverage.put(key, x);
}
return mapAverage;
}


Is there anything that could make overwriting all the values from before in map? Or am i missing something in this part?


You need to move the double[] creation to within the for loop.

Even though you are putting new values in the array, you are putting the same array into each entry into the map.


Yep, thats precisely correct. If you read it in its current form, there is only one call to "new double[2]" for the entire map, meaning that there is only memory allocated for one of these double[2] objects in the heap. By adding the line "x = new double[2]" to within the for loop, you are allocating N double[2] objects, so they won't all be the same reference. When x is assigned to a new object, since the old object is still referenced within the Map, the garbage collection won't be picking it up.


+ Show Spoiler +
Your dataset isn't too large, but if this code is taking too long, then you can try to optimize it by allocating a very large piece of the heap near the start of the function, then chopping it up and giving the map sequential 16 byte values from that allocated memory. I don't remember a good way to do that in Java....
Any sufficiently advanced technology is indistinguishable from magic
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
May 10 2013 19:14 GMT
#5943
On May 10 2013 07:47 thOr6136 wrote:
Hey, i have a problem.

So, java. Summing up a task first: 300 txt files with dates and temperatures over 10 years. I have to read all the temperatures and add them into maps with different kind of keys, for value we use List<Double> for storing temperatures. So basically we have to make 4 kind of maps with different kind of keys. One key is Location (name of file) other one is Location + year etc. After that we have to make another set of maps - keys equivalent to the ones before only values have to be different. This time we need double array (List before) with 2 values in it, one is an average value of all temperatures in that list (from map from before). Now here i have a problem.

I use a method for generating a new HashMap with same keys as before but different kind of values (double arrays). The problem is, when i add keys to the new map i am creating (i use put(key, value)) it overwrites values from before but the key is completely different. It shouldn't happen because put method always compares 2 keys with equals() method and it compares hashCode(). When i debug the key that i input in put method is always different, but values get overwritten each time. It's so strange... Anyway i can post a code of this part:


public static HashMap<String, double[]> averages(HashMap<String, List<Double>> map)
{
HashMap<String, double[]> mapAverage = new HashMap<>();
double[] x = new double[2];

for(Map.Entry<String, List<Double>> entry : map.entrySet())
{
// if i System.out.println(key); all keys are different
String key = entry.getKey();
//used to generate average number of all temperatures in list
x[0] = povprecje(entry.getValue(), key);
//used to generate something else
x[1] = odmik(entry.getValue(), key, x[0]);
mapAverage.put(key, x);
}
return mapAverage;
}


Is there anything that could make overwriting all the values from before in map? Or am i missing something in this part?


This has nothing to do with your problem, but parsing the files part sounds like a job for grep -r with some regex's. All you'd have to do is pipe its output to java. Not sure if that's possible. Anyway, just an idea!
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-05-10 19:49:55
May 10 2013 19:47 GMT
#5944
I'm curious what the most useful/efficient approach is when it comes to using threads.

A. Cached pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool() (you re-use threads)
B. Worker/dispatcher threads
C. Fixed thread pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool(int)
D. Other (specify please)

I guess it depends on the application, e.g. you may want worker/dispatcher threads for servers, while cached pool could work for desktop & servers.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
May 10 2013 21:18 GMT
#5945
On May 11 2013 04:47 darkness wrote:
I'm curious what the most useful/efficient approach is when it comes to using threads.

A. Cached pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool() (you re-use threads)
B. Worker/dispatcher threads
C. Fixed thread pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool(int)
D. Other (specify please)

I guess it depends on the application, e.g. you may want worker/dispatcher threads for servers, while cached pool could work for desktop & servers.


This is a totally OS and application dependent question. If you want to PM me some specifics, I can lay down the knowledge.
Any sufficiently advanced technology is indistinguishable from magic
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
May 10 2013 21:22 GMT
#5946
oooh can you post your discussions here? i want to drink on them knowledge
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-05-10 21:43:41
May 10 2013 21:37 GMT
#5947
On May 11 2013 06:18 RoyGBiv_13 wrote:
Show nested quote +
On May 11 2013 04:47 darkness wrote:
I'm curious what the most useful/efficient approach is when it comes to using threads.

A. Cached pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool() (you re-use threads)
B. Worker/dispatcher threads
C. Fixed thread pool like - http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool(int)
D. Other (specify please)

I guess it depends on the application, e.g. you may want worker/dispatcher threads for servers, while cached pool could work for desktop & servers.


This is a totally OS and application dependent question. If you want to PM me some specifics, I can lay down the knowledge.


I was asking in general, but if you feel like you want to explain, then I'd be happy to read.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
May 10 2013 22:02 GMT
#5948
I started typing up a wall of text, then realized I should probably be doing my work instead =P. I'll edit this post with the knowledge bomb after I get home today.

They say you don't really know a subject until you can teach it...
Any sufficiently advanced technology is indistinguishable from magic
Release
Profile Blog Joined October 2010
United States4397 Posts
May 11 2013 02:18 GMT
#5949
In light of recent discussion in this thread, is a computer science bachelor degree worth pursuing if I'm interested in programming in the future? Or should I major in something else (finance/engineering for example) and program on my own time?
☺
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
May 11 2013 02:23 GMT
#5950
as a CS major, there are a LOT of stuff aside from programming. you got to learn data structures, algorithms, AI, etc.

a bad analogy that i can think of is that anybody can shoot a ball to a hoop but not all can play basketball (or in the nba?)


Lol terrible
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
May 11 2013 02:29 GMT
#5951
On May 11 2013 11:18 Release wrote:
In light of recent discussion in this thread, is a computer science bachelor degree worth pursuing if I'm interested in programming in the future? Or should I major in something else (finance/engineering for example) and program on my own time?


You should major at something you like...
"When the geyser died, a probe came out" - SirJolt
snakeeyez
Profile Joined May 2011
United States1231 Posts
May 11 2013 03:06 GMT
#5952
You know in some ways turning a hobby or something you like into your real job can really burn you out on it. I would just say try to get some real world experience at what you want to do or talk to a few people that do it everyday for years to see what they say.
When I get home from programming all day the last thing I want to do is sit at a computer anymore let alone think or program something. The thing is though I still have stuff I want to do on my computer or do things I want to do that I cant do the whole day at work. It can be rough sometimes.
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2013-05-11 04:53:26
May 11 2013 04:52 GMT
#5953
Having a job you like is one of the keys to a happy life*. If you don't want to do it more when you get home, that's fine. But being able to do something you actually enjoy for ~8 hours every day instead of being forced to do shit you don't like... way better

* other components here would be: a job that you're good at, and a job that has some market. Simply liking it isn't sufficient.
Who after all is today speaking about the destruction of the Armenians?
GunSec
Profile Joined February 2010
1095 Posts
May 11 2013 19:31 GMT
#5954
So I wanted to create a very easy snooker game in python where you just randomise the colors and output either yellow,green,brown,blue,pink,black. My code is working fine but I have no idea if the random seed is actually random every time I run the function. Can someone explain if this is correct? I don't think I understand the weighted distribution here..

import random
def snookerGame():
colored_Balls = [('Yellow',1),('Green',1),('Brown',1),('Blue',1),('Pink',1),('Black',1)]
potted = [val for val, potted in colored_Balls for i in range(potted)]
print(random.choice(potted))

I got my inspiration here in the end of the page: http://docs.python.org/3/library/random.html

GunSec
Profile Joined February 2010
1095 Posts
May 11 2013 19:42 GMT
#5955
btw, I am also wondering if I can pm some of the moderators of this thread or the creator? I have some personal stuff I want to talk about in programming and computer science in general !
bangsholt
Profile Joined June 2011
Denmark138 Posts
May 11 2013 19:49 GMT
#5956
Suppose you have read this python doc, so yes, it should be random. Just remember that we in general are very bad at understanding random.
phar
Profile Joined August 2011
United States1080 Posts
May 11 2013 20:20 GMT
#5957
On May 12 2013 04:42 GunSec wrote:
btw, I am also wondering if I can pm some of the moderators of this thread or the creator? I have some personal stuff I want to talk about in programming and computer science in general !

Don't think many mods or the creator post here often...

Many here could probably field answers, but it's hard to say exactly without knowing what your line of questioning is about.
Who after all is today speaking about the destruction of the Armenians?
GunSec
Profile Joined February 2010
1095 Posts
May 11 2013 20:25 GMT
#5958
On May 12 2013 05:20 phar wrote:
Show nested quote +
On May 12 2013 04:42 GunSec wrote:
btw, I am also wondering if I can pm some of the moderators of this thread or the creator? I have some personal stuff I want to talk about in programming and computer science in general !

Don't think many mods or the creator post here often...

Many here could probably field answers, but it's hard to say exactly without knowing what your line of questioning is about.


well do you know who of them are responding to pm's or maybe I should try to pm all of them? I was just going to ask a few questions about computer science education and some personals problems about failing in programming etc.
phar
Profile Joined August 2011
United States1080 Posts
May 11 2013 20:47 GMT
#5959
I can try to answer I guess, not sure if I'll be able to give satisfactory answers.
Who after all is today speaking about the destruction of the Armenians?
CatNzHat
Profile Blog Joined February 2011
United States1599 Posts
May 11 2013 20:51 GMT
#5960
On May 12 2013 04:49 bangsholt wrote:
Suppose you have read this python doc, so yes, it should be random. Just remember that we in general are very bad at understanding random.


For the purposes of the game, python random will work fine. It's not like SecureRandom in Java, if you want to learn more about random number generators and their various levels of security (how random they actually are, what they use for seeds, etc..) then ask away.
Prev 1 296 297 298 299 300 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
09:00
WardiTV Mondays #68
CranKy Ducklings175
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Rex 43
StarCraft: Brood War
Rain 2426
Horang2 1724
Hyuk 1581
Larva 535
actioN 496
BeSt 367
Mini 205
EffOrt 180
Zeus 154
Light 146
[ Show more ]
Barracks 132
ZerO 117
Pusan 101
Leta 99
ggaemo 94
Killer 86
Mong 63
Rush 60
Mind 59
sorry 53
Aegong 51
Snow 46
Sharp 40
910 29
Yoon 25
JulyZerg 23
Movie 23
Free 23
Sacsri 20
Noble 15
soO 15
zelot 14
Dota 2
ODPixel367
NeuroSwarm91
XcaliburYe57
canceldota56
League of Legends
JimRising 479
C9.Mang0325
Counter-Strike
shoxiejesuss854
allub317
Other Games
singsing813
ceh9559
Pyrionflax307
crisheroes123
Livibee94
ZerO(Twitch)8
Organizations
Other Games
gamesdonequick4362
StarCraft 2
WardiTV14
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Berry_CruncH186
• StrangeGG 43
• LUISG 31
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 13
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt860
• HappyZerGling152
Upcoming Events
Wardi Open
3h 12m
Monday Night Weeklies
6h 12m
WardiTV Invitational
1d 1h
WardiTV Invitational
2 days
The PondCast
2 days
OSC
3 days
OSC
4 days
All Star Teams
4 days
INnoVation vs soO
sOs vs Scarlett
uThermal 2v2 Circuit
5 days
All Star Teams
5 days
MMA vs DongRaeGu
Rogue vs Oliveira
[ Show More ]
Sparkling Tuna Cup
5 days
OSC
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-01-11
Big Gabe Cup #3
NA Kuram Kup

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
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.