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

Source code in the bcpl programming language

get "libhdr"

let diffchar(s) = valof
$(  for i=2 to s%0
        unless s%i = s%1 resultis i
    resultis 0
$)

let show(s) be
$(  let i = diffchar(s)
    writef("*"%S*" (length %N): ", s, s%0)
    test i=0
        do writes("all the same.*N")
        or writef("'%C' at index %N.*N", s%i, i)
$)

let start() be
$(  show("")
    show("   ")
    show("2")
    show("333")
    show(".55")
    show("tttTTT")
    show("4444 444k")
$)

  

You may also check:How to resolve the algorithm Sum of squares step by step in the Draco programming language
You may also check:How to resolve the algorithm Fork step by step in the BASIC programming language
You may also check:How to resolve the algorithm Host introspection step by step in the Action! programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bead sort step by step in the Wren programming language
You may also check:How to resolve the algorithm Globally replace text in several files step by step in the PureBasic programming language