• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:15
CET 19:15
KST 03: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
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? SnOw's ASL S20 Finals Review BW General Discussion Brood War web app to calculate unit interactions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 Beyond All Reason
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2038 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
Bisutopia19299 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
IPSL
17:00
Ro16 Group D
ZZZero vs rasowy
Napoleon vs KameZerg
Liquipedia
PSISTORM Gaming Misc
15:55
FSL teamleague CNvsASH, ASHvRR
Freeedom38
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Railgan 184
IndyStarCraft 110
BRAT_OK 47
MindelVK 29
EmSc Tv 13
StarCraft: Brood War
Britney 25290
Calm 2532
Shuttle 775
Stork 341
firebathero 288
Dewaltoss 113
Barracks 68
Mong 61
Rock 43
Shine 18
Dota 2
Gorgc5830
qojqva1713
Dendi963
Counter-Strike
ScreaM1084
byalli378
Heroes of the Storm
Khaldor535
Liquid`Hasu237
Other Games
Beastyqt573
DeMusliM291
Hui .222
Fuzer 215
Lowko213
Trikslyr46
CadenZie18
Organizations
Dota 2
PGL Dota 2 - Main Stream8971
Other Games
EGCTV625
gamesdonequick359
StarCraft 2
angryscii 24
EmSc Tv 13
EmSc2Tv 13
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• HappyZerGling 71
• HeavenSC 61
• printf 5
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• Kozan
• IndyKCrew
StarCraft: Brood War
• Airneanach42
• HerbMon 6
• Michael_bg 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2455
• WagamamaTV359
• Ler79
League of Legends
• Nemesis2825
Other Games
• imaqtpie1125
• Shiphtur313
Upcoming Events
OSC
45m
davetesta15
BSL 21
1h 45m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
15h 45m
RSL Revival
15h 45m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
17h 45m
Cure vs herO
Reynor vs TBD
WardiTV Korean Royale
17h 45m
BSL 21
1d 1h
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d 1h
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 4h
Wardi Open
1d 17h
[ Show More ]
Monday Night Weeklies
1d 22h
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
IPSL
6 days
Julia vs Artosis
JDConan vs DragOn
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
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 © 2025 TLnet. All Rights Reserved.