• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 10:59
CEST 16:59
KST 23:59
  • 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 1 - Final Week6[ASL19] Finals Recap: Standing Tall12HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Weekly Cups (July 7-13): Classic continues to roll2Team TLMC #5 - Submission extension1Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced7Weekly Cups (June 30 - July 6): Classic Doubles7
StarCraft 2
General
RSL Revival patreon money discussion thread Weekly Cups (July 7-13): Classic continues to roll Esports World Cup 2025 - Final Player Roster TL Team Map Contest #5: Presented by Monster Energy Team TLMC #5 - Submission extension
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event RSL: Revival, a new crowdfunded tournament series $5,100+ SEL Season 2 Championship (SC: Evo) WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
External Content
Mutation # 482 Wheel of Misfortune Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome
Brood War
General
Flash Announces Hiatus From ASL BW General Discussion A cwal.gg Extension - Easily keep track of anyone [Guide] MyStarcraft [ASL19] Finals Recap: Standing Tall
Tourneys
CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China [Megathread] Daily Proleagues 2025 ACS Season 2 Qualifier
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile CCLP - Command & Conquer League Project The PlayStation 5
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 HOW TO HIRE A HACKER TO RECOVER STOLEN BITCOIN. Russo-Ukrainian War Thread Summer Games Done Quick 2025! Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion 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
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 607 users

The Big Programming Thread - Page 686

Forum Index > General Forum
Post a Reply
Prev 1 684 685 686 687 688 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.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 03 2015 17:34 GMT
#13701
On December 04 2015 00:01 WarSame wrote:
And for this reason I believe that I do need a min node class.

You could also implement a MinStack by wrapping 2 stacks into a single class. One acts as the normal stack, one holds the min values. Each time you push/pop you do so for both stacks.
If you have a good reason to disagree with the above, please tell me. Thank you.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 03 2015 17:39 GMT
#13702
Now there's an idea! That sounds really good. I'll give that a shot.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Aerisky
Profile Blog Joined May 2012
United States12129 Posts
Last Edited: 2015-12-03 19:39:02
December 03 2015 19:16 GMT
#13703
Is it worth doing a very long (4+ hours according to the recruiter, and looking at the spec I can definitely see why) coding challenge which I don't feel like I would be able to do properly anyway? I have finals coming up and assignments due still, and honestly if I thought I'd be able to do it reasonably well I would definitely go ahead and do it anyway (learning opportunity, it's not harmful, chance at interview, etc).

However I just feel like that's an awful lot of time to be spending on a coding challenge I couldn't complete, when I have other shit due. It's hexagonal text search if anyone else has ever heard of it. But then I'd feel bad just leaving it/the learning opportunity... Time is an issue because they want it back today (so I can't ask to wait until after exams and whatnot). :S
Jim while Johnny had had had had had had had; had had had had the better effect on the teacher.
solidbebe
Profile Blog Joined November 2010
Netherlands4921 Posts
December 03 2015 21:57 GMT
#13704
Why not just focus on your assignments and finals and try your hand at the challenge on your own some other time?
That's the 2nd time in a week I've seen someone sig a quote from this GD and I have never witnessed a sig quote happen in my TL history ever before. -Najda
Acrofales
Profile Joined August 2010
Spain17975 Posts
Last Edited: 2015-12-03 22:13:50
December 03 2015 22:12 GMT
#13705
On December 04 2015 02:10 WarSame wrote:
Alright a much simpler question this time: they have a Tower of Hanoi example,but I think it might be wrong. They say, as one of the requirements: " A disk is slid off the top of one rod onto the next rod" so you can only go from tower 1 to 2 and 2 to 3 or the reverse. However, in their solution they seem to ignore this - they move all their disks except the bottom to the buffer tower, and then move the very bottom disk to the destination tower. This means that they skip tower 1, and move it from tower 1 to 3, which violates the requirement. Am I going crazy or is this an error? If you'd like me to paste the solution they have then let me know.

Hanoi is unsolvable if that requirement you say exists. You can move any disk from any tower to any other tower, as long as it doesn't end up on a disk that's smaller than it. Now go back to programming recursion in Java (yeuch)!
Prillan
Profile Joined August 2011
Sweden350 Posts
Last Edited: 2015-12-03 23:02:52
December 03 2015 23:00 GMT
#13706
On December 04 2015 07:12 Acrofales wrote:
Show nested quote +
On December 04 2015 02:10 WarSame wrote:
Alright a much simpler question this time: they have a Tower of Hanoi example,but I think it might be wrong. They say, as one of the requirements: " A disk is slid off the top of one rod onto the next rod" so you can only go from tower 1 to 2 and 2 to 3 or the reverse. However, in their solution they seem to ignore this - they move all their disks except the bottom to the buffer tower, and then move the very bottom disk to the destination tower. This means that they skip tower 1, and move it from tower 1 to 3, which violates the requirement. Am I going crazy or is this an error? If you'd like me to paste the solution they have then let me know.

Hanoi is unsolvable if that requirement you say exists. You can move any disk from any tower to any other tower, as long as it doesn't end up on a disk that's smaller than it. Now go back to programming recursion in Java (yeuch)!


You sure? I'm pretty sure it's still solvable.

https://en.wikipedia.org/wiki/Tower_of_Hanoi#Graphical_representation
Incidentally, this longest non-repetitive path can be obtained by forbidding all moves from a to b.

Since forbidding moves from a to c is clearly symmetric to forbidding moves from a to b, there must be a solution.

Furthermore, this solution is maximal in the sense that it solves the problem while taking the most amount of moves without repeating any states.
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Aerisky
Profile Blog Joined May 2012
United States12129 Posts
Last Edited: 2015-12-03 23:10:24
December 03 2015 23:09 GMT
#13707
On December 04 2015 06:57 solidbebe wrote:
Why not just focus on your assignments and finals and try your hand at the challenge on your own some other time?

Recruiter got back to me and mentioned I could do it later if I wanted, so I'll probably just go ahead and do that, yeah
Jim while Johnny had had had had had had had; had had had had the better effect on the teacher.
Acrofales
Profile Joined August 2010
Spain17975 Posts
December 03 2015 23:36 GMT
#13708
On December 04 2015 08:00 Prillan wrote:
Show nested quote +
On December 04 2015 07:12 Acrofales wrote:
On December 04 2015 02:10 WarSame wrote:
Alright a much simpler question this time: they have a Tower of Hanoi example,but I think it might be wrong. They say, as one of the requirements: " A disk is slid off the top of one rod onto the next rod" so you can only go from tower 1 to 2 and 2 to 3 or the reverse. However, in their solution they seem to ignore this - they move all their disks except the bottom to the buffer tower, and then move the very bottom disk to the destination tower. This means that they skip tower 1, and move it from tower 1 to 3, which violates the requirement. Am I going crazy or is this an error? If you'd like me to paste the solution they have then let me know.

Hanoi is unsolvable if that requirement you say exists. You can move any disk from any tower to any other tower, as long as it doesn't end up on a disk that's smaller than it. Now go back to programming recursion in Java (yeuch)!


You sure? I'm pretty sure it's still solvable.

https://en.wikipedia.org/wiki/Tower_of_Hanoi#Graphical_representation
Show nested quote +
Incidentally, this longest non-repetitive path can be obtained by forbidding all moves from a to b.

Since forbidding moves from a to c is clearly symmetric to forbidding moves from a to b, there must be a solution.

Furthermore, this solution is maximal in the sense that it solves the problem while taking the most amount of moves without repeating any states.


Actually, you might be right. I always think in terms of minimal solution, which is impossible, but I guess you could move entire towers back and forth multiple times. For instance, take a tower of 2: under normal rules you move
1: a -> b
2: a -> c
3: b-> c
Done.

Under these rules, you have to move:

1: a->b
2: b->c
3: a->b
4: c->b
5: b->a
6: b->c
7: a->b
8: b->c

I don't see any point in this restriction. It adds an exponential number of pointless moves without actually teaching you anything about recursion or dynamic programming that the first method doesn't. But I do admit I was wrong: Hanoi is still solvable (or at least, my most immediate objection to why it is invalid: you CAN move entire towers one by one back and forth on top of each other, it's just tedious).
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 03 2015 23:44 GMT
#13709
Yeah, I saw that it was solvable with that restriction, but honestly had no clue how the fuck you would program that. The actual Tower of Hanoi is still fairly difficult, but actually possible to program. Thanks for the response. It was just me being stupid, then.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
TheNewEra
Profile Joined March 2011
Germany3128 Posts
Last Edited: 2015-12-04 00:29:46
December 04 2015 00:28 GMT
#13710
Sorry if this is not the right thread for my kind of question:

I'm currently thinking about buying an Arduino Starter Kit. Does anyone have experience with it? There seem to be quite a lot of imitiations( not sure if the right word) with some of them costing only half of what the Starter Kit does. Is it worth it to pay the full prize for the original Arduino kit or can anybody recommend another one? I'm a bit overwhelmed. You seem to have an awful lot of options to basically either buy the original Starter kit, a 3rd part version of it, or just assemble your own kit by buying elements on their own.
Midas <3 Casy <3 BeSt <3 | Pray to Doh-men, heathens! | Zwischen Harz und Heideland
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-12-04 00:38:44
December 04 2015 00:37 GMT
#13711
On December 04 2015 08:44 WarSame wrote:
Yeah, I saw that it was solvable with that restriction, but honestly had no clue how the fuck you would program that. The actual Tower of Hanoi is still fairly difficult, but actually possible to program. Thanks for the response. It was just me being stupid, then.


The Tower of Hanoi solution should just be a decision tree. Same way you would solve Tic-Tac-Toe.
There is no one like you in the universe.
Manit0u
Profile Blog Joined August 2004
Poland17248 Posts
Last Edited: 2015-12-04 01:01:55
December 04 2015 01:00 GMT
#13712
On December 04 2015 08:44 WarSame wrote:
The actual Tower of Hanoi is still fairly difficult, but actually possible to program.


How is it fairly difficult?


def moveTower(height, fromPole, toPole, withPole):
if height >= 1:
moveTower(height - 1, fromPole, withPole, toPole)
moveDisk(fromPole, toPole)
moveTower(height - 1, withPole, toPole, fromPole)

def moveDisk(fp, tp):
print("moving disk from", fp, "to", tp)

moveTower(3, "A", "B", "C")


I believe it's one of the first things you encounter when reading up on recursion.
Time is precious. Waste it wisely.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 04 2015 02:09 GMT
#13713
Ah... that is much easier. I was still stuck in the mode of the other way I was doing it.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
Last Edited: 2015-12-04 22:59:03
December 04 2015 22:53 GMT
#13714
I've been reading Robert Martin's Clean Code book, and had a question about his section on switch statements. He uses the example of different kinds of employees: commissioned, hourly, and salaried. You might have various decisions to make depending on what kind of employee they are, such as how much they're paid, their pay day, or how to deliver their check. Rather than wrapping each decision with a switch statement, where you have to hunt for and change each one every time there's a new kind of employee, his suggestion is to use an abstract factory and abstract out those decisions into child employee classes such as HourlyEmployee or SalariedEmployee. That way the switch statement is declared only once, and it's easy to find and change.

That makes sense to me, and I can see the advantages and disadvantages doing that as opposed to maybe using an enum. But my question is, what happens when you have more than one need to do that on the same object. Suppose you also have to make decisions based on the employee's gender regardless if they're salaried or whatever. You can't create a class that inherits from more than one parent (at least not in C#), which means you'd have to create an instance for each possible combination: HourlyFemaleEmployee, HourlyMaleEmployee, SalariedFemaleEmployee, SalariedMaleEmployee, etc. Is there a better way to do that? Am I over-complicating it like I always do?
solidbebe
Profile Blog Joined November 2010
Netherlands4921 Posts
December 04 2015 23:15 GMT
#13715
Look up decorator pattern, it was designed to deal with the exact problem youre describing.
That's the 2nd time in a week I've seen someone sig a quote from this GD and I have never witnessed a sig quote happen in my TL history ever before. -Najda
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
December 04 2015 23:18 GMT
#13716
On December 05 2015 08:15 solidbebe wrote:
Look up decorator pattern, it was designed to deal with the exact problem youre describing.

Yes! I knew there was a simple solution. I'm quite familiar with the decorator patter, and it just didn't occur to me to use it in this instance. Thank you!
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-12-05 18:05:22
December 05 2015 17:58 GMT
#13717
whelp, I just woke up and it's time to work on my CS project for java

but I need to get my head straight and in the game..

help me figure something out.

If I make a class, let's call it "database".
and in "database" I am gonna have a couple arraylists, that are going to hold objects. and I want those arraylists to be static because there will only be 1 of each. so that's cool and all


if this is all my database class does - hold those 2 arraylists - is it appropriate to make that class "final" ?

god I can't believe I am this far into the semester and I sitll get confused by how static and final interact

if I have static arraylists in a final class, can I still change what is in the arraylists? I can, right? or can NOTHING in the class be changed?

and if I have static arraylists in the class and I make a new instance of the class, then it doesn't matter which instance of the class I reference, if I reference the arraylist within that instance it will always be pointing to the same one, right?


supereddie
Profile Joined March 2011
Netherlands151 Posts
December 05 2015 18:17 GMT
#13718
'final' only indicates that you can not inherit from that class.
'static' members transcend class instances (that is, the static members in all class instances have exactly the same value). However, beware of multi-threading writing static members.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 05 2015 18:19 GMT
#13719
If you only have static members, you don't have to create an instance of the class to use it. Just make everything you need public static and use it like this:
Database.List1.Add(x);

Final on a class shouldn't interact with static at all. It just means you can't subclass the final class. It does not make instances of the class or its members immutable.

However, I discourage that whole setup. "because there will only be one of each" is a trap. Static is inflexible and should mostly be avoided, especially if it's static data. It might seem convenient that you don't have to pass around a reference to your Database class, but sooner or later you'll find that you would in fact prefer to have multiple different instances of that class.

Also unless you have a good reason to make your class final, why would you?
If you have a good reason to disagree with the above, please tell me. Thank you.
solidbebe
Profile Blog Joined November 2010
Netherlands4921 Posts
Last Edited: 2015-12-05 18:24:05
December 05 2015 18:19 GMT
#13720
Im not that sure myself what declaring a class final does but youre correct on static. Declaring a variable static means it belongs to the class, not to an instance of the class. So accessing it through any instance would lead to the same variable. Youll probably get a warning "variable should be accessed in a static way" though. Which means youd need to access it like *classname*.variable. (or through a static getter)


edit* I agree with the post above. Its usually better design to not use static but rather instances.
That's the 2nd time in a week I've seen someone sig a quote from this GD and I have never witnessed a sig quote happen in my TL history ever before. -Najda
Prev 1 684 685 686 687 688 1031 Next
Please log in or register to reply.
Live Events Refresh
Wardi Open
11:00
#44
WardiTV1675
OGKoka 1058
Rex159
CranKy Ducklings150
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 1058
Rex 159
StarCraft: Brood War
PianO 5140
Rush 1883
Sea 1611
firebathero 1558
EffOrt 1273
JulyZerg 1083
zelot 703
Larva 666
Stork 626
Mong 488
[ Show more ]
Mini 315
Mind 146
Zeus 117
ToSsGirL 104
sorry 93
Pusan 82
Barracks 78
Movie 66
Shinee 56
sSak 47
soO 41
Shine 40
Terrorterran 31
sas.Sziky 31
Rock 16
IntoTheRainbow 9
yabsab 8
Bale 7
SilentControl 7
NaDa 4
Stormgate
NightEnD30
Dota 2
qojqva3439
syndereN585
League of Legends
Dendi1601
febbydoto7
Counter-Strike
flusha479
Super Smash Bros
Mew2King94
Heroes of the Storm
Khaldor219
Other Games
singsing2817
hiko1314
Fuzer 685
crisheroes456
Beastyqt353
Lowko288
oskar233
XcaliburYe233
Hui .224
Liquid`VortiX181
KnowMe103
ArmadaUGS99
QueenE51
Trikslyr1
Organizations
Other Games
gamesdonequick5050
StarCraft: Brood War
Kim Chul Min (afreeca) 7
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• StrangeGG 58
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2532
League of Legends
• Nemesis6008
Upcoming Events
RotterdaM Event
1h 1m
Replay Cast
19h 1m
WardiTV European League
1d 1h
ShoWTimE vs sebesdes
Percival vs NightPhoenix
Shameless vs Nicoract
Krystianer vs Scarlett
ByuN vs uThermal
Harstem vs HeRoMaRinE
PiGosaur Monday
1d 9h
uThermal 2v2 Circuit
2 days
Replay Cast
2 days
The PondCast
2 days
Replay Cast
3 days
Epic.LAN
3 days
CranKy Ducklings
4 days
[ Show More ]
Epic.LAN
4 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs Sziky
Dewalt vs Hawk
Hawk vs QiaoGege
Sziky vs Dewalt
Mihu vs Bonyth
Zhanhun vs QiaoGege
QiaoGege vs Fengzi
Sparkling Tuna Cup
5 days
Online Event
6 days
BSL20 Non-Korean Champi…
6 days
Bonyth vs Zhanhun
Dewalt vs Mihu
Hawk vs Sziky
Sziky vs QiaoGege
Mihu vs Hawk
Zhanhun vs Dewalt
Fengzi vs Bonyth
Liquipedia Results

Completed

2025 ACS Season 2: Qualifier
RSL Revival: Season 1
Murky Cup #2

Ongoing

JPL Season 2
BSL 2v2 Season 3
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
BSL20 Non-Korean Championship
Championship of Russia 2025
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

Upcoming

CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
BSL Season 21
K-Championship
RSL Revival: Season 2
SEL Season 2 Championship
uThermal 2v2 Main Event
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
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.