Exercism task, isogram

new topic     » topic index » view thread      » older message » newer message

As with Perl, TMTOWTDI in Euphoria, but is this a good way? Granted, the example in the .meta subdirectory of a given task isn't necessarily supposed to be the be-all and end-all. Mostly it's there for the Github Actions CI workflow.

A-a-a-a-anyway, how's my Euphoria?

t_isogram.e

include std/unittest.e  
 
--include isogram.ex  
include .meta/example.ex 
 
test_true("empty string" , isogram("")  ) 
test_true("isogram with only lower case characters" , isogram("isogram") )  
test_false("word with one duplicated character" , isogram("eleven")  ) 
test_false("word with one duplicated character from the end of the alphabet" , isogram("zzyzx") )  
test_true("longest reported english isogram" , isogram("subdermatoglyphic")  ) 
test_false("word with duplicated character in mixed case" , isogram("Alphabet") )  
test_false("word with duplicated character in mixed case, lowercase first" , isogram("alphAbet"))   
test_true("hypothetical isogrammic word with hyphen" , isogram("thumbscrew-japingly")  ) 
test_false("hypothetical word with duplicated character following hyphen" , isogram("thumbscrew-jappingly"))   
test_true("isogram with duplicated hyphen" , isogram("six-year-old")  ) 
test_true("made-up name that is an isogram" , isogram("Emily Jung Schwartzkopf"))   
test_false("duplicated character in the middle" , isogram("accentor")  ) 
test_false("same first and last characters" , isogram("angola")  ) 
test_false("word with duplicated character and with two hyphens" , isogram("up-to-date"))   
  
test_report()  

and .meta/example.ex

include std/text.e 
include std/search.e 
include std/sequence.e  
 
public function isogram( sequence str ) 
    str = upper(str) 
    sequence toRemove = {} 
    for i = 1 to length(str) do 
        if not is_in_range(str[i], {'A', 'Z'}) then 
            toRemove = append(toRemove, str[i]) 
        end if 
    end for 
    for i = 1 to length(toRemove) do 
        str = remove_all(toRemove[i], str) 
    end for 
    for i = 1 to length(str) do 
        for j = i + 1 to length(str) do 
            if str[i] = str[j] then 
                return 0 
            end if 
        end for 
    end for 
    return 1 
end function 
new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu