• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:38
CEST 15:38
KST 22:38
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Weekly Cups (June 30 - July 6): Classic Doubles1[BSL20] Non-Korean Championship 4x BSL + 4x China7Flash Announces Hiatus From ASL64Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event22
StarCraft 2
General
Weekly Cups (June 30 - July 6): Classic Doubles Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form?
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
SC uni coach streams logging into betting site BGH Auto Balance -> http://bghmmr.eu/ ASL20 Preliminary Maps Flash Announces Hiatus From ASL Player “Jedi” cheat on CSL
Tourneys
[BSL20] Grand Finals - Sunday 20:00 CET [BSL20] Non-Korean Championship 4x BSL + 4x China CSL Xiamen International Invitational The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread What do you want from future RTS games? 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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2024! Summer Games Done Quick 2025!
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 732 users

The Big Programming Thread - Page 298

Forum Index > General Forum
Post a Reply
Prev 1 296 297 298 299 300 1031 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
Bisutopia19229 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
Jollibee19343 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
Jollibee19343 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Wardi Open
11:00
#43
WardiTV1322
OGKoka 522
Harstem420
Rex169
IndyStarCraft 165
CranKy Ducklings122
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 522
Harstem 420
Hui .184
Rex 169
IndyStarCraft 165
StarCraft: Brood War
Bisu 3073
Flash 2328
Jaedong 1756
Hyuk 1094
firebathero 707
EffOrt 657
Larva 521
ZerO 478
actioN 454
Soulkey 441
[ Show more ]
Stork 397
Snow 306
Soma 298
GuemChi 163
Mind 133
sSak 118
Light 108
Pusan 106
PianO 94
Sharp 77
JulyZerg 75
hero 73
TY 65
Barracks 48
Sea.KH 44
Aegong 36
sorry 32
Free 29
zelot 27
GoRush 25
HiyA 24
soO 23
Movie 18
JYJ17
yabsab 17
Terrorterran 11
Shine 10
IntoTheRainbow 10
ivOry 5
Dota 2
qojqva3148
Gorgc2576
XaKoH 629
XcaliburYe297
syndereN293
League of Legends
singsing2583
Dendi1
Counter-Strike
byalli270
markeloff134
Super Smash Bros
Mew2King169
Other Games
hiko1144
B2W.Neo1069
crisheroes369
Beastyqt345
Lowko293
ArmadaUGS140
Liquid`VortiX70
ZerO(Twitch)20
Organizations
Other Games
gamesdonequick37693
StarCraft: Brood War
UltimateBattle 978
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2960
• WagamamaTV335
League of Legends
• Nemesis5594
Upcoming Events
RotterdaM Event
2h 22m
Replay Cast
10h 22m
Sparkling Tuna Cup
20h 22m
WardiTV European League
1d 2h
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
1d 10h
The PondCast
1d 20h
WardiTV European League
1d 22h
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
uThermal 2v2 Circuit
2 days
Replay Cast
2 days
RSL Revival
2 days
ByuN vs SHIN
Clem vs Reynor
[ Show More ]
Replay Cast
3 days
RSL Revival
3 days
Classic vs Cure
FEL
4 days
RSL Revival
4 days
FEL
4 days
FEL
5 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
6 days
BSL20 Non-Korean Champi…
6 days
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Liquipedia Results

Completed

BSL Season 20
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #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 © 2025 TLnet. All Rights Reserved.