Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Gamer Meme Creator

+5
−0

Challenge

You will be given a string and an ascii art as input.

  • The string must be placed above the ascii art, and centered based on its longest line.
  • The text BOTTOM TEXT must be placed below the art and centered based on the ascii art's longest line.

The centering can be biased toward the left or right by 1 character if given text cannot be centered exactly.

Examples

Text: Hello, World!

Art(source:https://www.asciiart.eu/animals/camels):

        _
    .--' |
   /___^ |     .--.
       ) |    /    \
      /  |  /`      '.
     |   '-'    /     \
     \         |      |\
      \    /   \      /\|
       \  /'----`\   /
       |||       \\ |
       ((|        ((|
       |||        |||
jgs   //_(       //_(

Output:

      Hello, World!      
        _                
    .--' |               
   /___^ |     .--.      
       ) |    /    \     
      /  |  /`      '.   
     |   '-'    /     \  
     \         |      |\ 
      \    /   \      /\|
       \  /'----`\   /   
       |||       \\ |    
       ((|        ((|    
       |||        |||    
jgs   //_(       //_(    
       BOTTOM TEXT       

More info

  • You may have trailing and leading whitespace on each line as long as the art is properly centered.
  • ascii art can be taken as array of string, character arrays, so on.
  • art will always be in ascii/extended ascii.
  • given string will not exceed the width of ascii art, and ascii art will always have width ≥ 11.
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Padding? (1 comment)

4 answers

+4
−0

Ruby, 67 65 bytes

-2 from Razetime

->s,a{[s.center(l=a.map(&:size).max),*a,"BOTTOM TEXT".center(l)]}

Takes the art and outputs as a list of lines.

Try it online!

History
Why does this post require moderator attention?
You might want to add some details to your flag.

2 comment threads

Input is a string, not an array of strings (3 comments)
[65 bytes](https://tio.run/##ZZDBSgMxEIbveYoxB5PIbnKXbg@FhV6kIHsQjKZRt1JZ22Wzxarx2deMzfTiHMI/Xz5mYIbD... (1 comment)
+2
−0

Scala, 98 83 bytes

Saved 15 bytes thanks to Shaggy!

a=>t=>{val w=a.map(_.size).max
(" "*(w-t.size>>1)+t)+:a:+" "*(w/2-5)+"BOTTOM TEXT"}

Try it online!

a is the ASCII art, t is the string on top. w is the size of the longest line in the art, used for centering. A line x can be centered using " "*((w-x.size)/2)+x (no padding on the right side). We do that for both t and BOTTOM TEXT, then join on newlines.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Some Savings (3 comments)
+2
−0

Japt, 19 bytes

Takes the artwork as an array of lines and the string as the second input. If we can require that the artwork be right padded with spaces on each line so they're all the same length then the first 2 bytes can be removed but I suspect that them being different lengths is integral to the challenge.

ú iV p`Þ­om ’xt`u)û

Try it

ú iV p`...`u)û     :Implicit input of array U & string V
ú                  :Right pad each element in U with spaces to the length of the longest.
  iV               :Prepend V
     p             :Push
      `...`        :  Compressed string "bottom text"
           u       :  Uppercased
            )      :End push
             û     :Centre pad each element with spaces to the length of the longest
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

"I suspect that them being different lengths is integral to the challenge." correct, that is part of ... (1 comment)
+2
−0

Haskell, 116 bytes

a#b=a!b:a++[a!"BOTTOM TEXT"]
a!b=replicate(div(m a-k b)2)' '++b
m=foldr1 max.map k
k=length.dropWhile(==' ').reverse

Try it online!

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »