Constructing text with astericks
Basile B.
b2.temp at gmx.com
Wed May 30 23:08:03 UTC 2018
On Wednesday, 30 May 2018 at 22:57:06 UTC, aberba wrote:
> I've been given a challenge to write texts using asterisks to
> form the letters. D happen to have an unlimited amount of
> idioms yet i'm out out ideas as to the simplest approach. Task
> is to basically take a piece of text and write them as
> asterisks to the console.
>
> ***** *
> * *
> ***** *
> * *
> ***** *
>
> First solution I found was to create a class for each
> letter...like new A(), new B() and implement the logic withing
> each class. This doesn't scale and i'll have to write about 24
> or more classes.
>
> Another complex but "makes sense" solution will be to use a
> GRID system like old digital watches but i'll need a more
> complex grid to draw complex letters using a dictionary of
> REPOPULATED indexes of asterisk for each word. First use the
> length of the string to compute the grid size and iterate over
> each character to indentify the dictionary of a letter's
> indexes to use:
>
> *****
> *******
> ** **
> *******
> ** ***
> ** *** (an R using a more complex Grid)
>
>
> How will you approach this problem in D idiomatically?
I'd use an ascii art approach:
- Programatically make bitmaps with each letter rendered using a
monospaced font.
- use higher order functions to make 2d arrays of ' ' and '*'
More information about the Digitalmars-d-learn
mailing list