How to resolve the algorithm Determine if a string has all unique characters step by step in the Factor programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Determine if a string has all unique characters step by step in the Factor programming language

Table of Contents

Problem Statement

Given a character string   (which may be empty, or have a length of zero characters):

Use (at least) these five test values   (strings):

Show all output here on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Determine if a string has all unique characters step by step in the Factor programming language

Source code in the factor programming language

USING: formatting fry generalizations io kernel math.parser
sequences sets ;

: repeated ( elt seq -- )
    [ dup >hex over ] dip indices first2
    "  '%c' (0x%s) at indices %d and %d.\n" printf ;

: uniqueness-report ( str -- )
    dup dup length "%u — length %d — contains " printf
    [ duplicates ] keep over empty?
    [ 2drop "all unique characters." print ]
    [ "repeated characters:" print '[ _ repeated ] each ] if ;

""
"."
"abcABC"
"XYZ ZYX"
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"
[ uniqueness-report nl ] 5 napply


  

You may also check:How to resolve the algorithm Loops/For step by step in the VBA programming language
You may also check:How to resolve the algorithm Aliquot sequence classifications step by step in the C programming language
You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Rock-paper-scissors step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Elementary cellular automaton step by step in the UNIX Shell programming language