Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -1,17 +1,16 @@
# Split the text at $ and then justify each word 3 ways
N ← {"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."}
Ls ← ≡⍚(⊜□≠@$.)N # Get the word arrays
P ← +1/↥≡◇⧻/◇⊂Ls # Padding = Max length + 1
PadL ← /↥⬚@ ⊟↯P@
PadR ← ⍜⇌PadL
PadC ← PadL⊂↯:@ ⌊÷2-:P⧻.
Format! ← ≡&p≡(□/⊂≡◇^!°□)
# Demonstration of use of an array macro, which actually just resolves to
# ⊃(Format!PadC|Format!PadR|Format!PadL)Ls
Fall‼! ←^ $"⊃(_)"/⊂≡($"Format!_ |"°□)⇌
Fall‼!PadL PadR PadC Ls
Ls ← ≡⍚(⊜□≠@$.) # Get the word arrays.
PadC ← ↻:⊙(⌊÷2-)⊃(⬚@ ↙|⊙⧻) # Pad centre.
Pad! ← ≡/◇⊂⍉≡≡⍚^! # Apply a padding function to all.
Prep ← (
≡◇⬚""↙/↥≡◇⧻. # Pad each row to same length.
+1≡◇(/↥≡◇⧻).⍉ # Find required length for each column.
)
≡(&p/$"_\n_")[⊃(Pad!⬚@ ↙|Pad!(⬚@ ↙¯)|Pad!PadC)] Prep Ls N