• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:19
CEST 18:19
KST 01:19
  • 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
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun11[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists22[ASL21] Ro16 Preview Pt1: Fresh Flow9
Community News
2026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced92026 GSL Tour plans announced15Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid25
StarCraft 2
General
Team Liquid Map Contest #22 - The Finalists Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid Maestros of the Game 2 announced
Tourneys
GSL Code S Season 1 (2026) SC2 INu's Battles#15 <BO.9 2Matches> WardiTV Spring Cup RSL Revival: Season 5 - Qualifiers and Main Event SEL Masters #6 - Solar vs Classic (SC: Evo)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base Mutation # 521 Memorable Boss
Brood War
General
Data needed Pros React To: Leta vs Tulbo (ASL S21, Ro.8) ASL21 General Discussion [TOOL] Starcraft Chat Translator JaeDong's ASL S21 Ro16 Post-Review
Tourneys
Escore Tournament StarCraft Season 2 [Megathread] Daily Proleagues [ASL21] Ro8 Day 2 [ASL21] Ro8 Day 1
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Daigo vs Menard Best of 10 Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV Diablo IV
Dota 2
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1981 users

The Big Programming Thread - Page 560

Forum Index > General Forum
Post a Reply
Prev 1 558 559 560 561 562 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.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
December 27 2014 22:27 GMT
#11181
On December 28 2014 04:11 CatNzHat wrote:
Show nested quote +
On December 26 2014 19:04 Manit0u wrote:
JS really needs some coherent way of writing code. Like you can use the semicolon but you can just as well not use it at all. And then you have to deal with code written by various people that mixes the styles and it's a mess even bigger than in the other languages that adhere to a much more strict way of doing things. And because in JS everything is an object you can chain everything and you end up working with lots of code violating the Single Responsibility Principle etc.

Seriously, JS scripts suffer from excessive code bloat more often than anything I've seen and debugging it is painful as hell.

JSLINT is your friend.

If you use the module design pattern you can more strictly adhere to SRP. The language is not at fault here, it's the programmers.

I've taken up JS very recently (although I had intention to for a long time) and I found it pretty easy. Of course, there is a big lack of well-established best practices in comparison to C/C++/Java.
In terms of debugging though. GOD BLESS JAVA AND JVM.
"windows bash is a steaming heap of shit" tofucake
Animzor
Profile Joined March 2011
Sweden2154 Posts
Last Edited: 2014-12-30 11:40:54
December 30 2014 01:41 GMT
#11182
zzdd
Profile Joined December 2010
United States484 Posts
December 30 2014 01:48 GMT
#11183
On December 30 2014 10:41 Animzor wrote:
Quick noob Java question:

I'm supposed to write a method that prints every phone number that belongs to two or more people. I have a person class, phone number class and each person has an arraylist with phone numbers. I have tried everything that I can think but I just can't figure this one out. I've gotten very close though by using nested for loops where I check if one person has the same number as another person, but it never works out. I feel like I'm overlooking some easy solution, if anyone can point me in the right direction I'd be grateful.

It might be easier to make the phone number have an arraylist of people and maybe a counter for how many people have that number. At least for that specific problem.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
December 30 2014 01:55 GMT
#11184
Inelegant solution would be to make two new lists. Iterate through each person and add numbers to the first list. If that number is already on the first list then add it to the second list (you'll have to check that it isn't already on the second list as well so you don't print duplicates). Then you can print the second list which will have all the numbers.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Animzor
Profile Joined March 2011
Sweden2154 Posts
Last Edited: 2014-12-30 11:41:05
December 30 2014 02:10 GMT
#11185
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2014-12-30 02:24:24
December 30 2014 02:14 GMT
#11186
On December 30 2014 10:41 Animzor wrote:
Quick noob Java question:

I'm supposed to write a method that prints every phone number that belongs to two or more people. I have a person class, phone number class and each person has an arraylist with phone numbers. I have tried everything that I can think but I just can't figure this one out. I've gotten very close though by using nested for loops where I check if one person has the same number as another person, but it never works out. I feel like I'm overlooking some easy solution, if anyone can point me in the right direction I'd be grateful.


For each person, for each phone number you could add the phone number to a hashset, it returns a boolean according to the existence in the hashset. If the add to the hashset isn't new, you can print the phone number.

If you want to use a hashset on a custom class you'll need to implement hashcode, just make sure to keep it consistent with equals.

On December 30 2014 11:10 Animzor wrote:
I forgot to add. I also need to list the people that the number belongs to like this:

number1, name, name, name
number2, name, name
number3, name, name, name, name

and I have to have an arraylist of numbers in the person class for other functions. This is just a small part of the program, I've finished everything else, but I can't figure this one out


If you also need the people , you could use HashMap<PhoneNumber, List<Person>>. If you loop once through all the people you can populate the map with the info, then loop over the hashmap looking for where the list.size() > 2. You'll still need to look at hashcode and equals if you want to use your custom phone number class as the key.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2014-12-30 09:00:22
December 30 2014 08:52 GMT
#11187
Make pairs of people and numbers, then group by numbers, then print all groups that have more than 1 element.
In C# using Linq:
void printNumbers(IEnumerable<Person> persons)
{
// for each person, makes as many pairs as the person has number
// then puts the pairs for all persons in a single list
var personNumberPairs = persons.SelectMany(p => p.Numbers.Select(n => new { Person = p, Number = n}));
var pairsGroupedByNumber = personNumberPairs.GroupBy(p => p.Number);
var pairsWithMoreThanOne = pairsGroupedByNumber.Where(p => p.Count() > 1);
foreach(var groupOfPairs in pairsWithMoreThanOne)
{
// print contents of groupOfPairs
// where number = groupOfPairs.Key
// and names = groupOfPairs.Select(g => g.Person.Name)
}
}

No idea how that translates into Java, does it have a proper Linq equivalent? In any case you need a remapping of the persons->numbers mapping so there can not be a trivial solution. In terms of steps required I think the above is as simple as it gets, with the HashMap solution above being pretty much the same thing in a more low level form.
If you have a good reason to disagree with the above, please tell me. Thank you.
Manit0u
Profile Blog Joined August 2004
Poland17740 Posts
Last Edited: 2014-12-30 10:12:25
December 30 2014 10:10 GMT
#11188
You need a 3-step process here:

1. Create a hash map. Populate map keys with all the numbers.
2. Iterate over persons and their numbers, add person as map value associated with number as key.
3. Iterate over your map populated with keys and values now to create a new map which only meets the criteria (ie: value has at least 2 names in it).
Time is precious. Waste it wisely.
xtorn
Profile Blog Joined December 2013
4060 Posts
December 30 2014 10:49 GMT
#11189
On December 30 2014 17:52 spinesheath wrote:
Make pairs of people and numbers, then group by numbers, then print all groups that have more than 1 element.
In C# using Linq:
void printNumbers(IEnumerable<Person> persons)
{
// for each person, makes as many pairs as the person has number
// then puts the pairs for all persons in a single list
var personNumberPairs = persons.SelectMany(p => p.Numbers.Select(n => new { Person = p, Number = n}));
var pairsGroupedByNumber = personNumberPairs.GroupBy(p => p.Number);
var pairsWithMoreThanOne = pairsGroupedByNumber.Where(p => p.Count() > 1);
foreach(var groupOfPairs in pairsWithMoreThanOne)
{
// print contents of groupOfPairs
// where number = groupOfPairs.Key
// and names = groupOfPairs.Select(g => g.Person.Name)
}
}

No idea how that translates into Java, does it have a proper Linq equivalent? In any case you need a remapping of the persons->numbers mapping so there can not be a trivial solution. In terms of steps required I think the above is as simple as it gets, with the HashMap solution above being pretty much the same thing in a more low level form.

nice one

instead of that last foreach tho

var result = pairsWithMoreThanOne.Select(t=> new { Number = t.Key, NamesBelonging = string.Join(",", t.Select(g => g.Person.Name)) });

i hate foreaches ,they're old and ugly
Life - forever the Legend in my heart
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2014-12-30 11:16:57
December 30 2014 11:06 GMT
#11190
You still have to print the result though:
var rows = pairsWithMoreThanOne.Select(p => p.Key + ", " + string.Join(", ", p.Select(g => g.Person.Name)));
var result = string.Join(Environment.NewLine, rows);
Console.WriteLine(result);

I usually try to pull as much code out of a foreach as I can reasonably do. Especially control flow statements. I still prefer foreach over anything that involves the keyword let in a Linq block though.

I'd also wrap the longer lambdas into Methods like such:
var rows = pairsWithMoreThanOne.Select(CreateRow);

string CreateRow(IGrouping<Number, Person> p)
{
return p.Key + ", " + string.Join(", ", p.Select(g => g.Person.Name));
}

Which separates the details of row layout from the other code, which is quite nice.
If you have a good reason to disagree with the above, please tell me. Thank you.
xtorn
Profile Blog Joined December 2013
4060 Posts
December 30 2014 11:26 GMT
#11191
yeah separation is cleaner more readable, and more unit testable (if this was something more complex, worthy of unit tests)

Life - forever the Legend in my heart
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-12-30 15:38:00
December 30 2014 14:27 GMT
#11192
@amnesty
i dl'ed visual15 preview today, and tried to get seq and abstract to compile.

am having some problems with constexpr when you expand a parameter pack through a constexpr function into an initializer list and return it, along the lines of:

template<class... T>
struct
F
{
static constexpr std::array<return_type_of_constexpr_func,sizeof(T...)>
apply()
{ return { constexpr_function<T>()... }; }
};


in addition it seems like the direct product (or coordinate function) is instantiating the 'wrong' specilalizations (different compared to gcc).

i'll have to take another stab at it later.
but it prompted me to rearrange the metastructure of the seq library in a saner fashion:

namespace seq{namespace guts{

template<class>
struct
metafun_impl;

template<class... arguments>
struct
metafun_impl<use arguments...>
{
...
};

}

template<class... arguments>
using metafun=guts::metafun_impl<...>;

}

trying to employ a naming convention along the lines of metafunction = indirect object, and metafunction parameter = direct object was rough, my vernacular was too feeble and the convention lead me into the borderlands of absurd identifiers.

see how he (the programmer) uses a spanner to tighten that nut
template<class>
struct
spanner;

template<class... descriptors>
struct
spanner<nut<descriptors...>>
{
...
};

template<class nut>
using tighten=typename spanner<nut>::output;

...

using too_tight_of_a_nut=tighten<already_tight_nut>;


disclaimer: i'm not very grammar, but the example shows what i mean.
conspired against by a confederacy of dunces.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
December 31 2014 22:28 GMT
#11193
Happy New Year guys! Less software bugs, more profit in the New Year!
Animzor
Profile Joined March 2011
Sweden2154 Posts
December 31 2014 23:28 GMT
#11194
On December 30 2014 19:10 Manit0u wrote:
You need a 3-step process here:

1. Create a hash map. Populate map keys with all the numbers.
2. Iterate over persons and their numbers, add person as map value associated with number as key.
3. Iterate over your map populated with keys and values now to create a new map which only meets the criteria (ie: value has at least 2 names in it).


This worked amazingly well btw. Thank you!
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2015-01-01 16:04:55
January 01 2015 14:09 GMT
#11195
finally got clang working on my computer, need to recompile gcc 4.10 as well.
variable templates, guuu.

[image loading]
src

instant disappointment, it doesn't seem very sfinae-friendly...
hope this is a bug and not the intended functionality!
#include<type_traits>

template<class argument>
constexpr bool condition=argument::output;

template<class argument,class=void>
struct
outer;

template<class argument>
struct
outer<argument,std::enable_if_t<condition<argument>>>
{ using output=int; };

template<class argument>
struct
outer<argument,std::enable_if_t<!condition<argument>>>
{ using output=float; };

template<class argument>
using inner=typename outer<argument>::output;

struct
argument
{ static constexpr bool output{false}; };

int
main()
{ inner<argument> value; }

clang++ -c -std=c++1y -I. -I../ -Wpedantic -Wfatal-errors -fdiagnostics-color -fmessage-length=64 -O2 work.cpp
work.cpp:55:1: fatal error: implicit instantiation of undefined
template 'outer<argument, void>'
using inner=typename outer<argument>::output;
^
work.cpp:64:2: note: in instantiation of template type alias
'inner' requested here
inner<argument> value;
^
work.cpp:42:2: note: template is declared here
outer;
^


surely outer<argument,std::enable_if_t<!argument::output>> ought to be instantiated, and not the primary template (if i define it that's the one that gets instantiated).
conspired against by a confederacy of dunces.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
January 01 2015 14:38 GMT
#11196
Haha, nunez you're so set on C++11/14. It's kind of pointless though because most (?) companies haven't caught up yet.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2015-01-01 15:09:32
January 01 2015 15:06 GMT
#11197
o ye of little faith! that is irrelevant before god.
be not anxious for your life, what ye may eat, and what ye may drink, nor for your body, what ye may put on.
seek ye first the reign of The Most Conforming Compiler and Its Righteousness, and all these shall be added to you.

i'm compiling fresh gcc now, it think it has support for variable templates.
if it agrees with me, and disagrees with the verdict of the Clang, i will cast the Clang back into the abyss.
conspired against by a confederacy of dunces.
ZenithM
Profile Joined February 2011
France15952 Posts
Last Edited: 2015-01-01 16:19:59
January 01 2015 16:18 GMT
#11198
I just spent several hours tinkering with GC options on the JVM to get my shit to work. One piece of advice for those who like me are pretty sure they don't have any memory leak in their code (mine was in Scala and it's pretty easy to code so that you don't leak in that language ;D) and whose program ends up running full GCs for nothing like 100% of the computing time: start thinking about tuning the GC. I mean, think about it last, but don't forget to think about it either, because that would be a mistake

Oh and happy new year guys!
netherh
Profile Blog Joined November 2011
United Kingdom333 Posts
Last Edited: 2015-01-01 17:21:49
January 01 2015 17:20 GMT
#11199
On January 01 2015 23:09 nunez wrote:
instant disappointment, it doesn't seem very sfinae-friendly...
hope this is a bug and not the intended functionality!

<snip>



This works on whatever version of gcc Coliru uses, if you get rid of the bool template variable: http://coliru.stacked-crooked.com/a/dd147352e035c760

You could just do this, though: http://coliru.stacked-crooked.com/a/e17282b0b18b948d

I find the direction C++ is going in a little odd. vector<bool> doesn't even work properly, but sure lets have constexpr and template variables, and enable_if all over the place.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2015-01-01 19:23:52
January 01 2015 17:44 GMT
#11200
sorry i misread.
you had removed the variable template: the raison d'etre of my prayer.
coliru uses 4.9.2 (__VERSION__ macro), so i didn't bother checking it earlier (since i thought it was the same i had on my puter).

i will not forsake clang yet.

my wish was exactly not to do any of those.

actually my real wish is to use variable templates instead of constexpr functions to call value metafunctions in my little seq library, so that value metafunction calls and type metafunction calls have uniform syntax.

i agree with your critique, it's odd how there are things, and also other things at the same time.

edit:
same result in gcc-5.0, however there's already a bugreport: src. i believe the author has his shit together, so i will conclude it is indeed a bug, and not the intended semantic, and will have to wait a bit longer... actually it's not quite the same. clang accepts his code, but not mine.
conspired against by a confederacy of dunces.
Prev 1 558 559 560 561 562 1032 Next
Please log in or register to reply.
Live Events Refresh
Big Brain Bouts
16:00
#114
TriGGeR vs Percival
RotterdaM775
Liquipedia
OSC
13:00
King of the Hill #246
WardiTV678
TKL 261
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 775
TKL 261
MindelVK 24
JuggernautJason24
ProTech23
UpATreeSC 21
StarCraft: Brood War
Britney 35576
Calm 5046
Sea 2347
Mini 773
Shuttle 557
firebathero 441
EffOrt 363
BeSt 264
Leta 236
ggaemo 233
[ Show more ]
Hyuk 187
Hyun 108
Dewaltoss 96
Sharp 91
ToSsGirL 51
Sea.KH 45
Hm[arnc] 44
Barracks 32
Free 30
Rock 25
yabsab 22
scan(afreeca) 20
Terrorterran 16
910 16
GoRush 14
Shine 14
IntoTheRainbow 12
SilentControl 12
Sacsri 9
JulyZerg 7
Dota 2
Gorgc5540
qojqva1951
monkeys_forever326
syndereN263
Other Games
Grubby4253
singsing2184
FrodaN913
B2W.Neo857
hiko761
Hui .172
crisheroes171
ArmadaUGS88
QueenE74
ViBE71
Trikslyr44
KnowMe29
Organizations
Dota 2
PGL Dota 2 - Main Stream60
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• Adnapsc2 14
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis3911
Other Games
• WagamamaTV301
• Shiphtur211
Upcoming Events
Replay Cast
7h 41m
Replay Cast
16h 41m
RSL Revival
17h 41m
Classic vs GgMaChine
Rogue vs Maru
WardiTV Invitational
18h 41m
Percival vs Shameless
ByuN vs YoungYakov
IPSL
23h 41m
Ret vs Art_Of_Turtle
Radley vs TBD
BSL
1d 2h
Replay Cast
1d 7h
RSL Revival
1d 17h
herO vs TriGGeR
NightMare vs Solar
uThermal 2v2 Circuit
1d 21h
BSL
2 days
[ Show More ]
IPSL
2 days
eOnzErG vs TBD
G5 vs Nesh
Patches Events
2 days
Replay Cast
2 days
Wardi Open
2 days
Afreeca Starleague
2 days
Jaedong vs Light
Monday Night Weeklies
2 days
Replay Cast
3 days
Sparkling Tuna Cup
3 days
Afreeca Starleague
3 days
Snow vs Flash
WardiTV Invitational
3 days
GSL
4 days
Classic vs Cure
Maru vs Rogue
GSL
5 days
SHIN vs Zoun
ByuN vs herO
Replay Cast
6 days
Escore
6 days
The PondCast
6 days
WardiTV Invitational
6 days
Liquipedia Results

Completed

Proleague 2026-04-30
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Escore Tournament S2: W5
KK 2v2 League Season 1
SCTL 2026 Spring
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
RSL Revival: Season 5
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
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.