• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:00
CET 22:00
KST 06:00
  • 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: Winners2Intel 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
Starcraft, SC2, HoTS, WC3, returning to Blizzcon!20$5,000+ WardiTV 2025 Championship5[BSL21] RO32 Group Stage3Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
TL.net Map Contest #21: Winners Starcraft, SC2, HoTS, WC3, returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond) $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review [BSL21] RO32 Group Stage Practice Partners (Official) [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION
Strategy
Current Meta How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV ZeroSpace Megathread General RTS Discussion Thread
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 YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
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 Recent Gifted Posts
Blogs
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Career Paths and Skills for …
TrAiDoS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1245 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
Spain18108 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
Spain18108 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
Spain18108 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
Spain18108 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
Spain18108 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
LAN Event
18:00
Day 3: Ursa 2v2, FFA
SteadfastSC393
IndyStarCraft 177
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 499
SteadfastSC 393
White-Ra 211
IndyStarCraft 177
UpATreeSC 142
ProTech125
Railgan 67
ROOTCatZ 43
StarCraft: Brood War
Shuttle 460
Bonyth 69
ivOry 14
Dota 2
Dendi985
Counter-Strike
pashabiceps1182
Foxcn163
Super Smash Bros
Liquid`Ken9
Heroes of the Storm
Liquid`Hasu516
Other Games
Beastyqt728
fl0m665
Mlord452
FrodaN427
shahzam403
KnowMe185
Pyrionflax168
C9.Mang0125
ArmadaUGS115
ToD77
Mew2King74
Trikslyr53
OptimusSC21
Organizations
Counter-Strike
PGL192
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• Adnapsc2 11
• Reevou 9
• Dystopia_ 0
• Kozan
• sooper7s
• AfreecaTV YouTube
• Migwel
• LaughNgamezSOOP
• intothetv
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3055
• Ler92
League of Legends
• TFBlade886
Other Games
• imaqtpie1303
• WagamamaTV341
• Scarra290
• Shiphtur221
Upcoming Events
OSC
1h
Replay Cast
2h
OSC
15h
LAN Event
18h
Korean StarCraft League
1d 6h
CranKy Ducklings
1d 13h
LAN Event
1d 18h
IPSL
1d 21h
dxtr13 vs OldBoy
Napoleon vs Doodle
BSL 21
1d 23h
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
2 days
[ Show More ]
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
2 days
LAN Event
2 days
IPSL
2 days
JDConan vs WIZARD
WolFix vs Cross
BSL 21
2 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
3 days
Wardi Open
3 days
WardiTV Korean Royale
4 days
Replay Cast
5 days
Kung Fu Cup
5 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
6 days
The PondCast
6 days
RSL Revival
6 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
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
Esports World Cup 2025

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 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.