How to resolve the algorithm Cheryl's birthday step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Cheryl's birthday step by step in the REXX programming language
Table of Contents
Problem Statement
Albert and Bernard just became friends with Cheryl, and they want to know when her birthday is. Cheryl gave them a list of ten possible dates: Cheryl then tells Albert the month of birth, and Bernard the day (of the month) of birth.
Write a computer program to deduce, by successive elimination, Cheryl's birthday.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Cheryl's birthday step by step in the REXX programming language
Source code in the rexx programming language
/*REXX pgm finds Cheryl's birth date based on a person knowing the birth month, another */
/*──────────────────────── person knowing the birth day, given a list of possible dates.*/
$= 'May-15 May-16 May-19 June-17 June-18 July-14 July-16 August-14 August-15 August-17'
call delDays unique('day')
$= unique('day')
$= unique('month')
if words($)==1 then say "Cheryl's birthday is" translate($, , '-')
else say "error in the program's logic."
exit 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
unique: arg u 2, dups; #= words($); $$= $
do j=# to 2 by -1
if u=='D' then parse value word($, j) with '-' x
else parse value word($, j) with x '-'
do k=1 for j-1
if u=='D' then parse value word($, k) with '-' y
else parse value word($, k) with y '-'
if x==y then dups= dups k j
end /*k*/
end /*j*/
do d=# for # by -1
do p=1 for words(dups) until ?==d; ?= word(dups,p)
if ?==d then $$= delword($$, ?, 1)
end /*d*/
end /*d*/
if words($$)==0 then return $
else return $$
/*──────────────────────────────────────────────────────────────────────────────────────*/
delDays: parse arg days; #= words(days)
do j=# for # by -1; parse value word(days, j) with x '-'; ##= words($)
do k=## for ## by -1; parse value word($, k) with y '-'
if x\==y then iterate; $= delword($, k, 1)
end /*k*/
end /*j*/
return $
You may also check:How to resolve the algorithm Word ladder step by step in the Java programming language
You may also check:How to resolve the algorithm Write entire file step by step in the BASIC programming language
You may also check:How to resolve the algorithm Modular arithmetic step by step in the Quackery programming language
You may also check:How to resolve the algorithm Web scraping step by step in the zkl programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Lang programming language