3 Replies - 426 Views - Last Post: 11 December 2018 - 12:56 PM Rate Topic: -----

#1 johny_smith   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-December 18

Using Nested For Loops To Create Ascii Art

Posted 10 December 2018 - 08:22 PM

Hi everyone,

I'm trying different ways to create advanced nested arrays using ascii art.

What I'm trying to achieve is the following:

Input amount of boxes:

2

Which need to be put in boxes, like so:

.---.
|.-.|
|| ||
|'-'|
'---'



This is inspired/ a remake of https://codegolf.sta...p5-nested-boxes

This exercise takes advantage of the many different ways of handling arrays/nested data in ruby and I'm interested in understanding the advance use of procs such as these ones:

This is one of the solutions of the original puzzle

g=->n{(1..n).map{g[Integer l=gets.chop]rescue l}}
w=->b{b.bytesize rescue b.map{|e|w[e]}.max+4}
p=->b,c{r=c-2
[?.+?-*r+?.,*b.map{|i|p[i,c-4]}.flatten.map{|k|"| #{k} |"},?'+?-*r+?']rescue[b.ljust(c)]}
puts p[b=g[1][0],w[b]]



Can you guys help me out?

Is This A Good Question/Topic? 0
  • +

Replies To: Using Nested For Loops To Create Ascii Art

#2 Lemur   User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1453
  • View blog
  • Posts: 3,633
  • Joined: 28-November 09

Re: Using Nested For Loops To Create Ascii Art

Posted 10 December 2018 - 09:50 PM

That's not advanced, that's code golf and being needlessly clever for the sake of it. It's not something you want to emulate.
Was This Post Helpful? 1
  • +
  • -

#3 johny_smith   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-December 18

Re: Using Nested For Loops To Create Ascii Art

Posted 10 December 2018 - 10:19 PM

Thanks for the feedback lemur, I'm trying to come up with a class/method that gives me the expected output, definitely not golfed, I was just making providing an example of something that kinda "works"
Was This Post Helpful? 0
  • +
  • -

#4 NeoTifa   User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4572
  • View blog
  • Posts: 19,277
  • Joined: 24-September 08

Re: Using Nested For Loops To Create Ascii Art

Posted 11 December 2018 - 12:56 PM

Well, it's just a matter of searching for the patterns. For instance, the sides are odd numbers, increasing by 2 for every box. Think of something along those lines.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1