Last letter-first letter: Difference between revisions

m
→‎optimized version: added/changed whitespace and comments, included an extra check for stop words.
m (→‎brute force version: added/changed whitespace and comments.)
m (→‎optimized version: added/changed whitespace and comments, included an extra check for stop words.)
Line 4,061:
'remoraid rufflet sableye scolipede scrafty seaking sealeo silcoon simisear snivy snorlax spoink',
'starly tirtouga trapinch treecko tyrogue vigoroth vulpix wailord wartortle whismur wingull yamask'
#= words(@); @.=; @s=@.; ig=0; og=0; !.=0 /*nullify array and the longest path. */
parse arg limit .; if limit\=='' then #=limit limit /*allow user to specify a scan limit. */
call build@ /*build a stemmed array from the @ list*/
do v=# by -1 for # /*scrub the @ list for unusable words. */
parse var @.v F 2 '' -1 L /*obtain first and last letter of word.*/
if !.1.F>1 | !.9.L>1 then iterate /*is this a dead word? */
say 'ignoring dead word:' @.v; ig= ig + 1; @= delword(@, v, 1)
end /*v*/ /*delete dead word from @ ──┘ */
#= words(@) /*recalculate the number of words in @.*/
do v=# by -1 for # /*scrub the @ list for stoppable words.*/
parse var @.v F 2 '' -1 L /*obtain first and last letter of word.*/
if !.1.L>0 then iterate /*is this a stop word? */
say 'removing stop word:' if @.v;\=='' og=og+1;then @=delword(@,say v,'removing 1);stop word:' @s=@s @.v
og= og + 1; @= delword(@, v, 1); @s= @s @.v
end /*v*/ /*delete dead word from @ ──┘ */
 
if og\==0 then do; call build@; say; say 'ignoring' og "stop word"s(og).
say 'stop words: ' @s; say
end
$$$= /*nullify the possible longest path. */
Line 4,087 ⟶ 4,088:
g= words($$$)
say 'Of' # "words," MP 'path's(MP) "have the maximum path length of" g'.'
say; say 'One example path of that length is: ' word($$$, 1)
do m=2 to g; say left('', 36) word($$$, m); end /*m*/
end /*m*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)==1 then return arg(3); return word( arg(2) 's', 1) /*a pluralizer.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
build@: do i=1 for #; @.i= word(@, i) /*build a stemmed array from the list. */
F= left(@.i, 1); !.1.F= !.1.F + 1 /*F: 1st char; !.1.F=count of 1st char*/
L= right(@.i, 1); !.9.L= !.9.L + 1 /*L: last " !.9.L= " " last " */
end /*i*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
scan: procedure expose @. # !. $$$ MP MPL; parse arg $$$,!; p= ! - 1