Programming Corner from Icon Newsletter 17


March 1, 1985 ; Icon Version 5

Old Business

A number of readers objected that the following two expressions from the last Newsletter are not equivalent:
if not (1 <= i <= *s) then ...

if *s < i < 1 then ...
Actually, no claim of equivalence was made. As an exercise, determine in what situations the two expressions are equivalent.

Anagramming

There is an easy way in Icon, given a string s, to produce another string that contains the characters of s in alphabetical order with duplicate characters removed:
string(cset(s))
Problem: Write a procedure anagram(s) that produces a string consisting of the characters in s in alphabetical order, but without the deletion of duplicates. For example,
anagram("hello")
should produce ehllo.

Experiment with different techniques to try to find the fastest method.


Icon home page