2
\$\begingroup\$

The infinity symbol is also called a lemniscate. Your program must draw a lemniscate with text via standard out (formatted with newline feeds) or graphically.

The infinity symbol (by my standards) must be continuous (that is, every non-whitespace character must be touching two other non-whitespace characters diagonally or orthogonally). It must also have two and no more than two gaps of enclosed whitespace (connectivity for whitespace is only orthogonal). Thus, the following output fails:

   ooo   ooo
 o    o o    o
o      o      o
 o    o o    o
   ooo   ooo

A correct version the above example might be

  oooo   oooo
 o    o o    o
o      o      o
 o    o o    o
  oooo   oooo

or

  ooo   ooo
 o   o o   o
o     o     o
 o   o o   o
  ooo   ooo

The size of the ∞ is unimportant. The orientation of the ∞ is unimportant. Symmetry is also unimportant. Graphical displays are accepted as well. Appropriate newline feeds are required in the output.

This is a question so answers will be scored in bytes, with less bytes being better.

\$\endgroup\$
  • 4
    \$\begingroup\$ "Your program must draw a lemnescate with text". OK: Print["∞"] \$\endgroup\$ – Not a tree Jul 18 '17 at 0:31
  • 3
    \$\begingroup\$ @Notatree You can golf that to Print@"∞", or "∞"& if a lambda function is acceptable. (I assume your language is Mathematica judging by the square brackets and upercase Print) \$\endgroup\$ – Pavel Jul 18 '17 at 0:45
  • 5
    \$\begingroup\$ Gotta have a winning criterion, or people'll bury your question. ;) Are you asking for the shortest code possible? \$\endgroup\$ – totallyhuman Jul 18 '17 at 0:48
  • 2
    \$\begingroup\$ Why has this been closed as too broad? I get that it lacks a winning criterion, which as JonathanAllen mentioned is likely intended to be code-golf, but closing as too broad without explanation baffles me. \$\endgroup\$ – Wheat Wizard Jul 18 '17 at 1:29
  • 5
    \$\begingroup\$ @WheatWizard, it clearly is too broad. Just looking at the first couple of answers shows that it's about arguing that a given output falls under the umbrella provided by the spec rather than golfing an implementation of a narrowly defined spec. It's really a bunch of similar questions rather than one question. \$\endgroup\$ – Peter Taylor Jul 18 '17 at 7:02

10 Answers 10

12
\$\begingroup\$

Desmos, 22 bytes

r=\sqrt{\sin 2\theta }

Try it here! Desmos is a graphing tool. This plots the polar equation:

r = sqrt[sin 2 theta]

which draws a lemniscate shape.

\$\endgroup\$
  • \$\begingroup\$ Where is "Desgos" and 4 bytes s½2Θ? :p \$\endgroup\$ – Jonathan Allan Jul 18 '17 at 1:27
  • 1
    \$\begingroup\$ @JonathanAllan Believe it or not I was working a language to interface with desmos, I called it "sindesi". I started the project 2 ish years ago and haven't gotten back to it yet. \$\endgroup\$ – Conor O'Brien Jul 18 '17 at 1:30
7
\$\begingroup\$

J, 8 bytes

3 5$' o'

Like Conor's, prints:

 o o 
o o o
 o o 

$ is J's shape operator, so we are creating a 3 x 5 grid, using the fill chacters o. When fill runs out, $ repeats them cyclically by default.

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ I really like this one :D \$\endgroup\$ – Conor O'Brien Jul 18 '17 at 0:48
  • \$\begingroup\$ Another approach for 11 bytes: 2":__,i.3 4 \$\endgroup\$ – Conor O'Brien Jul 18 '17 at 1:14
6
\$\begingroup\$

Mathematica, 4 bytes

∞&

I think this answer covers all the criteria

Mathematica, 17 bytes

Graphics@Text@∞

@ovs's opinion is that the right answer is...

Mathematica, 2 bytes

8&

and I agree!

\$\endgroup\$
  • \$\begingroup\$ Strictly speaking, I believe that's a snippet, not a program or function (but you can make it a function by putting & at the end). \$\endgroup\$ – Not a tree Jul 18 '17 at 8:04
  • 6
    \$\begingroup\$ Strictly speaking this is a very broad question...Why not? I'll edit! \$\endgroup\$ – J42161217 Jul 18 '17 at 8:08
  • 1
    \$\begingroup\$ I think an 8 matches all criteria as well. So 8& for 2 bytes \$\endgroup\$ – ovs Jul 18 '17 at 17:51
  • \$\begingroup\$ @ovs I agree! posted! \$\endgroup\$ – J42161217 Jul 18 '17 at 17:56
  • 1
    \$\begingroup\$ Neither single character answers fit the criteria that "every non-whitespace character must be touching [at least] two other non-whitespace characters diagonally or orthogonally" \$\endgroup\$ – Jonathan Allan Jul 19 '17 at 1:40
3
\$\begingroup\$

Mathematica - 49 bytes

ParametricPlot[{ReIm[Sin[t+I Sin[t]]]},{t,0,2Pi}]

Result:

Output

\$\endgroup\$
  • \$\begingroup\$ Is this acceptable? To answer your own challenge? \$\endgroup\$ – sergiol Jul 18 '17 at 0:24
  • \$\begingroup\$ Ps: The downvote was not me. \$\endgroup\$ – sergiol Jul 18 '17 at 0:25
  • 5
    \$\begingroup\$ Can I compete in my own challenge? \$\endgroup\$ – sergiol Jul 18 '17 at 0:27
  • \$\begingroup\$ Can you give a screenshot of the output? \$\endgroup\$ – Pavel Jul 18 '17 at 0:46
  • \$\begingroup\$ You can golf this down a bit, using @ and the fact you don't need a list for the first parameter: ReIm@Sin[t+I Sin@t]~ParametricPlot~{t,0,2Pi} for 44 bytes. \$\endgroup\$ – numbermaniac Jul 18 '17 at 7:37
2
\$\begingroup\$

///, 13 bytes

/z/ o o
/zozz

Try it online! Outputs:

 o o
o o o
 o o

I think this is the smallest valid "lemniscate" allowed by the rules.

\$\endgroup\$
  • \$\begingroup\$ I always try to improve my content, so please, do try and leave a comment with your downvote. \$\endgroup\$ – Conor O'Brien Jul 18 '17 at 16:19
2
\$\begingroup\$

Python 2, 21 19 bytes

print"o o\nooo\n"*3

Try it online!

This prints:

o o
ooo
o o
ooo
o o
ooo

It may not look like a lemnescate but it has two enclosed spaces (marked with x)

o o
ooo
oxo
ooo
oxo
ooo

And every o is connected to at least two other os. Thus despite not looking anything like what it is supposed to this fulfills the bare-minimum requirements.

\$\endgroup\$
  • \$\begingroup\$ heh, I was just going to say o o, ooo :) \$\endgroup\$ – Jonathan Allan Jul 18 '17 at 1:14
  • \$\begingroup\$ @JonathanAllan It looks like you pointing out an error helped me save a byte. So double thanks for that. :) \$\endgroup\$ – Wheat Wizard Jul 18 '17 at 1:15
  • 2
    \$\begingroup\$ I don't understand how you can ask why the question was voted "Too Broad" and also post this answer. The fact that you think you can argue that this meets the spec is exhibit A. And if this is valid, then surely 8 is a valid answer in CJam, GolfScript, etc.? \$\endgroup\$ – Peter Taylor Jul 18 '17 at 7:12
  • 1
    \$\begingroup\$ you can golf this down to 10 bytes: print"∞" \$\endgroup\$ – Uriel Jul 18 '17 at 8:31
  • 1
    \$\begingroup\$ @PeterTaylor I don't see what you are saying. The original post pretty clearly lays out specific requirements for answers, and this fits those requirements. Just because this looks like an 8 does not mean that this is the same as printing an 8. An 8 on its own meets none of the requirements. \$\endgroup\$ – Wheat Wizard Jul 18 '17 at 13:30
1
\$\begingroup\$

Jelly,  8  7 bytes

8RKḊs5Y

As a full program prints:

 2 3 
4 5 6
 7 8

Which seems to adhere to the specification.

Try it online!

How?

8RKḊs5Y - Main link: no arguments
8R      - range of 8 -> [1,2,3,4,5,6,7,8]
  K     - join with spaces -> [1,' ',2,' ',3,' ',4,' ',5,' ',6,' ',7,' ',8]
   Ḋ    - dequeue -> [' ',2,' ',3,' ',4,' ',5,' ',6,' ',7,' ',8]
    s5  - split into chunks of length 5 -> [[' ',2,' ',3,' '],[4,' ',5,' ',6],[' ',7,' ',8]]
      Y - join with newlines -> [' ',2,' ',3,' ',`\n`,4,' ',5,' ',6,'\n',' ',7,' ',8]
        - implicit print
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 9 bytes

o↘ooo‖B¬←

Draws the actual last example. 10-byte version that takes a size parameter as input:

G→↘↘No‖B¬←

Try it online! Link is to verbose version of code.

\$\endgroup\$
1
\$\begingroup\$

Charcoal, 7 bytes (ASCII-art version)

GHX²o‖B

Try it online!

The first part (GHX²o) prints a hollow polygon of size 2 in the X direction using the o char as border, that results in this:

 o 
o o
 o 

Then I only have to reflect the canvas horizontally (skipping the middle column), to get this:

 o o
o o o
 o o

Link to the verbose version.

\$\endgroup\$
  • \$\begingroup\$ 6 bytes: ↙oo‖BT. \$\endgroup\$ – Neil Jul 18 '17 at 21:27
  • \$\begingroup\$ @Neil whawhawhat??? You can use complex directions with ReflectButterfly?? \$\endgroup\$ – Charlie Jul 18 '17 at 21:30
  • \$\begingroup\$ You can use any sequence of directions. It just happens that :T expands to :Right, :Down, :Left which is exactly what's needed to reflect the two os to give the hexagon. \$\endgroup\$ – Neil Jul 18 '17 at 21:33
  • \$\begingroup\$ In fact you're using the same trick with your PolygonHollow - :X expands to the four diagonals, so PolygonHollow just draws a diamond shape. \$\endgroup\$ – Neil Jul 18 '17 at 21:34
  • \$\begingroup\$ The single character answer does not fit the criteria that "every non-whitespace character must be touching [at least] two other non-whitespace characters diagonally or orthogonally" \$\endgroup\$ – Jonathan Allan Jul 19 '17 at 1:44
0
\$\begingroup\$

C , 55 bytes

i;f(){while(i++<18)putchar(i%6?(i/6+i)%2?32:'o':'\n');}

outputs

Lemniscate

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.