How to resolve the algorithm Align columns step by step in the Phixmonti programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Align columns step by step in the Phixmonti programming language
Table of Contents
Problem Statement
Given a text file of many lines, where fields within a line are delineated by a single 'dollar' character, write a program that aligns each column of fields by ensuring that words in each column are separated by at least one space. Further, allow for each word in a column to be either left justified, right justified, or center justified within its column. Use the following text to test your programs:
Note that:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Align columns step by step in the Phixmonti programming language
Source code in the phixmonti programming language
include ..\Utilitys.pmt
0 40 repeat var gap
( "Given$a$text$file$of$many$lines,$where$fields$within$a$line$"
"are$delineated$by$a$single$'dollar'$character,$write$a$program"
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$"
"column$are$separated$by$at$least$one$space."
"Further,$allow$for$each$word$in$a$column$to$be$either$left$"
"justified,$right$justified,$or$center$justified$within$its$column." )
len var lines
def alignWords /# -1/0/1 for left/center/right #/
>ps
lines for
get len for >ps
tps get gap ps> get nip 1 +
tps -1 == if -1 * align else
tps 0 == if tostr align else
tps 1 == if align else
drop drop "Wrong!" exitfor
endif endif endif
print
endfor
drop
nl
endfor
ps> drop
enddef
lines for var i
i get "$" " " subst split
len for var j
j get len dup
gap j get rot
< if swap j set else swap drop endif var gap drop
endfor
i set
endfor
-1 alignWords nl
0 alignWords nl
1 alignWords nl
drop
You may also check:How to resolve the algorithm Selectively replace multiple instances of a character within a string step by step in the J programming language
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the BQN programming language
You may also check:How to resolve the algorithm Constrained random points on a circle step by step in the D programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the Yorick programming language
You may also check:How to resolve the algorithm Show the epoch step by step in the FreeBASIC programming language