How to resolve the algorithm Odd word problem step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Odd word problem step by step in the Sidef programming language

Table of Contents

Problem Statement

Write a program that solves the odd word problem with the restrictions given below.

You are promised an input stream consisting of English letters and punctuations.
It is guaranteed that:

A stream with six words:

The task is to reverse the letters in every other word while leaving punctuations intact, producing: while observing the following restrictions:

Work on both the   "life"   example given above, and also the text:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Odd word problem step by step in the Sidef programming language

Source code in the sidef programming language

func rev {
    (var c = STDIN.getc) \\ return()
    if (c ~~ /^[a-z]\z/i) {
        var r = rev()
        print c
        return r
    }
    return c
}

var (n=0, l=false)
while (defined(var c = STDIN.getc)) {
    var w = (c ~~ /^[a-z]\z/i)
    ++n if (w && !l)
    l = w
    if (n & 1) {
        print c
    } else {
        var r = rev()
        print(c, r)
        n = 0
        l = false
    }
}


  

You may also check:How to resolve the algorithm Truncatable primes step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Determine sentence type step by step in the Nim programming language
You may also check:How to resolve the algorithm Empty program step by step in the Odin programming language
You may also check:How to resolve the algorithm Arithmetic evaluation step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Convert decimal number to rational step by step in the Perl programming language