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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Determine if a string has all the same characters step by step in the Quackery 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 seven 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 the same characters step by step in the Quackery programming language

Source code in the quackery programming language

  [ 0 swap
    dup size 0 = iff 
      drop done 
    behead swap witheach
      [ over != if
          [ drop i^ 1+
            swap conclude ] ]
    drop ]                    is allsame ( [ --> n )

  ( 0 indicates all items are the same,
    otherwise n is first different item )

  [ say ' String: "' dup echo$
    say '" length ' dup size echo  
    dup allsame dup 0 = iff
      [ say ', all characters are the same.'
        2drop ]
    else
      [ say ', first difference is item '
        dup echo 
        say ', char "' 
        peek dup emit
        say '", hex: '
        16 base put echo base release
        say '.' ]
    cr ]                      is task    ( $ -->   )

  $ ""          task
  $ "   "       task
  $ "2"         task
  $ ".55"       task
  $ "tttTTT"    task
  $ "4444 444k" task

  

You may also check:How to resolve the algorithm 15 puzzle game step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Comments step by step in the langur programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the TI-89 BASIC programming language
You may also check:How to resolve the algorithm Superellipse step by step in the REXX programming language
You may also check:How to resolve the algorithm Named parameters step by step in the PicoLisp programming language