• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:15
CET 12:15
KST 20:15
  • 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
Team Liquid Map Contest #22 - Presented by Monster Energy5ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13
Community News
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool31Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains18
StarCraft 2
General
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Potential Updates Coming to the SC2 CN Server Weekly Cups (March 2-8): ByuN overcomes PvT block Weekly Cups (August 25-31): Clem's Last Straw? Weekly Cups (March 9-15): herO, Clem, ByuN win
Tourneys
World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament WardiTV Team League Season 10 KSL Week 87
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 517 Distant Threat Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Gypsy to Korea JaeDong's form before ASL BSL Season 22
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours Small VOD Thread 2.0 IPSL Spring 2026 is here!
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread Mexico's Drug War
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books Movie Discussion! [Manga] One Piece
Sports
2024 - 2026 Football Thread Cricket [SPORT] Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 4384 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
Bisutopia19316 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
RSL Revival
10:00
Season 4: Playoffs Day 2
Rogue vs TriGGeRLIVE!
Tasteless1015
IndyStarCraft 153
Rex106
CranKy Ducklings68
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Tasteless 1015
IndyStarCraft 153
ProTech126
Rex 106
StarCraft: Brood War
Sea 17553
Calm 9118
Britney 8134
Hyuk 2076
Jaedong 1397
Horang2 1394
BeSt 969
firebathero 621
EffOrt 592
Larva 470
[ Show more ]
Mong 446
Flash 397
actioN 346
Light 227
Hm[arnc] 168
Last 140
Soma 129
Rush 122
Mind 88
Pusan 73
Aegong 64
ZerO 55
Barracks 41
Yoon 41
hero 38
ToSsGirL 31
GoRush 30
NotJumperer 30
zelot 28
sorry 25
Free 22
IntoTheRainbow 19
Terrorterran 16
Noble 15
SilentControl 14
910 12
Bale 9
Sea.KH 8
ivOry 4
eros_byul 1
Dota 2
XaKoH 750
XcaliburYe247
Counter-Strike
zeus480
fl0m436
x6flipin184
edward23
Heroes of the Storm
MindelVK15
Other Games
singsing2680
B2W.Neo527
Fuzer 181
Sick125
DeMusliM86
ZerO(Twitch)18
Organizations
Other Games
gamesdonequick542
Dota 2
PGL Dota 2 - Main Stream156
Other Games
BasetradeTV66
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH254
• 3DClanTV 71
• CranKy Ducklings SOOP4
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos352
Upcoming Events
LAN Event
4h 45m
BSL
8h 45m
Replay Cast
12h 45m
Replay Cast
21h 45m
Afreeca Starleague
22h 45m
Sharp vs Scan
Rain vs Mong
Wardi Open
1d
Monday Night Weeklies
1d 5h
Sparkling Tuna Cup
1d 22h
Afreeca Starleague
1d 22h
Soulkey vs Ample
JyJ vs sSak
Replay Cast
2 days
[ Show More ]
Afreeca Starleague
2 days
hero vs YSC
Larva vs Shine
Kung Fu Cup
2 days
Replay Cast
3 days
KCM Race Survival
3 days
The PondCast
3 days
WardiTV Team League
4 days
Replay Cast
4 days
WardiTV Team League
5 days
RSL Revival
5 days
Cure vs Zoun
WardiTV Team League
6 days
BSL
6 days
RSL Revival
6 days
ByuN vs Maru
Liquipedia Results

Completed

Jeongseon Sooper Cup
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
CSL 2026 SPRING (S20)
CSL Season 20: Qualifier 1
Acropolis #4
IPSL Spring 2026
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 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.