Debugging Part 3

I am debugging the following program, and I started realising the disadvatanges of blind debugging. I had solved the problem
before. And I solved it through debugging. So now faced with the same problem I seem not to remember how I solved it. So here i
is the disadvatanges of blind debugging. It is adhoc and prone to blind programming. The other way I like to say it, is it is "hacky".
Not hack of breaking computers but that of prototyping something quickly without following principles. I am still in the process of
solving the problem below. When I am done, I will let you know how I did it.

;P09 (**) Pack consecutive duplicates of list elements into sublists.
;If a list contains repeated elements they should be placed in separate sublists.

;Example:
;* (pack '(a a a a b c c a a d e e e e))
;((A A A A) (B) (C C) (A A) (D) (E E E E))

to pack.run :list :item 
 ifelse emptyp :list  
  [output :list]
  [ifelse equalp first :list :item 
   [output sentence first :list pack.run (butfirst :list) :item]
   [output (list sentence first :list pack.run (butfirst :list) (first :list))]]
end 

to pack :list
 output pack.run :list []
end 

show pack [a a a a b c c a a d e e e e]

Comments

Popular posts from this blog

Recursion Part 1

Back to programming competitons