×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
dcl-s content Varchar(64) Inz('');
dcl-s result Varchar(44) Inz('');
dcl-s chr Char(1) Inz('');
dcl-s lastchr Char(1) Inz('');
dcl-s i Int(5) Inz(0);
dcl-s j Int(5) Inz(0);
dcl-s InWord Ind Inz(*Off);
dcl-s count Int(5);
dcl-s added Ind Inz(*Off);
for i=1 to %size(string);
chr = %subst(string: i: 1);
if %check(alpha: chr) > 0;
if InWord;
if not added;
count += 1;
endif;
result += %char(count - 1) + lastchr;
endif;
InWord = *Off;
result += chr;
else;
lastchr = chr;
added = *Off;
if not InWord;
result += chr;
count = 0;
content = '';
elseif %check(content: chr) > 0;
count += 1;
content += chr;
added = *On;
endif;
InWord = *On;
endif;
endfor;
if InWord;
result += %char(count-1) + lastchr;
endif;
dsply 'Result: ' '*EXT' result;
end-proc;
Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx
-----John Yeung <gallium.arsenide@xxxxxxxxx> wrote: -----
To: "RPG programming on the IBM i / System i" <rpg400-l@xxxxxxxxxxxx>
From: John Yeung <gallium.arsenide@xxxxxxxxx>
Date: 06/30/2016 08:29PM
Cc: IBMi Open Source Roundtable <opensource@xxxxxxxxxxxx>
Subject: Clarified interview question (programming puzzle)
In another thread, Craig Pelkie presented a contrived programming task
being used as an interview question. I think we all agreed that there
were a number of problems with it as an interview question for an
actual, real-world RPG programming job.
But a few of us found it at least somewhat intriguing just as a
puzzle, and I wound up coding it myself, just for fun. It took me
significantly longer than I expected. I wasn't timing myself
carefully, but I was purposely trying to do it fairly quickly, and it
still took me probably two hours, give or take.
Then I tried to solve the same puzzle in Python, and it was kind of
ridiculous how easy it was, just taking a few minutes.
Here is the puzzle, restated to try to correct some of the terminology
problems in the original:
Write some RPG code which takes a string and transforms it according
to the following rules:
1. An "alphabetic character" is defined as a case-sensitive letter in
the English alphabet, so there are 52 possible different alphabetic
characters: A-Z and a-z. Everything else is a nonalphabetic character.
2. A "word" is defined as a contiguous sequence of one or more
alphabetic characters. Words are separated by one or more
nonalphabetic characters. Any two adjacent alphabetic characters must
belong to the same word (no two words can just butt up against each
other; they must be separated by at least one nonalphabetic
character).
3. Each word in the input must be replaced by the following: The first
character in the word, followed by the count of different characters
between (not inclusive of) the first character and the last character
in the word, followed by the last character in the word. This is
probably best understood with a few examples.
foo -> f1o
bar -> b1r
blue -> b2e
book -> b1k
Automotive -> A6e
AutomOtive -> A7e
my -> m0y
a -> a0a
aa -> a0a
4. All nonalphabetic characters should "pass through" unchanged to the
output. Examples of complete input -> complete output, using
single-quotes to denote the beginning and end of strings, as you would
see in normal RPG:
5. You can use whatever mechanism of input and output you like. You
could write a program which accepts a string as a parameter and uses
the same parameter as output; you could write a subprocedure; you
could output to a spooled file; whatever.
I think that should be enough to clearly define the task. If you are
interested in trying this and still need more clarification, just ask.
I believe that the spirit of the problem involves using only RPG,
without embedded SQL, but this is just for fun so if you want to use
it, go ahead. Here's the Python solution I came up with, taking one
command-line parameter as input and printing the output to the screen
(well, technically to stdout):
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.