How to resolve the algorithm Odd word problem step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Odd word problem step by step in the Racket 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 Racket programming language
Source code in the racket programming language
#!/bin/sh
#|
exec racket -tm- "$0" "$@"
|#
#lang racket
(define (even k)
(define c (read-char))
(cond [(eq? c eof) (k)]
[(not (char-alphabetic? c)) (k) (write-char c) (odd)]
[else (even (λ() (write-char c) (k)))]))
(define (odd)
(define c (read-char))
(unless (eq? c eof)
(write-char c)
(if (char-alphabetic? c) (odd) (even void))))
(provide main)
(define (main) (odd) (newline))
;; (with-input-from-string "what,is,the;meaning,of:life." main)
;; ;; -> what,si,the;gninaem,of:efil.
;; (with-input-from-string "we,are;not,in,kansas;any,more." main)
;; ;; -> we,era;not,ni,kansas;yna,more.
You may also check:How to resolve the algorithm Animate a pendulum step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Create a file on magnetic tape step by step in the Lua programming language
You may also check:How to resolve the algorithm Quaternion type step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Sorting algorithms/Stooge sort step by step in the Euphoria programming language