Re: add_item question
- Posted by coconut Sep 24, 2012
- 1562 views
Aveu said...
Well, it would appear then that there must be something "subtle" (aka "obvious") wrong with my code that I do not understand. I am an old programmer learning a new language. I ran with trace and things looked good right up to the add_item line but the result was an empty sequence.
As a learning exercise I am writing an anagram solver and the following is my code so far. The relevant variables are Jword1 (aka theWord) and Jwords (aka theList):
include std/console.e include std/io.e include std/os.e include std/pretty.e include std/search.e include std/sequence.e include std/sort.e include std/text.e include std/types.e with batch with trace sequence letters = "txhoefqdueirck" integer size = length( letters ) sequence tumbler = series( 1 , 1 , size ) sequence Jword1 = "" sequence Jwords = {} integer ccflag = 0 function valid_Jword( sequence TUMBLER ) integer ZZ = 0 for XX = 1 to size do ZZ += ( length( find_all ( TUMBLER[XX] , tumbler ) ) - 1 ) end for return ( ZZ = 0 ) end function function make_Jword( sequence TUMBLERZ ) integer ZZ sequence JWORD = repeat( "@" , size ) for XX = 1 to size do ZZ = TUMBLERZ[XX] JWORD[XX] = letters[ZZ] end for return JWORD end function -- initialize -- clear_screen() letters = upper ( sort( letters ) ) tumbler[size] -= 1 -- back off last tumbler by 1 to pre-adjust for the very first pass -- run main process -- loop label "loop_AA" do -- until tumbler[1] > size loop label "loop_BB" do -- until a valid Jword is found ccflag = 1 for CC = size to 1 by -1 label "loop_CC" do tumbler[CC] += ccflag if tumbler[CC] > size then tumbler[CC] = 1 ccflag = 1 else ccflag = 0 end if end for until valid_Jword( tumbler ) -- end loop_BB end loop trace(1) if ( tumbler[1] <= size ) then Jword1 = make_Jword( tumbler ) add_item( Jword1 , Jwords , ADD_SORT_UP ) end if trace(0) until tumbler[1] > size end loop
should be:
Jwords = add_item(Jword1,Jwords,ADD_SORT_UP)