• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:56
CET 14:56
KST 22:56
  • 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: Winners10Intel 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!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
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
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
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 Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
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
[Manga] One Piece Anime Discussion Thread Movie Discussion! 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
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1429 users

The Big Programming Thread - Page 886

Forum Index > General Forum
Post a Reply
Prev 1 884 885 886 887 888 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
Spain18110 Posts
May 31 2017 23:18 GMT
#17701
On June 01 2017 07:58 travis wrote:
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

No, you're right. It's not as trivially reduceable to the maximum congruent subarray problem as I thought. The fact that it's circular allows you to do stuff that cannot simply be replicated by making repeating the array. I guess to use this approach, you'd have to simultaneously find the longest stretch you can within your current subarray with a value less or equal to 0. And then do some magic at the end, if necessary.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
May 31 2017 23:23 GMT
#17702
If you want to spoil an elegant solution for yourself, I expect you will enjoy it's simplicity like I did

http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
May 31 2017 23:26 GMT
#17703
I don't understand that solution *at all*, anyone have an explanation?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-05-31 23:39:26
May 31 2017 23:35 GMT
#17704
The solution covers 2 cases. The first case is that we can use the normal algorithm (the one blisse linked). We can use this algorithm if we don't have to worry about "wrapping around" our circular array.

A couple examples of that are {5, 5, 5} or {-3, 7, 8, 9} or {-2, 6, 3, -1, 7, -5}

In all of those we do not need to wrap to find our subarray. We now have a way to handle this case, so we can include it in our code - we don't need to worry about it anymore.


However there are cases where we do need to wrap around to find our subarray. Examples could be: {7, -2, 7 } or {1, 2, 3, 4, -5, 6, 7 } etc. These are cases where we need to remove negative stuff from the inside but still use both the ends of the array (since if it was a real necklace the end would connect to the beginning).

For those cases we know we have positive elements on the ends, because it is wrapping. So, we know that the subarray that we are removing is NOT wrapping - it's inside the array - not on the ends.
Because we know the subarray to be removed is inside, we can make all our positives negative, and all our negatives positive.

Then we find the greatest sum with this new array, which is actually the part to be removed because the signs were flipped. So our "start position" will be at the end of this subarray(the one that has the part we need to remove), and our "end position" will be just before it begins.


To cover both cases we need to run both algorithms in our code, and compare to see which gives us the greater sum - and that is the one that we will use.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2017-05-31 23:40:00
May 31 2017 23:39 GMT
#17705
Aahh so the trick is flipping the sign bit so that one loop through will get a max value. But you will also have to solve problem where you find "snip points", so that will add a little more complexity.

E: These kind of tricky problems are frustrating. Good job working through it man
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-05-31 23:45:56
May 31 2017 23:45 GMT
#17706
Sorry, I don't understand why running my originally suggested algorithm with the array 2x and max N wouldn't work.

Changing {7, -2, 7} to {7, -2, 7, 7, -2, 7} would get you the maximum sequence {7, 7}.
Changing {1, 2, 3, 4, -5, 6, 7 } to {1, 2, 3, 4, -5, 6, 7, 1, 2, 3, 4, -5, 6, 7 } would get you the maximum sequence {6, 7, 1, 2, 3, 4}.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
May 31 2017 23:51 GMT
#17707
In both of those cases the maximum sequence would be the full 2x arrays. {7, -2, 7, 7, -2, 7} has a higher value than {7, 7}
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2017-05-31 23:52:43
May 31 2017 23:52 GMT
#17708
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-05-31 23:54:16
May 31 2017 23:53 GMT
#17709
On June 01 2017 08:51 travis wrote:
In both of those cases the maximum sequence would be the full 2x arrays. {7, -2, 7, 7, -2, 7} has a higher value than {7, 7}


> ... with the array 2x and max N wouldn't work.

Should've specified max length N, oops.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-06-01 00:10:32
May 31 2017 23:58 GMT
#17710
edit: actually let me make sure I know what I am saying is correct

edit2: My brain is starting to get a bit worn out so I can't prove it but I think you lose linear time efficiency by doing what you are saying. I think that every time you reach "n" length subarray you would have to start over, 1 index from where you started last time, over and over again.
Well I guess there might be other ways but it definitely isn't simple


and if you tried to do it using the algorithm you originally posted, you would have to "snip" the subarray it found to shorten it to N length, which would mean you would have to go through all the N-length subarrays within the subarray that it found
Acrofales
Profile Joined August 2010
Spain18110 Posts
Last Edited: 2017-06-01 06:58:45
June 01 2017 06:58 GMT
#17711
On June 01 2017 08:23 travis wrote:
If you want to spoil an elegant solution for yourself, I expect you will enjoy it's simplicity like I did

http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/

Yup. More elegant by far than trying to deal with the wrap-around case by snipping out the middle, although it's essentially the same algorithm. It just looks neater that way
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-06-02 04:13:01
June 02 2017 04:11 GMT
#17712
so after taking a break from that really weird c project I brought up in this thread a while ago, I've been working on it all day today to figure out the kinks before the due date tomorrow at midnight

I managed to finish it just now and wow it was pretty frustrating

so basically what I did originally was for the most part fine, it's just that the mips simulator completely bugs out unless I follow some rules:

1) has to be in that old C style the professor used. I rewrote my code according to how he wrote his code
2) must define empty __main() function since the simulator calls for it and gives an error if it's not defined
3) must define empty dummy function and call it in each function I am using pointers to access the stack
4) cannot use printf, must use a separate string printing function the professor defined
5) when compiling it into the needed .s file the .c file used must be the same as the .s file. (did not know this and took hours)

also had to change frame pointer along with return address

if people are still interested in the final code I'll post tomorrow after the due date since I'd rather not chance (albeit hilariously small) someone comes across and copies it before the due date. or PM ing is fine

it's basically what I posted before with all those rules followed above. just save the address of the return address and frame pointer in the setjmp function and have the return address and frame pointer in longjmp function be changed to that of the one from setjmp. doesn't work when I write it like how modern human beings write C code. only in that archaic form does it work in the simulator. top 5 stupidest assignments i've had so far in my life not because of the content but because of the horrible guidelines and directions. And so much effort needed for trying to teach something rather simple.
TL/SKT
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
June 02 2017 07:04 GMT
#17713
On June 02 2017 13:11 dsyxelic wrote:
so after taking a break from that really weird c project I brought up in this thread a while ago, I've been working on it all day today to figure out the kinks before the due date tomorrow at midnight

I managed to finish it just now and wow it was pretty frustrating

so basically what I did originally was for the most part fine, it's just that the mips simulator completely bugs out unless I follow some rules:

1) has to be in that old C style the professor used. I rewrote my code according to how he wrote his code
2) must define empty __main() function since the simulator calls for it and gives an error if it's not defined
3) must define empty dummy function and call it in each function I am using pointers to access the stack
4) cannot use printf, must use a separate string printing function the professor defined
5) when compiling it into the needed .s file the .c file used must be the same as the .s file. (did not know this and took hours)

also had to change frame pointer along with return address

if people are still interested in the final code I'll post tomorrow after the due date since I'd rather not chance (albeit hilariously small) someone comes across and copies it before the due date. or PM ing is fine

it's basically what I posted before with all those rules followed above. just save the address of the return address and frame pointer in the setjmp function and have the return address and frame pointer in longjmp function be changed to that of the one from setjmp. doesn't work when I write it like how modern human beings write C code. only in that archaic form does it work in the simulator. top 5 stupidest assignments i've had so far in my life not because of the content but because of the horrible guidelines and directions. And so much effort needed for trying to teach something rather simple.


Wow...

What class is that? C? Embedded systems?

Also, to anyone familiar with mips: do you really have to use old syntax for it and some non-standard functions or is it just this weird simulator that enforces this?

Super weird assignment. I feel your pain and am glad you made it work.
Time is precious. Waste it wisely.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
June 02 2017 07:08 GMT
#17714
I'll take a look! I write C/C++ professionally so I'd be pretty interested in peeking.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-06-02 08:13:22
June 02 2017 07:58 GMT
#17715
--- Nuked ---
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-06-02 21:02:59
June 02 2017 14:06 GMT
#17716
Yup nesserev got it. Thats the book we use and thats what the class is called. I agree hand writing this in assembly would have taught the same thing with less trouble.

@cecil ill pm you after work! Or just post here since its due around then anyways.

And respect to those who work in c, this language hurts me

edit:

here's the code

+ Show Spoiler +

int *ra; //return address
int *fp; //frame pointer
main()
{
int r;
r = setjmp(r);
if(r==0)
{
fun1();
return(0);
}
else
{
print_str("error\n");
return(2);
}
}
__main()
{
return(0);
}
dummy(v)
int v;
{
return(0);
}
setjmp(v)
int v;
{
int *p = &v;
ra = *(p-1);
fp = *(p-2);
dummy(v);
return(0);
}
longjmp(v)
int v;
{
int *p;
p = &v;
*(p-1) = ra;
*(p-2) = fp;
dummy(v);
return(1);
}
fun1()
{
print_str("start fun1\n");
fun2();
return(0);
}
fun2()
{
int d;
print_str("start fun2\n");
longjmp(d);
return(0);
}
print_str(str)
char *str;
{
int code;
code = 4;
asm(
"add $a0, %1, $zero\n\t"
"add $v0, %0, $zero\n\t"
"syscall"
:
: "r" (code), "r" (str));
return(0);
}
//output is:
//start fun1
//start fun2
//error
TL/SKT
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-06-03 16:27:46
June 03 2017 16:25 GMT
#17717
I was wondering if any of you could glance over my homework solutions for this week's "NP-Completeness" homework. It's really short - but I haven't done stuff quite like this and I am liable to screw it up (and some of it is a bit confusing for me)

Here is a link to the homework
http://www.cs.umd.edu/class/summer2017/cmsc351/hwk-np.pdf

this week we do only part 1 - sorting
so the questions I am wanting checked over is questions 2 and questions 3 of part 1

here are my solutions

http://www.filedropper.com/scan0001_2

(I had to click to download it twice before it actually downloaded it)

If you can't tell - my answer for 3a was to "put all the elements of all lists into a linked list" - or I guess that if they already were linked lists (it's not specific) - then link them all together.


note: if you are worried about helping me "cheat", it's not like that for this class. We can work together and review each other's stuff, we just need to write our solutions ourselves. Also, 87% of our grade is our one midterm and final so homework doesn't matter too much. I mostly just care about it so I will be better on the 2 exams.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 03 2017 17:38 GMT
#17718
--- Nuked ---
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-06-03 18:13:41
June 03 2017 18:09 GMT
#17719
On June 04 2017 02:38 Nesserev wrote:
Show nested quote +
On June 04 2017 01:25 travis wrote:
I was wondering if any of you could glance over my homework solutions for this week's "NP-Completeness" homework. It's really short - but I haven't done stuff quite like this and I am liable to screw it up (and some of it is a bit confusing for me)

Here is a link to the homework
http://www.cs.umd.edu/class/summer2017/cmsc351/hwk-np.pdf

this week we do only part 1 - sorting
so the questions I am wanting checked over is questions 2 and questions 3 of part 1

here are my solutions

http://www.filedropper.com/scan0001_2

(I had to click to download it twice before it actually downloaded it)

If you can't tell - my answer for 3a was to "put all the elements of all lists into a linked list" - or I guess that if they already were linked lists (it's not specific) - then link them all together.


note: if you are worried about helping me "cheat", it's not like that for this class. We can work together and review each other's stuff, we just need to write our solutions ourselves. Also, 87% of our grade is our one midterm and final so homework doesn't matter too much. I mostly just care about it so I will be better on the 2 exams.

Your answers for 2 are correct, but you seem to leave out some steps, which is annoying.

In 3a, you seem to have missed that you're also supposed to split that big list back up into all those separate lists afterwards in linear time. How will you do that?

The answer 3a will affect your answers for 3b, 3c and 3d, because you have to add the preprocessing and postprocessing times.


Hmm ok, I will be more meticiulous about 2.
As for 3 - are you sure I need to do that? I guess that does make sense, but it doesn't explicitly say it.

As for how I would do it - I honestly have no idea. That sounds impossible. I could separate it into lists of the original sizes, but the elements would be all wrong for each list.

Did the math for what I actually did look correct?

Thank you btw, appreciate your time.


edit: oh quick note, the homework says: "In order to get exact results, for the remaining problems in this section, ignore the cost of preparing the lists for input into the sorting package or processing the results (assuming those costs are within reason)."
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-06-03 18:30:30
June 03 2017 18:29 GMT
#17720
--- Nuked ---
Prev 1 884 885 886 887 888 1032 Next
Please log in or register to reply.
Live Events Refresh
CranKy Ducklings
10:00
Sea Duckling Open #140
CranKy Ducklings84
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 198
Railgan 42
Creator 14
StarCraft: Brood War
Sea 6776
Horang2 4135
GuemChi 1585
Jaedong 890
actioN 290
Mini 250
BeSt 249
Soma 228
Killer 218
EffOrt 205
[ Show more ]
Rush 172
Mind 105
Hyun 95
Bonyth 72
ToSsGirL 67
Backho 60
PianO 34
JYJ32
sas.Sziky 32
Aegong 28
zelot 23
Terrorterran 14
soO 11
sorry 10
HiyA 7
Sacsri 7
Dota 2
Gorgc5272
singsing2292
qojqva1976
Dendi596
XcaliburYe219
BananaSlamJamma107
Heroes of the Storm
Khaldor214
Other Games
B2W.Neo1235
Sick275
Lowko237
Fuzer 197
Hui .121
XaKoH 87
nookyyy 56
MindelVK20
Organizations
StarCraft 2
WardiTV622
Counter-Strike
PGL231
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 73
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2101
League of Legends
• Stunt689
• HappyZerGling108
Upcoming Events
IPSL
4h 4m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
4h 4m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
6h 4m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
9h 4m
Sparkling Tuna Cup
20h 4m
WardiTV Korean Royale
22h 4m
LAN Event
1d 1h
IPSL
1d 4h
JDConan vs WIZARD
WolFix vs Cross
BSL 21
1d 6h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
1d 19h
[ Show More ]
Wardi Open
1d 22h
WardiTV Korean Royale
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
4 days
RSL Revival
4 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
RSL Revival
5 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
5 days
CranKy Ducklings
6 days
RSL Revival
6 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
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
BSL Season 21
Stellar Fest: Constellation Cup
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: 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.