• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 05:41
CEST 11:41
KST 18:41
  • 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 TLMC #5 - Finalists & Open Tournaments0[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon9[ASL20] Ro16 Preview Pt1: Ascent10Maestros of the Game: Week 1/Play-in Preview12
Community News
BSL 2025 Warsaw LAN + Legends Showmatch0Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8Weekly Cups (Sept 1-7): MaxPax rebounds & Clem saga continues29
StarCraft 2
General
#1: Maru - Greatest Players of All Time Weekly Cups (Sept 8-14): herO & MaxPax split cups Team Liquid Map Contest #21 - Presented by Monster Energy SpeCial on The Tasteless Podcast Team TLMC #5 - Finalists & Open Tournaments
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris Sparkling Tuna Cup - Weekly Open Tournament SC4ALL $6,000 Open LAN in Philadelphia WardiTV TL Team Map Contest #5 Tournaments RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense Mutation # 488 What Goes Around
Brood War
General
Soulkey on ASL S20 ASL TICKET LIVE help! :D BW General Discussion NaDa's Body A cwal.gg Extension - Easily keep track of anyone
Tourneys
[ASL20] Ro16 Group D [ASL20] Ro16 Group C [Megathread] Daily Proleagues BSL 2025 Warsaw LAN + Legends Showmatch
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Borderlands 3 General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread UK Politics Mega-thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
I <=> 9
KrillinFromwales
The Personality of a Spender…
TrAiDoS
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1589 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
Bisutopia19262 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 19m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Rex 1
StarCraft: Brood War
Calm 5699
Bisu 731
Hyuk 162
HiyA 96
Hyun 96
sorry 86
ToSsGirL 84
Dewaltoss 82
Pusan 77
Light 74
[ Show more ]
Soma 60
actioN 56
Mini 49
ZerO 32
BeSt 30
Liquid`Ret 29
Nal_rA 28
soO 27
Sharp 24
Rush 19
Free 16
SilentControl 10
Dota 2
singsing1260
XcaliburYe206
boxi98170
League of Legends
JimRising 381
Counter-Strike
olofmeister1583
shoxiejesuss598
allub166
Other Games
XaKoH 143
NeuroSwarm80
Trikslyr15
Organizations
StarCraft: Brood War
lovetv 593
Other Games
gamesdonequick587
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1421
• Stunt679
Other Games
• WagamamaTV81
Upcoming Events
RSL Revival
19m
Maru vs Reynor
Cure vs TriGGeR
Rex1
Map Test Tournament
1h 19m
The PondCast
3h 19m
RSL Revival
1d
Zoun vs Classic
Korean StarCraft League
1d 17h
BSL Open LAN 2025 - War…
1d 22h
RSL Revival
2 days
BSL Open LAN 2025 - War…
2 days
RSL Revival
3 days
Online Event
3 days
[ Show More ]
Wardi Open
4 days
Monday Night Weeklies
4 days
Sparkling Tuna Cup
5 days
LiuLi Cup
6 days
Liquipedia Results

Completed

Proleague 2025-09-10
Chzzk MurlocKing SC1 vs SC2 Cup #2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
LASL Season 20
RSL Revival: Season 2
Maestros of the Game
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

Upcoming

2025 Chongqing Offline CUP
BSL World Championship of Poland 2025
IPSL Winter 2025-26
BSL Season 21
SC4ALL: Brood War
BSL 21 Team A
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
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.