• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:19
CET 19:19
KST 03: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
TL.net Map Contest #21: Winners11Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation6Weekly 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 [TLMC] Fall/Winter 2025 Ladder Map Rotation Weekly Cups (Nov 3-9): Clem Conquers in Canada Craziest Micro Moments Of All Time? SC: Evo Complete - Ranked Ladder OPEN ALPHA
Tourneys
Master Swan Open (Global Bronze-Master 2) Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament $5,000+ WardiTV 2025 Championship
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
BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle Terran 1:35 12 Gas Optimization BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET [ASL20] Grand Finals
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread EVE Corporation Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? Path of Exile
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
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread The Games Industry And ATVI
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! 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: 1673 users

The Big Programming Thread - Page 885

Forum Index > General Forum
Post a Reply
Prev 1 883 884 885 886 887 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.
Acrofales
Profile Joined August 2010
Spain18114 Posts
May 31 2017 17:00 GMT
#17681
On June 01 2017 01:00 Hanh wrote:
What would an algorithmic solution be?


What the guys above you did.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-05-31 19:40:32
May 31 2017 19:38 GMT
#17682
Ok we've been given homework #1.

It is okay for me to post homeworks, and to discuss them. I figure you guys will probably find this fun so I am posting it, I'll post my attempt before I read any solutions.


Assume you have a necklace of stones. Some of the stones have positive value and some
have negative value. You have the opportunity to snip the necklace in two places (creating two
bands) and weld the endpoints of one of the two bands back into a necklace. You would like
your new necklace to be as valuable as possible. You can assume the necklace has n stones
with values v[0], v[1], . . . , v[n − 1].


ah, so we have a circular connecting necklace and you snip it in 2 places, using one of the new bands to make a new necklace


(a) Give an algorithm to find the value of the new necklace. If all of the stones have negative
value your answer should be 0. Make your algorithm as clean and elegant as possible.



(b) Give an algorithm to determine where you should snip the original necklace (not just its
value). Make your algorithm as clean and elegant as possible. If all of the values are
positive you should not snip and your algorithm should print:
Do not snip.
If all of the values are negative you should not snip and your algorithm should print:
Throw necklace away.
If possible the algorithm should determine these two situations without explicitly checking
for them.

CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2017-05-31 19:50:55
May 31 2017 19:49 GMT
#17683
What the heck kind of homework question is that lol. My eyes glaze over trying to read the paragraphs. Sounds like a pretty hard problem. Looks like a linked list, or an array kind of problem. Linked list would probably be the easiest to write code for.

"Some have positive, some have negative", why can't we say signed integers? It's just signed integers.

It sounds like one of those "maximal subset" problems. I hate those problems man. Actually this problem here is my least favorite programming question I have ever heard, and sounds pretty similar to yours.

Edit: When it says clean and elegant, what do those terms even mean. Those are really subjective terms. It sort of sounds like "try to find the trick that makes this problem easy to solve", like the trick in the wikipedia page.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
May 31 2017 19:57 GMT
#17684
When he says clean and elegant I imagine he is hinting that there is at least one efficient solution that will not be super complicated, and he wants that solution.

I think that interestingly enough this question is almost the opposite of question 1 of the 3 questions I posted back a little bit ago.

For the sake of familiarity I would view the necklace as a circular array (just "decide" that the ends connect)
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-05-31 20:07:10
May 31 2017 20:05 GMT
#17685
Overcomplicating it a bit, the problem simply boils down to the maximum subarray problem.

Of course, part of the course is learning how to decipher word problems.
There is no one like you in the universe.
Acrofales
Profile Joined August 2010
Spain18114 Posts
Last Edited: 2017-05-31 20:14:16
May 31 2017 20:05 GMT
#17686
Sounds like dynamic programming to me. Did you learn dynamic programming yet?

E: re Blisse
+ Show Spoiler +

Yeah. That. Just have to make sure you copy the values twice, so you get the fact that the first and last element are connected. Alternatively you could loop an extra time at the end until your previous value is greater or equal to the newest one.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-05-31 20:23:18
May 31 2017 20:21 GMT
#17687
It isn't the same problem though, I think. I haven't started it yet but I think for this one we actually need to find the minimum subarray. Finding the maximum could give us an incorrect result.

For example if our necklace is:

5 7 -2 5 -2
and then we return back the whole necklace - we are wrong. (or if you don't like this example, replace with much bigger more complicated examples)


I know of dynamic programming but I haven't really done much of it in practice. I think I will be okay though since I know the premise behind it.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
May 31 2017 20:29 GMT
#17688
What's wrong with returning the whole array?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
May 31 2017 20:32 GMT
#17689
in the example above the correct answer would be to remove an instance of negative 2 and return everything else, ie: 5 7 5 -2
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2017-05-31 20:35:42
May 31 2017 20:34 GMT
#17690
Minimum subarray means lowest value, so -2. Maximum means 5 7 -2 5, for value of 15 (like you correctly pointed out).
Acrofales
Profile Joined August 2010
Spain18114 Posts
Last Edited: 2017-05-31 20:39:51
May 31 2017 20:38 GMT
#17691
On June 01 2017 05:29 CecilSunkure wrote:
What's wrong with returning the whole array?

In that example? It doesn't maximize the value. By just returning [5, 7] you get a value of 12. If you add negative values, your value isn't maximal.

@Travis: you don't want a minimal length. You don't want maximal length. You want maximal value, which is what blisse's link describes.

E: I read -5 for the second 5 :p. But even so you don't want to return the whole array
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-05-31 20:46:18
May 31 2017 20:43 GMT
#17692
I didn't actually realize he had posted a link, it seems to be the exact same color as normal text for me. I thought he was referring to a problem I had posted yesterday.

Which, actually is that problem. But making it circular changes it a bit.

I know we don't want maximal or minimal length, but I am now seeing there really is no difference between looking for minimum subarray or looking for maximum subarray.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
May 31 2017 20:44 GMT
#17693
Yep that's right, maximum and minimum subarrays can have any length, because the values are what determine max/min, not the element indices or how many elements the subarray has.

And yeah... TL links seem to have lost their luster. It's impossible to see them.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-05-31 20:59:09
May 31 2017 20:53 GMT
#17694
okay now that I am actually working on this it is a bit harder than what I thought it was.

I don't think Blisse's link does it justice - the trouble for me is in handling that it is circular.

edit: I looked up an answer and it's really cute - you guys were underselling this problem

a hint is that my intuition was right that I needed to find the maximum negative subarray, but there is more to it than that.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
May 31 2017 21:37 GMT
#17695
lol well i'm glad you're enjoying it. You model student you
Acrofales
Profile Joined August 2010
Spain18114 Posts
Last Edited: 2017-05-31 23:02:58
May 31 2017 21:54 GMT
#17696
Pretty sure you can solve it just fine as follows:

+ Show Spoiler +


neckarray = 2*necklace

maxstart = 0
maxend = 0
maxval = 0

tempstart = 0
tempval = 0

for index, value in neckarray:
tempval = max(value, tempval + value);
if tempval == value:
tempstart = index

maxval = max(tempval, maxval)
if maxval == tempval:
maxstart = tempstart
maxend = index +1

if maxend - maxstart > len(necklace):
print "Don't cut"
elif maxval == 0:
print "Trash"
else:
maxend = maxend%len(necklace)
maxstart = maxstart%len(necklace)
print("cut at", maxstart, maxend, "for a necklace with value", maxval)

Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-05-31 22:19:45
May 31 2017 22:14 GMT
#17697
edit2:

I don't know what language that is, but I am guessing what you are doing is

1.) make an array that repeats the original array once
2.) find the maximum continuous subarray.
3.) if the maximum continuous subarray is greater in length than the original array, don't cut

{5, 5, -1, 5, -1, 5} would return "don't cut", which would be wrong because the correct answer would remove an instance of -1
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-05-31 22:43:40
May 31 2017 22:39 GMT
#17698
@travis, haven't walked through, but arcofales's code repeats the original array twice, and performs the maximal subarray code on that repeated array.

Seems to be missing a check to ensure that the selected maximum subarray is only of length N though.

edit: oo, neat lol
There is no one like you in the universe.
Acrofales
Profile Joined August 2010
Spain18114 Posts
Last Edited: 2017-05-31 22:44:50
May 31 2017 22:40 GMT
#17699
On June 01 2017 07:14 travis wrote:
edit2:

I don't know what language that is, but I am guessing what you are doing is

1.) make an array that repeats the original array once
2.) find the maximum continuous subarray.
3.) if the maximum continuous subarray is greater in length than the original array, don't cut

{5, 5, -1, 5, -1, 5} would return "don't cut", which would be wrong because the correct answer would remove an instance of -1


It is pseudopython. Mostly python, but too lazy to make it properly. And yeah, completely interested code.

Unless I made a mistake somewhere, it'd return 5, 4 as the start and end for your cut, which is what you'd want. The loop would end with 5, 10 as the maxstart, maxend. Those would then be adjusted (just the maxend in this case) to not be greater than the necklace's length.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-05-31 23:01:11
May 31 2017 22:58 GMT
#17700
Can you explain why it would return 5, 10 as max start and end instead of 0, 10 ?

I thought I had a clue reading that code but maybe I don't, lol
Prev 1 883 884 885 886 887 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 4h 41m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
UpATreeSC 252
White-Ra 46
StarCraft: Brood War
Calm 2294
Rain 1728
Horang2 746
Shuttle 457
Backho 63
Rock 47
Barracks 29
hero 28
zelot 22
Aegong 16
[ Show more ]
Killer 16
ivOry 7
Dota 2
Gorgc4134
qojqva2757
Dendi1192
LuMiX1
League of Legends
rGuardiaN43
Counter-Strike
pashabiceps1051
Super Smash Bros
Mew2King89
Other Games
ceh9569
DeMusliM473
Beastyqt267
Fuzer 250
Sick248
Hui .162
QueenE69
Trikslyr41
BRAT_OK 20
MindelVK14
C9.Mang04
fpsfer 1
Organizations
Other Games
BasetradeTV31
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• 3DClanTV 49
• HeavenSC 40
• intothetv
• Kozan
• sooper7s
• Migwel
• AfreecaTV YouTube
• LaughNgamezSOOP
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Nemesis3816
• TFBlade1153
• imaqtpie615
Other Games
• WagamamaTV372
• Shiphtur263
Upcoming Events
Tenacious Turtle Tussle
4h 41m
The PondCast
15h 41m
RSL Revival
15h 41m
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
17h 41m
ByuN vs ShoWTimE
Classic vs Cure
Reynor vs TBD
WardiTV Korean Royale
17h 41m
PiGosaur Monday
1d 6h
RSL Revival
1d 15h
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
1d 17h
herO vs TBD
CranKy Ducklings
2 days
RSL Revival
2 days
herO vs Gerald
ByuN vs SHIN
[ Show More ]
Kung Fu Cup
2 days
IPSL
2 days
ZZZero vs rasowy
Napoleon vs KameZerg
BSL 21
3 days
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
3 days
RSL Revival
3 days
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
3 days
WardiTV Korean Royale
3 days
BSL 21
4 days
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
4 days
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
4 days
Wardi Open
4 days
Monday Night Weeklies
4 days
WardiTV Korean Royale
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2025-11-07
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
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
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
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.