My Squiggly Lamp

13

0

While moving, I broke my lamp. Now, I need a new one. It's your job to make me a lamp! I'm not sure what size I want, though I know I want a squiggly one.

Your program/function must take in a number input, and print out a lamp with that many squiggles/bumps.

Examples:

Input:2

Output:

/--\
 ()
 ()
/__\

Input:3

Output:

/--\
 ()
 ()
 ()
/__\

Input:5

Output:

/--\
 ()
 ()
 ()
 ()
 ()
/__\

Rules:

  • 0 & negative numbers don't matter
  • To give the lamps (an this challenge) more of a variety, you must change the lamp shade.
    • They must be 4 characters wide and 1 character high.
    • They can be in any shape, including non-lamp-shade shapes.
    • They must not contain whitespace.
    • The base must stay the same.
  • You must show an example input & output with your lamp shade.
  • Shortest code wins!

phase

Posted 2015-07-21T20:12:12.073

Reputation: 2 540

But it doesn't squiggle at all!. Would have loved if inputs > 5 made it squiggle. – Optimizer – 2015-07-21T20:15:46.033

@Optimizer I think "bumpy" would be a better word for it, but "squiggly" sounds fun :3 – phase – 2015-07-21T20:16:58.600

Does space count as a character for lamp shade ? – Optimizer – 2015-07-21T20:19:39.340

@Optimizer No, forgot to add that in. – phase – 2015-07-21T20:20:01.483

Wait do I have to change the shade per input, or just make it different from the input? – Maltysen – 2015-07-21T20:23:03.203

@Maltysen The shade must be different from the examples provided, and must stay the same between inputs. – phase – 2015-07-21T20:23:47.507

22I downvoted. I think this is a boring ASCII art. There's a repeated section in the middle and no overlap between the parts, which are also too short to compress. It just has form ABBB..BBBC. The requirement to change a section just means people will use a short built-in string. – xnor – 2015-07-21T20:27:44.710

7You can all stop downvoting already! I think OP got the message. – xnor – 2015-07-21T21:16:54.130

1

@xnor I feel sorry for the poor guy. This is probably one of the most downvoted questions ever :/ http://i.stack.imgur.com/T4A7X.jpg

– Beta Decay – 2015-07-22T07:08:49.547

@BetaDecay ;__; – phase – 2015-07-22T07:17:48.427

1

Not voted in any way myself, but given the similarity with Draw an ASCII Lightning Bolt, I can understand the downvoters. Some little twist like having larger base for higher lamp, or having a repeated decoration only on each nth squiggle would made it a little bit different.

– manatwork – 2015-07-22T11:07:34.447

Answers

4

Pyth - 16 bytes

Uses quotes for the shade since N is preinitialized to that.

*N4VQ+d`();"/__\

Try it online here.

* 4            String repetition 4x, implicit print
 N             Preinitialized to Quote
VQ             For N in range(Q)
 +             String concat
  d            Space
   `()         Repr of empty tuple
;              Close for loop
"/__\          Implicitly print string, implicit close quote

Sample for 5:

""""
 ()
 ()
 ()
 ()
 ()
/__\

Maltysen

Posted 2015-07-21T20:12:12.073

Reputation: 25 023

7

Snowman 0.2.0, 42 chars

)vg10sB]"[--]
"sP:" ()
"sP;bR"/__"sP92wRsP

Sample run:

llama@llama:...Code/snowman/ppcg53483lamp$ snowman lamp.snowman
5
[--]
 ()
 ()
 ()
 ()
 ()
/__\

So I only noticed that I forgot to implement the ability to escape backslashes within strings when I solved this challenge. That's definitely going to be a thing in the next version, but for now, here's what I did to print the final line:

"/__"sP92wRsP

92 is the ASCII code for a backslash, wR wraps it in an array, and I can now print it with sP because "strings" in Snowman are actually just arrays of numbers.

Doorknob

Posted 2015-07-21T20:12:12.073

Reputation: 68 138

7Do you want to build a snow lamp? – Alex A. – 2015-07-21T21:52:08.757

3

><>, 43 41 38 bytes

"\__/"aiv
"&-1v!?:<&a" ()
~"!_\
?!;o>l

Input via a code point, e.g. space is 32. This uses part of the program's own code as the lampshade, resulting in something that looks like a satellite dish:

~\_!
 ()
 ()
 ()
 ()
 ()
/__\

(Suggestion thanks to @randomra)

For three more bytes, we can change the third line to add a bit more customisation:

"\__/"aiv
"&-1v!?:<&a" ()
__\"\~"/
?!;o>l

This produces one of those lamps which shoot light upwards, for lack of a better way of putting it:

\__/
 ()
 ()
 ()
 ()
 ()
/__\

Sp3000

Posted 2015-07-21T20:12:12.073

Reputation: 58 729

3

R, 54 52 46 bytes

cat("RRRR",rep(" ()",scan()),"/__\\",sep="\n")

In this version, input and output are almost mixed together :

{in/out}PUT :

> cat("RRRR",rep(" ()",scan()),"/__\\",sep="\n")
1: 4
2: 
Read 1 item
RRRR
 ()
 ()
 ()
 ()
/__\

EDIT 1 : -2 bytes thanks to @manatwork comment.
EDIT 2 : -6 bytes. Full credit goes to @manatwork again

Frédéric

Posted 2015-07-21T20:12:12.073

Reputation: 2 059

1Changes nothing but the look: " /_\\" should be "/__\\". BTW, is that \r necessary? – manatwork – 2016-08-02T10:17:23.140

@manatwork It did change the shape of the lamp's foot, making it more stable + your remark about \r saved me two bytes ! Should have re-read my code ! Thanks ! – Frédéric – 2016-08-02T10:22:39.850

1Hmm… Weird tool. Can't make it to work non-interactively. Anyway, cat("RRRR",rep(" ()",scan()),"/__\\",sep="\n") seems to work. – manatwork – 2016-08-02T10:37:15.297

@manatwork : well... I've never thought that this could work ! It's indeed a nice solution. R is full of surprises ! – Frédéric – 2016-08-02T10:42:15.907

Bonjour Frédéric, if you're still active on PPCG you can save 5 bytes

– JayCe – 2018-07-31T14:18:33.347

3

Straw, 26 bytes (non-competing)

<#~('--'
)>( ()
)-*>(/__\)>

Use '--' as lamp shade, take input in unary now in decimal

TuxCrafting

Posted 2015-07-21T20:12:12.073

Reputation: 4 547

How does this work? – Conor O'Brien – 2016-09-09T20:50:52.173

@BetaDecay *therefore noncompeting – Conor O'Brien – 2016-09-09T20:51:27.780

2

CJam, 18 bytes

"/__\
"" ()
"ri*1$

Sample run for input 5:

/__\
 ()
 ()
 ()
 ()
 ()
/__\

Try it online here

Optimizer

Posted 2015-07-21T20:12:12.073

Reputation: 25 836

2

JavaScript ES6, 34 bytes

i=>`|==|
${` ()
`.repeat(i)}/__\\`

The newlines are significant

Example with input of 5:

|==|
 ()
 ()
 ()
 ()
 ()
/__\

Downgoat

Posted 2015-07-21T20:12:12.073

Reputation: 27 116

2

sed, 28 bytes

s#.# ()\n#g
s#^\|$#/__\\\n#g

Takes input in unary. The shade is the obvious selection (same as the base).

Test run

$ echo -n 111 | sed -f lamp.sed
/__\
 ()
 ()
 ()
/__\

Dennis

Posted 2015-07-21T20:12:12.073

Reputation: 196 637

1

05AB1E, 17 15 13 11 bytes

„ (и„/_.ø)˜∞

-2 bytes (17 → 15) thanks to @EriktheOutgolfer.
-2 byte (13 → 11) after being inspired by @dzaima's Canvas answer.

Cap is the same as the base (/__\).

Explanation:

„ (            # Literal string " ("
   и           # Repeat " (" the input amount of times
               #  i.e. " (" and 3 → [' (',' (',' (']
    „/_        # Literal string "/_"
       .ø      # Surround the list of " (" with "/_" on both ends
               #  i.e. [' (',' (',' ('] → ['/_',[' (',' (',' (',' ('],'/_']
         ˜     # Flatten this list
               #  i.e. ['/_',[' (',' (',' ('],'/_'] → ['/_',' (',' (',' (','/_']
          ∞    # Mirror each item
               #  i.e. ['/_',' (',' (',' (','/_'] → ['/__\',' () ',' () ',' () ','/__\']
               # And output the list new-line delimited (implicitly due to the mirror)

Old 13 bytes answer:

„/_D„ (Iиs)˜∞

Try it online.

Kevin Cruijssen

Posted 2015-07-21T20:12:12.073

Reputation: 67 575

1

PowerShell 5.1, 28 26 Bytes

Thanks Mazzy for 2 bytes

8008;," ()"*"$args";"/__\"

Since the shade can be any 4 characters, using a number saves a pair of quotes. The hardest part was finding a nice looking shade.

Output:

PS C:\Users\ItsMe\Desktop> .\scratch.ps1 4
8008
 ()
 ()
 ()
 ()
/__\

Veskah

Posted 2015-07-21T20:12:12.073

Reputation: 3 580

nice lamp shade ) – mazzy – 2018-08-01T08:50:14.150

1try this 8008;," ()"*"$args";"/__\" – mazzy – 2018-08-01T08:56:21.697

1

Kotlin, 36 bytes

{"|MM|\n${" ()\n".repeat(it)}/__\\"}

Try it online!

snail_

Posted 2015-07-21T20:12:12.073

Reputation: 1 982

1

Canvas, 8 bytes

(×_¶/e⟳║

Try it here!

Explanation:

(×        repeat "(" input times
  _¶/e    encase it on both sides in "_\n/"
          the 1st line is surrounded in "_" and the second ends and starts with "/"
      ⟳   rotate the string clockwise without changing characters
       ║  palindromize horizontally with 0 overlap

dzaima

Posted 2015-07-21T20:12:12.073

Reputation: 19 048

1

Whitespace, 169 bytes

[S S S N
_Push_0][T  N
T   T   _Read_STDIN_as_integer][S S S T S T T   T   S S N
_Push_92_\][S S S T S T T   T   T   T   N
_Push_95__][S N
S _Duplicate_95__][S S S T  S T T   T   T   N
_Push_47_/][N
S S N
_Create_Label_LOOP][S S S N
_Push_0][T  T   T   _Retrieve_at_address_0][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][S S S N
_Push_0][S N
T   _Swap_top_two][T    T   S _Store_at_address_0][N
T   T   S N
_If_neg_Jump_to_Label_PRINT][S S S T    S T S N
_Push_10_newline][S S S T   S T S S T   N
_Push_41_)][S S S T S T S S S N
_Push_40_(][S S S T S S S S S N
_Push_32_space][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT][S S S T    S T S N
_Push_10_newline][S S S T   S S S S T   N
_Push_33_!][S N
S _Duplicate_33_!][S N
S _Duplicate_33_!][S N
S _Duplicate_33_!][N
S S T   N
_Create_Label_LOOP_2][T N
S S _Print_as_character][N
S N
T   N
_Jump_to_Label_LOOP_2]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Pushes all characters in reversed order to the stack, and then prints them in a loop.

Integer i = STDIN as input
Push "\__/" to the stack
Start LOOP:
  i = i - 1
  if(i is negative):
    Go to function PRINT
  Push "\n)( " to the stack
  Go to next iteration of LOOP

function PRINT:
  Push "\n!!!!" to the stack
  Start LOOP_2:
    Print top as character to STDOUT
    Go to next iteration of LOOP_2

NOTE: i in the pseudo-code above is stored back in the heap in every iteration of LOOP, because we don't want to leave it on the stack to be printed at the end.

Kevin Cruijssen

Posted 2015-07-21T20:12:12.073

Reputation: 67 575

1

Excel, 31 bytes

An anonymous worksheet function that takes input as a numeric from range [A1] and outputs to the calling cell.

This lamp is musical - and will help to liven and lighten up your day.

="/\
"&REPT(" ()
",A1)&"/__\"

Output

I love lamp

Taylor Scott

Posted 2015-07-21T20:12:12.073

Reputation: 6 709

1

Japt, 17 bytes

Æ` ()`Ãi¥² p"/__\

Try it online!

Output for 5 is:

====
 ()
 ()
 ()
 ()
 ()
/__\

Oliver

Posted 2015-07-21T20:12:12.073

Reputation: 7 160

Nice trick with the ¥. – Shaggy – 2019-02-01T00:03:56.773

@Shaggy Thank you! :D – Oliver – 2019-02-01T01:44:39.413

1

Python 2, 36 bytes

print"-"*4+"\n ()"*input()+"\n/__\\"

For input 4:

----
 ()
 ()
 ()
 ()
/__\

Note that for Python that any lamp shade using pipes is a byte less.

-1 bytes thanks to @Alex!

Beta Decay

Posted 2015-07-21T20:12:12.073

Reputation: 21 478

1I think if you change the lampshade to a single character and multiply it by 4 you can save one byte: print"-"*4+"\n ()"*input()+"\n/__\\" – Alex – 2018-08-05T02:33:57.783

1

jq: 30 characters

(29 characters code + 1 character command line option.)

8888,(range(.)|" ()"),"/__\\"

Sample run:

bash-4.3$ jq -r '8888,(range(.)|" ()"),"/__\\"' <<< 3
8888
 ()
 ()
 ()
/__\

On-line test (Passing -r through URL is not supported – check Raw Output yourself.)

manatwork

Posted 2015-07-21T20:12:12.073

Reputation: 17 865

1

Gema: 30 characters

*=gema\n@repeat{*;\ ()\n}/__\\

Sample run:

bash-4.3$ gema '*=gema\n@repeat{*;\ ()\n}/__\\' <<< 3
gema
 ()
 ()
 ()
/__\

manatwork

Posted 2015-07-21T20:12:12.073

Reputation: 17 865

1

C, 54 bytes

Call f() with the desired height of the lamp.

f(n){for(puts("||||");n--;puts(" ()"));puts("/__\\");}

Try it on ideone.

Example output for 5:

||||
 ()
 ()
 ()
 ()
 ()
/__\

owacoder

Posted 2015-07-21T20:12:12.073

Reputation: 1 556

1

Pyke, 15 bytes

" ()"~mQAD"/__\

Try it here!

     ~m         - 1000
" ()"           -  " ()"
       QAD      - duplicate(^) input times
          "/__\ - "/__\"

Outputs:

1000
 ()
 ()
/__\

Blue

Posted 2015-07-21T20:12:12.073

Reputation: 26 661

0

Noether, 26 bytes

"-"4*P?I(" ()"P?!i)"/__\"P

Try it online!

Beta Decay

Posted 2015-07-21T20:12:12.073

Reputation: 21 478

0

Ahead, 38 bytes

I"|MM|"Wr
~W" ()"oN<s!:-1~
@W"/__\"oN<

Try it online!

Samples

1
|MM|
 ()
/__\

2
|MM|
 ()
 ()
/__\

3
|MM|
 ()
 ()
 ()
/__\

snail_

Posted 2015-07-21T20:12:12.073

Reputation: 1 982

2Could you maybe provide a link to an online testing environment so one can easily run your submission? – Jonathan Frech – 2018-07-30T03:32:25.267

@JonathanFrech TIO link now available – snail_ – 2018-07-31T02:19:13.607

0

Perl 5, 24 bytes

$_=$<.'
 ()'x$_.'
/--\
'

Try it online!

Uses 1000 as the cap.

Dom Hastings

Posted 2015-07-21T20:12:12.073

Reputation: 16 415

0

Befunge-93, 50 bytes

"\__/"&v
0-1_v#:<g00" ()"*25p0
*25$<>:#,_@#::::"_"

Try it online!

Example with Input 3

____
 ()
 ()
 ()
/__\

ItsJ0el

Posted 2015-07-21T20:12:12.073

Reputation: 95

0

PHP, 38 bytes

/--\<?while($argn--)echo"
 ()"?>

/__\

Save to file; run as pipe with -nF or try it online.

Titus

Posted 2015-07-21T20:12:12.073

Reputation: 13 814

0

Charcoal, 16 12 10 bytes

8E⊕N(←_/‖M

-4 bytes thanks to @ASCII-only.
-1 byte thanks to @Neil by using a Map.

Try it online (verbose) or try it online (pure).

Uses 8()8 as cap, but the 8 can be any character from Charcoal's code-page that isn't used as a command/operator.

Explanation:

Print 8:

Print("8");
8

Print ( the input+1 amount of times downwards:

Print(Map(Incremented(InputNumber()), "("));
E⊕N(

Then after that print _/ in a left direction:

Print(:Left, "_/");
←_/

And finally mirror everything vertically:

ReflectMirror();
‖M

Kevin Cruijssen

Posted 2015-07-21T20:12:12.073

Reputation: 67 575

112? – ASCII-only – 2018-08-06T06:12:23.873

@ASCII-only Thanks! Forgot about Print(... Time(...));, and smart way of using Move(:DownLeft); so regular Prints instead of MultiPrints can be used and the space at " (" can be saved at the same time. – Kevin Cruijssen – 2018-08-06T06:33:55.813

You can save a byte here using Map too, although you'll need to rewrite the way you print the {8 so that you don't have to explicitly move to the next line. – Neil – 2019-01-27T12:23:20.940

@Neil I've found a few 12-byte alternatives with Map, but not 11 yet. Alternative 1; Alternative 2.

– Kevin Cruijssen – 2019-01-27T16:55:24.817

Alternative 2 is closer, but you can print those two characters in 3 bytes and still end up with the cursor in the correct place. – Neil – 2019-01-27T17:11:24.177

1@Neil Still not sure how to do {8 in 3 bytes while moving the cursor at the same time, but I've been able to golf 2 bytes instead of 1 by using 8( instead of {8 as lamp shade. Still curious how to do the {8 in 3 bytes through. :) – Kevin Cruijssen – 2019-01-27T17:43:56.850

1Print("{"); Print(:Down, "8"); – Neil – 2019-01-27T17:55:39.917

@Neil Ah, of course! So simple now that I see it.. – Kevin Cruijssen – 2019-01-27T17:56:07.837

0

Brain-Flak, 164 bytes

({}<((((((((((()()){}()){})()){}()){}())){}()))[[]]()){({}<>)<>}<>>()){({}[()]<(((((((()()){}()){}){}){}())[()])[(()()()()){}])((()()()()()){})>)}(((({}{}{}{}{}))))

Try it online!

Output for 5:

{{{{
 ()
 ()
 ()
 ()
 ()
/__\

MegaTom

Posted 2015-07-21T20:12:12.073

Reputation: 3 787

0

SWI-Prolog, 73 60 bytes

a(X):-write(golf),writef("%r",["\n ()",X]),write("\n/__\\").

a(5). outputs

golf
 ()
 ()
 ()
 ()
 ()
/__\

Fatalize

Posted 2015-07-21T20:12:12.073

Reputation: 32 976

0

Julia, 36 bytes

n->print("|~~|\n"*" ()\n"^n*"/__\\")

This creates an unnamed function that takes an integer as input and prints to stdout.

Example:

julia> f(4)
|~~|
 ()
 ()
 ()
 ()
/__\

Alex A.

Posted 2015-07-21T20:12:12.073

Reputation: 23 761

0

Java 7 11, 84 83 37 bytes

n->"i!!i\n"+" ()\n".repeat(n)+"/__\\"

Try it online. (NOTE: Java 11 isn't supported on TIO yet, so String.repeat(int) has been emulated with repeat(String,int) for the same byte-count.)

Uses i!!i as cap. ¡!!¡ looks better, but is two bytes more.

Explanation:

n->                    // Method with integer parameter and String return-type
  "i!!i\n"             //  Return the cap + new-line
  " ()\n".repeat(n)    //   appended with " ()" and a new-line `n` amount of times
  "/__\\"              //   append with "/__\"

Kevin Cruijssen

Posted 2015-07-21T20:12:12.073

Reputation: 67 575

0

Neoscript, 28 bytes

{n|"[~~]
"+" ()
"*n+"/--\\"}

TuxCrafting

Posted 2015-07-21T20:12:12.073

Reputation: 4 547

0

Bash + coreutils, 37 bytes

yes ' ()'|sed '1i####
'$1'{a/__\\
q}'

The newlines are necessary and counted in the bytes total. GNU sed is required.

Run:

./squiggly_lamp.sh 2

Output:

####
 ()
 ()
/__\

seshoumara

Posted 2015-07-21T20:12:12.073

Reputation: 2 878

0

Ruby, 42 bytes

i=gets.to_i
puts "|--|\n#{" ()\n"*i}/__\\"

dkudriavtsev

Posted 2015-07-21T20:12:12.073

Reputation: 5 781

-1

PyMin, 24 bytes / 17 characters

»ƒ+ѿ+" ø\n"*¬+ɓ+ѿ

Output for 5:

Fizz
 ()
 ()
 ()
 ()
 ()
Buzz

Shorter version with v0.5:

21 bytes / 13 characters

»ƒƜ+" ø¶"¯+ɓƜ

acrolith

Posted 2015-07-21T20:12:12.073

Reputation: 3 728

The base of the lamp must be /__. – snail_ – 2018-08-07T03:08:22.740