Jump to content
  • Advertisement
Sign in to follow this  
MrEvil

Optimization of intercal quicksort' code

This topic is 5032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm fully aware that any program in intercal will run slowly, therefore it should be `slowsort', but I wondered if there is any possible way I can optimize this mess, so that it might only be `moderatelyslowsort'. This code also contains the code to fill the array and output the array. I'm also doing Heap sort in intercal, does anyone know if that will be better?
	PLEASE NOTE MAIN CODE SEQUENCE HERE
	DO (400) NEXT
	DO (401) NEXT
	DO .12 <- #1
	DO .13 <- .6
	DO (300) NEXT
	DO (401) NEXT
	PLEASE GIVE UP

	PLEASE NOTE WRITE IN ARRAY
(400)	PLEASE WRITE IN .6
	DO ,1 <- .6
	PLEASE DO .5 <- #1
(410) 	DO (411) NEXT
(411) 	DO COME FROM (412)
	DO (413) NEXT
(412) 	PLEASE DO .1 <- .1
(413) 	DO STASH .1
	DO NOT WRITE IN ,1SUB.5
	DO NOT .1 <- .5
	DO (1900) NEXT
	PLEASE DO ,1SUB.5 <- .1
	DO RETRIEVE .1
	DO .1 <- .5
	DO (1020) NEXT
	PLEASE DO .5 <- .1
	DO .4 <- '?.1$.6'~'#0$#65535'
	DO .4 <- '&"'.1~.4'~'"?'?.4~.4'$#32768"~"#0$#65535"'"$".4~.4"'~#1
	DO .4 <- "?!4'$#1"~#3
	PLEASE RESUME .4
	DO COME FROM (410)
	DO RESUME #1

	PLEASE NOTE READ OUT ARRAY
(401)	DON'T READ OUT #0
	PLEASE DO .5 <- #1
(420) 	DO (421) NEXT
(421) 	DO COME FROM (422)
	DO (423) NEXT
(422) 	PLEASE DO .1 <- .1
(423) 	DO READ OUT ,1SUB.5
	DO .1 <- .5
	DO (1020) NEXT
	PLEASE DO .5 <- .1
	DO .4 <- '?.1$.6'~'#0$#65535'
	DO .4 <- '&"'.1~.4'~'"?'?.4~.4'$#32768"
        	 ~"#0$#65535"'"$".4~.4"'~#1
	DO .4 <- "?!4'$#1"~#3
	PLEASE RESUME .4
	DO COME FROM (420)
	DO RESUME #1

	PLEASE NOTE BEGINNING OF QUICKSORT ROUTINE
	PLEASE NOTE EXECUTE ROUTINE ONLY IF .13 > .12
(300)	DO STASH .4 + .10 + .11 + .12 + .13 + .14 + .15
	DO .4 <- '?.13$.12'~'#0$#65535'
	DO .4 <- '&"'.13~.4'~'"?'?.4~.4'$#32768"~"#0$#65535"'"$".4~.4"'~#1
	PLEASE DO .4 <- "?.4$#1"~#3
	DO (301) NEXT

	DO (310) NEXT
	DO (320) NEXT
	PLEASE DO (360) NEXT

(303)	DO NOTHING
(301)	DO (302) NEXT
(302)	DO RESUME .4
	PLEASE COME FROM (301)
	DO RETRIEVE .4 + .10 + .11 + .12 + .13 + .14 + .15
	DO RESUME #2
	PLEASE COME FROM (303)
	DO RETRIEVE .4 + .10 + .11 + .12 + .13 + .14 + .15
	DO RESUME #1
	PLEASE NOTE END OF QUICKSORT ROUTINE

	PLEASE NOTE CALCULATES MIDPOINTER AND MIDVALUE AND .10 AND .11
(310)	DO STASH .1 + .2 + .3
	DO .1 <- .12
	DO .2 <- .13
	DO .10 <- .12
	DO .11 <- .13
	PLEASE DO (1000) NEXT
	DO .14 <- !3$#0'~'#65534$#0'
	DO RETRIEVE .1 + .2 + .3
	DO .15 <- ,1SUB.14
	PLEASE RESUME #1

	PLEASE NOTE MAIN DO-LOOP THING UNTIL .10 > .11
(320)	DO STASH .4
	DO COME FROM (321)
	DO .4 <- '?.10$.11'~'#0$#65535'
	DO .4 <- '&"'.10~.4'~'"?'?.4~.4'$#32768"~"#0$#65535"'"$".4~.4"'~#1
	PLEASE DO .4 <- "?!4'$#1"~#3
	
	DO (330) NEXT
	DO (340) NEXT
	PLEASE DO (350) NEXT

(321)	DO (322) NEXT
(322)	DO (323) NEXT
	DO RETRIEVE .4 
	PLEASE RESUME #2
(323)	DO RESUME .4

	PLEASE NOTE CALLS 335 UNTIL NOT NECESSARY
(330)	DO STASH .4
	DO COME FROM (334)
	DO .4 <- '?.15$",1SUB.10"'~'#0$#65535'
	DO .4 <- '&"'.15~.4'~'"?'?.4~.4'$#32768"~"#0$#65535"'"$".4~.4"'~#1
	PLEASE DO .4 <- "?!4'$#1"~#3

(331)	DO (332) NEXT
(334)	DO (335) NEXT
(332)	DO (333) NEXT
	DO RETRIEVE .4
	PLEASE RESUME #2
(333)	DO RESUME .4

	PLEASE NOTE INCREMENTS .10
(335)	DO STASH .1
	DO .1 <- .10
	DO (1020) NEXT
	PLEASE DO .10 <- .1
	DO RETRIEVE .1
	DO RESUME #1

	PLEASE NOTE CALLS 345 UNTIL NOT NECESSARY
(340)	DO STASH .4
	DO COME FROM (344)
	DO .4 <- '?",1SUB.11"$.15'~'#0$#65535'
	DO .4 <- '&"'",1SUB.11"~.4'~'"?'?.4~.4'$#32768"~"#0$#65535"'"$".4~.4"'~#1
	PLEASE DO .4 <- "?!4'$#1"~#3

(341)	DO (342) NEXT
(344)	DO (345) NEXT
(342)	DO (343) NEXT
	DO RETRIEVE .4
	PLEASE RESUME #2
(343)	DO RESUME .4

	PLEASE NOTE DECREMENTS .11
(345)	DO STASH .1
	DO .1 <- .11
	DO (2000) NEXT
	PLEASE DO .11 <- .1
	DO RETRIEVE .1
	DO RESUME #1

	PLEASE NOTE SWAPS ELEMENTS IF .10 <= .11
(350)	DO STASH .4
	DO .4 <- '?.10$.11'~'#0$#65535'
	DO .4 <- '&"'.10~.4'~'"?'?.4~.4'$#32768"~"#0$#65535"'"$".4~.4"'~#1
	PLEASE DO .4 <- "?!4'$#2"~#3
	DO (351) NEXT
(353)	DO (355) NEXT
(351)	DO (352) NEXT
(354)	DO FORGET #1
(352)	DO RESUME .4
	DO COME FROM (354)
	DO COME FROM (353)
	PLEASE RETRIEVE .4
	DO RESUME #1

	PLEASE NOTE SWAPS ELEMENTS ,1SUB.10 AND ,1SUB.11, CALLS 335 AND 345
(355)	DO STASH .1
	DO .1 <- ,1SUB.10
	DO ,1SUB.10 <- ,1SUB.11
	PLEASE DO ,1SUB.11 <- .1
	DO RETRIEVE .1
	DO (335) NEXT
	DO (345) NEXT
	PLEASE RESUME #1

	PLEASE NOTE THIS IS THE RECURSIVE BIT
	PLEASE NOTE SORT THE SMALLEST SEGMENT FIRST, IN ORDER TO OPTIMIZE
(360)	DO STASH .4
	DO .4 <- '?.11$.14'~'#0$#65535'
	DO .4 <- '&"'.11~.4'~'"?'?.4~.4'$#32768"~"#0$#65535"'"$".4~.4"'~#1
	PLEASE DO .4 <- "?!4'$#2"~#3
	DO (361) NEXT
(363)	DO (365) NEXT
(361)	DO (362) NEXT
	DO (366) NEXT
	DO FORGET #1
	PLEASE ABSTAIN FROM (362)
(362)	DO RESUME .4
	DO REINSTATE (362)
	DO COME FROM (363)
	PLEASE RETRIEVE .4
	DO RESUME #1

	PLEASE NOTE SORT THE TAIL SEGMENT FIRST
(366)	DO STASH .12 + .13
	DO .12 <- .10
	DO (300) NEXT
	PLEASE RETRIEVE .12	
	DO .13 <- .11
	DO (300) NEXT
	DO RETRIEVE .13
	PLEASE RESUME #1

	PLEASE NOTE SORT THE TAIL SEGMENT LAST
(365)   DO STASH .12 + .13
	DO .13 <- .11
	PLEASE DO (300) NEXT
	DO RETRIEVE .13
	DO .12 <- .10
       	DO (300) NEXT
	DO RETRIEVE .12
	PLEASE RESUME #1

	PLEASE NOTE: THIS CODE FROM LIB2.I BY LOUIS HOWELL
(2010)  PLEASE ABSTAIN FROM (2004)
(2000)  PLEASE STASH .2
        DO .2 <- #1
        DO (2001) NEXT
(2001)  PLEASE FORGET #1
        DO .1 <- '?.1$.2'~'#0$#65535'
        DO (2002) NEXT
        DO .2 <- !2$#0'~'#32767$#1'
        DO (2001) NEXT
(2003)  PLEASE RESUME "?!1~.2'$#1"~#3
(2002)  DO (2003) NEXT
        PLEASE RETRIEVE .2
(2004)	PLEASE RESUME #2
	PLEASE DO REINSTATE (2004)
	PLEASE RESUME '?"!1~.1'~#1"$#2'~#6

Share this post


Link to post
Share on other sites
Advertisement
And you're doing this why exactly? o__O

(Although actually I'm kind of impressed that you'd try at all, I doubt you'll find many people willing to volunteer the free time to optimize INTERCAL code.)

Share this post


Link to post
Share on other sites
Eventually, I will get around to making a 3d library for intercal. Therefore sorting is of the utmost importance, and it needs to be as fast as possible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!