I Love Sardines

WallyWest 08/21/2017. 12 answers, 2.823 views
code-golf ascii-art

I love sardines, I can't get enough of them, and so does my computer, the Omnilang 5000, which is language agnostic.

To give my computer the joy of experiencing sardines, I've decided to feed him a number of programs that are capable of displaying on the screen tins of sardines in various orientations, and showing up to ten sardines.

In this challenge, you'll be responsible for creating the programs based on these parameters:

The input

A number (between 0 and 10) and a letter from one of the following "LR" (representing Left or Right respectively) For example: 3L or 5R; how this is input into the program is up to you.

Output

An open tin of sardines with the sardines facing the indicated direction, with the key (represented by the "%" character) and peeled lid (rolled up tin at the end represented by the "@" character) located at the top of the tin.

  • All sardines must face the direction indicated by the input.
  • All sardines will have bodies five characters long between the gill (either ")" or "(" ) and the tail "><"
  • The key and peeled lid roll will always be facing the opposite direction to the sardines.
  • The tin must have a 3-D look to it as shown below in the examples.
  • The minimum height of the tin is 3 sardines in height. So if a number is less than 3, a tin of 3 sardines in height must be shown, with the inputted number of sardines in it. Otherwise, the tin must be the number of sardines high indicated in the input. So input of 0R or 0L will show an empty sardine tin.
  • Any other input that can't be validated will not show anything.

For example, for "3L"

 __________
(__________@%
|<*)_____><||
|<*)_____><||
|<*)_____><||
'==========''

For "7R"

   __________
 %@__________)
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ''=========='  

For "2L"

 __________
(__________@%
|<*)_____><||
|<*)_____><||
|          ||
'==========''

For "0R"

   __________
 %@__________)
 ||          |
 ||          |
 ||          |
 ''=========='

"0L"

 __________
(__________@%
|          ||
|          ||
|          ||
'==========''

Invalid input will not return anything...

  • This is code golf, so the smallest number of characters will win this challenge.
  • No Loopholes as per usual.

12 Answers


Not a tree 07/31/2017.

><>, 250 235 + 3 = 238 bytes

</~?{"  __________"a:="L"i&
o/?=1l
:/}rv?{~$?{"()__________@%":
l< o/?=1
:&oa/&~$?(3$@0-3:
/!?:</"||><_____(*>|"av?@:$-1
 /=?/v"|<*)_____><||"a/
 \2lo/
\~&
\>:?!\1+$::{a"|"{?:"          ||"{?~
<\?=2 lo
"'":~/~?{"''==========":?{
;!?lo<

Try it online, or watch it at the fish playground! Reads the "L" or "R" from STDIN and assumes the number of sardines is already on the stack (needs a -v flag for +3 bytes).

Because of course I had to write this in ><>.

5 comments
3 WallyWest 07/30/2017
Writing this solution in Fish is inspired...
7 Jop V. 07/30/2017
+1 just for writing this in ๐ŸŸ
Jarko Dubbeldam 07/31/2017
How does the fish playground work? I can't get it to run. Where do I place the input?
Not a tree 07/31/2017
@JarkoDubbeldam, after copying the code into the window and submitting it, you need to put the number of sardines where it says "initial stack" (simulating the -v flag), and the direction ("L" or "R") under "give input to the program" then click "give". (I've edited the answer to hopefully make that clearer.)
1 Jarko Dubbeldam 07/31/2017
Awesome :D Must be nice during debugging too

betseg 07/31/2017.

Emojicode, 456 448 bytes

๐Ÿ‹๐Ÿš‚๐Ÿ‡๐Ÿ–๐ŸŸd๐Ÿš‚๐Ÿ‡๐Ÿฆa๐Ÿ˜›0d๐ŸŠa๐Ÿ‡๐Ÿ˜€๐Ÿ”ค __________โŒn(__________@%๐Ÿ”ค๐Ÿ‰๐Ÿ“๐Ÿ‡๐Ÿ˜€๐Ÿ”ค  __________โŒn%@__________)๐Ÿ”ค๐Ÿ‰๐Ÿ”‚iโฉ0๐Ÿ•๐Ÿ‡๐ŸŠa๐Ÿ‡๐Ÿ˜€๐Ÿ”ค|<*)_____><||๐Ÿ”ค๐Ÿ‰๐Ÿ“๐Ÿ‡๐Ÿ˜€๐Ÿ”ค||><_____(*>|๐Ÿ”ค๐Ÿ‰๐Ÿ‰๐ŸŠโ–ถ๏ธ4๐Ÿ•๐Ÿ‡๐Ÿ”‚iโฉ0โž–3๐Ÿ•๐Ÿ‡๐ŸŠa๐Ÿ‡๐Ÿ˜€๐Ÿ”ค|          ||๐Ÿ”ค๐Ÿ‰๐Ÿ“๐Ÿ‡๐Ÿ˜€๐Ÿ”ค||          |๐Ÿ”ค๐Ÿ‰๐Ÿ‰๐Ÿ‰๐ŸŠa๐Ÿ‡๐Ÿ˜€๐Ÿ”ค'==========''๐Ÿ”ค๐Ÿ‰๐Ÿ“๐Ÿ‡๐Ÿ˜€๐Ÿ”ค''=========='๐Ÿ”ค๐Ÿ‰๐Ÿ‰๐Ÿ‰

Takes 2 arguments: first one is lines, second one is direction (0 or 1).

Try it online!

"Readable" ungolfed version and pseudocode version:

๐Ÿ‹ ๐Ÿš‚ ๐Ÿ‡
  ๐Ÿ– ๐ŸŸ  d ๐Ÿš‚  ๐Ÿ‡
    ๐Ÿฆ a  ๐Ÿ˜› 0 d

    ๐ŸŠ a ๐Ÿ‡
      ๐Ÿ˜€ ๐Ÿ”ค __________โŒn(__________@%๐Ÿ”ค
    ๐Ÿ‰
    ๐Ÿ“ ๐Ÿ‡
      ๐Ÿ˜€ ๐Ÿ”ค  __________โŒn%@__________)๐Ÿ”ค
    ๐Ÿ‰

    ๐Ÿ”‚ i โฉ 0 ๐Ÿ• ๐Ÿ‡
      ๐ŸŠ a ๐Ÿ‡
        ๐Ÿ˜€ ๐Ÿ”ค|<*)_____><||๐Ÿ”ค
      ๐Ÿ‰
      ๐Ÿ“ ๐Ÿ‡
        ๐Ÿ˜€ ๐Ÿ”ค||><_____(*>|๐Ÿ”ค
      ๐Ÿ‰
    ๐Ÿ‰

    ๐ŸŠ โ–ถ๏ธ 4 ๐Ÿ• ๐Ÿ‡
      ๐Ÿ”‚ i โฉ 0  โž– 3 ๐Ÿ•  ๐Ÿ‡
        ๐ŸŠ a ๐Ÿ‡
          ๐Ÿ˜€ ๐Ÿ”ค|          ||๐Ÿ”ค
        ๐Ÿ‰
        ๐Ÿ“ ๐Ÿ‡
          ๐Ÿ˜€ ๐Ÿ”ค||          |๐Ÿ”ค
        ๐Ÿ‰
      ๐Ÿ‰
    ๐Ÿ‰

    ๐ŸŠ a ๐Ÿ‡
      ๐Ÿ˜€ ๐Ÿ”ค'==========''๐Ÿ”ค
    ๐Ÿ‰
    ๐Ÿ“ ๐Ÿ‡
      ๐Ÿ˜€ ๐Ÿ”ค''=========='๐Ÿ”ค
    ๐Ÿ‰
  ๐Ÿ‰
๐Ÿ‰

๐Ÿ‘ต
extendclass int { // this makes the first argument be an int without declaring it
  func ๐ŸŸ(int d) {
    const a = 0 == d // a bool

    if a {
      print " __________\n(__________@%"
    }
    else {
      print "  __________\n%@__________)"
    }

    for i in range(1, arg) {
      if a {
        print "|<*)_____><||"
      }
      else {
        print "||><_____(*>|"
      }
    }

    if 4 > arg {
      for i in range(0, arg - 3) {
        if a {
          print "|          ||"
        }
        else {
          print "||          |"
        {
      }
    }

    if a {
      print "'==========''"
    }
    else {
      print "''=========='"
    {
  }
}
๐Ÿ‘ต
3 comments
2 WallyWest 07/30/2017
Never come across Emojicode before but that is a mind f**k and a half... Crazy! Love it!
Taylor Scott 07/31/2017
... why does this language even exist? I mean, I like it, but why? and how long did it take you to learn it?
1 betseg 07/31/2017
@TaylorScott 1) dunno, i didn't create it. 2) a few hours really

HyperNeutrino 07/30/2017.

Python 2, 155 bytes

lambda x,y,t='_'*10:'\n'.join(x[::1-2*y]for x in[' %s  '%t,'()'[y]+t+'@%']+['|'+('<>**)(%s><<>'%t)[y::2]+'||']*x+['|'+' '*10+'||']*(3-x)+["'"+'='*10+"''"])

Try it online!

Input consists of a length 2 tuple. The first element indicates the number of sardines. The second element indicates the direction; 0 for left, 1 for right.

-84 bytes using lambda magic thanks to notjagan and officialaimm

5 comments
1 notjagan 07/30/2017
174 bytes (sorta got ninja'd by @officialaimm there).
1 notjagan 07/30/2017
Got it down further to 161 bytes!
1 officialaimm 07/30/2017
@notjagan Lambda for 155
1 Pavel 07/30/2017
@officialaimm intrestingly enough, if supplied with a negative value, it extends the size of the tin, but doesn't put sardines in.
3 officialaimm 07/30/2017
@Phoenix Yes. It doesn't matter though, since OP has specified the range 0 to 10 . P.S.` -10` would print empty tin, becuase it signifies that there were 10 sardines, but you already ate them. :D

Neil 07/30/2017.

Charcoal, 49 bytes

๏ผกโŒˆโŸฆ๏ผฉฮธยณโŸงฮถ๏ผขฯ‡ยฒ_โ†โ†“(โ†“ฮถ'ร—=ฯ‡''โ†–๏ผฐโ†‘ฮถโ†โ†‘ฮถ@%๏ผฆ๏ผฎโ€œ#โˆจโ€น๏ผถ๏ผข“ยซjiโ€๏ผฆ๏ผฎโ€–๏ผด

Try it online! Link is to verbose version of code. First argument is number of sardines, second is direction (0 = left, 1 = right).

2 comments
WallyWest 07/30/2017
Great work, Neil. Thanks for supplying a compiler link!
2 Neil 07/30/2017
Don't thank me, thank @Dennis for creating TIO which generates all of the boilerplate for you.

dzaima 07/30/2017.

SOGL V0.12, 51 48 bytes

!gXโดโ€˜gjโฐ%!โตโ€˜bโŒก"ฮบNโ•ฅโ–ˆ*โ‰คโŒกโ•‘)โ€˜3b-"รทAZโดโ€˜โˆ™_"ฮงccฯƒยซโ€˜โฐe?ยฑโ†”

Try it Here!
Expects input as the 1st one being the count and the 2nd one - left or right represented by 1 or 0.

Explanation:

..โ€˜..โ€˜                          push 2 compressed strings - the 1st two lines of the box - "  __________ " and "%@__________)"
      bโŒก                        input times do
        "..โ€˜                      push a line with a sardine - "||><_____(*>|"
            3b-                 push 3-input
               "..โ€˜โˆ™            get an array of that many "||          |"
                    _           put all the arrays contents on the stack
                     "..โ€˜       push "''=========='" - the last line
                         โฐ      wrap all of that in an array
                          e?    if the 2nd input [is not 0]
                            ยฑโ†”    reverse the array horizontally

insert_name_here 08/11/2017.

Fishing, 1311 bytes

v+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC?CCCDCC[CCCCCCCCCCCCCCCCCCCCC?CCCCCCCCCCCCCCCCCCCC[CCC[CCCCC?CCCC?DDDDD[CCCCCCCCCCCCCCCCCCC?CCCCCCCCCCCCCCCCC[?CCCCCCCCCCCCCCCC_
  `3`n{n{In{I{`L`{`  __________ `}}!{{rD}}D{{NE`%@__________)`}}!{{E`(__________@%`}}D{{NDE}}}}={d}}!  d  D{{{{{`><_____(*>`}}!{{E`<*)_____><`}}D!{{{E`|`P}PE`||`ND
                                   [DDDDDD|                     [DDDDDDDDDDDDDDDDDDDD|   D     [C?CDDDDDDDDCCCCCCCCCCCCCCCCCCC[DDDDDDDDDDDDDDDDD|[CCCCCCCCCCCCCCCC_
                                                                                         D      }=d [^+Cv-|{{{{{`          `}}                    {{{E`||`P}PE`|`ND
                                                                                         D       [CCCCCCCCCCCCCCCCCCC?DDDDDDDDD+CCCC                              D
                                                                                         D        E`''=========='`{{{= }}}r{{{ [CCCC                              D
                                                                                         D                           [^CCCCCCCv|}}}N                              D
                                                                                         |DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD]

Takes input from stdin in the form:

5
R

Fishing isn't on Try It Online, but there's an interpreter for it in Ruby on the linked esolangs page.

This is the first program I've made in Fishing -- in fact, it's the first program I've made in any 2D language -- so it can probably be a lot shorter. Golfing tips are welcome (though I wouldn't be surprised if no one gave any, considering that even I don't know what the heck I just wrote).

Here's a GIF of the path the program takes for input 1R (sorry for low quality):

GIF

(This was created using an interpreter that I made; there are no publicly available programs that "visualize" Fishing, as far as I know)

2 comments
WallyWest 08/11/2017
The C and D syntax looks like it's contributing to the bloat... Is there any shorthand available to reduce that?
WallyWest 08/11/2017
Actually scratch that, looks like they're integral to the code... Interesting choice of language! :)

Mark 07/31/2017.

R, 334 bytes 311 bytes

s=function(n,d){
a="__________"
b="'=========='"
if(d == "L"){cat(paste(c(" ",a,"\n(",a,"@%\n",rep("|<*)_____><||\n",n),rep("|          ||\n",max(c(3-n,0))),b,"'\n"),collapse=""))} else {cat(paste(c("  ",a,"\n%@",a,")\n",rep("||><_____(*>|\n",n),rep("||          |\n",max(c(3-n,0))),"'",b,"\n"),collapse=""))}}

Function takes a numeric value for n and a string for the direction.

This is my first time posting, so I'll admit I'm not sure how to count bytes of code.

1 comments
1 Ian H. 08/01/2017
You can paste your code into TIO, where people can also test your code :) it also displays your byte count, which is 310 in this case.

HatsuPointerKun 08/01/2017.

C++, 307 296 292 bytes

#include<string>
auto z(int n,char c){std::string r=c-82?" __________\n(__________@%\n":"  __________\n%@__________)\n";int l=0;for(;l<n;++l)r+=c-82?"|<*)_____><||\n":"||><_____(*>|\n";for(;l<3;++l)r+=c-82?"|          ||\n":"||          |\n";r+=c-82?"'==========''":"''=========='";return r;}

Usage :

z(<number of sardines>,<'L' or 'R'>);

-11 bytes saved thanks to user ThePirateBay -4 bytes thanks to Zacharรฝ

2 comments
1 ThePirateBay 08/01/2017
Can you remove the parentheses in #define directive? I didn't test it but it seems that there's no need for them.
1 Zacharý 08/01/2017
Can c!=82 be c-82 in every case where you use it?

totallyhuman 07/30/2017.

Python 2, 287 bytes

n,d=input()
t,a,b,c,e,k=' __________   ','(__________@% ','|<*)_____><|| ','|          || ',"'=========='' ",'\n'
print[t+k+a+k+k.join([b]*n)+k+k.join([c]*(3-n))+k*(n<3)+e,t[::-1]+k+a[::-1].replace(*'()')+k+k.join([b[::-1].replace(*')(')]*n)+k+k.join([c[::-1]]*(3-n))+k*(n<3)+e[::-1]][d]

Try it online!

Input is a comma separated tuple of numbers of this format: 2, 1. The first number is the amount of fish and the second is is 0 for left and 1 for right.

This started out as an attempt to out-golf the other answer (I totally thought I could), but it sucks. :P If anybody can make head and tail of it and help golf it (I blame it on it being 12 am right now), I'd be glad.

1 comments
WallyWest 07/30/2017
Great attempt nonetheless!

Ian H. 07/31/2017.

C# (.NET Core), 289 bytes

(h,d)=>{var l=d=='L';string r=(l?" ":"  ")+"__________\n"+(l?"(":"%@")+"__________"+(l?"@%":")")+"\n";for(int i=0;i<(h>3?h:3);i++){r+=(l?"|":"||")+(i<h?(d=='L'?"<*)_____><":(d=='R'?"><_____(*>":"")):"          ")+(l?"||":"|")+'\n';}var b=(l?"'":"''")+"=========="+(l?"''":"'");return r+b;}

Try it online!

Takes an integer and a char (L, R) as parameters and outputs the resulting string.

Ugh. Had to deal with some annoying string constants, sadly you cant just do string * length in C#. And the method with new string(char, length) wouldn't have been worth the byte cost.


The algorithm works as follows:

  1. At the start we determine if the sardines face right or left, since we will then format our strings accordingly. We create a string for the top, with some conditional operators to switch between the L and R perspective.
  2. Then we create a loop that runs 3 times at minimum and the left input times at maximum. That way we can create empty spaces if we have less than 3 sardines in our box.
  3. Inside this loop we format a string, depending on the perspective and also, if h > i, we put a sardine inside of it. If i >= h, there will be an empty space where a sardine would normally be.
  4. At the end we create the bottom of the box, again formatted according to perspective.

Xcali 07/31/2017.

Perl 5, 167 + 1 (-n) = 168 bytes

($n,$d)=/(\d+)([LR])/ or die;say('R'eq$d?(reverse$_)=~y/()></)(<>/r:$_)for" __________  ","(__________@%",("|<*)_____><||")x$n,("|          ||")x(3-$n),"'==========''"

Try it online!


Jared Smith 08/01/2017.

JavaScript (ES6), 283 273 269 251 bytes

Saved 10 bytes thanks to @WallyWest

Saved 4 bytes removing extra parens

Saved 18 bytes thanks to @ThePirateBay

Suffers from lack of string reversal in the standard library. Defines a function that takes inputs n for number of fish and d for direction. Throws if d is not "L" or "R".

(n,d,_=c=>c.repeat(10),x=_(`_`),z=a=>a.reverse``.join``)=>
([p,q,g,r,s]=d>`L`?d>`R`?[]:[`)`,`(`,`>`,z,y=>z(y.split``)]:
[`(`,`)`,`<`,a=>a.join``,y=>y],` ${x}
`+r([p,x,s(`@%`)])+`
`+(r([`|`,g,`*`,q,`_____`,`><`,`||`])+`
`).repeat(n)+r([`'`,_(`=`),`''`]))

Try it online

5 comments
WallyWest 07/31/2017
Welcome to PPCG! We hope you like it here... Let's see what we can do to golf your score down... Great commencing effort!
Jared Smith 07/31/2017
@WallyWest thanks! Shaved off another 17 bytes by pulling out a function and changing the if...else if to nested ternaries with a destructuring assignment. I'm out of ideas though...
1 Jared Smith 07/31/2017
@WallyWest I use the _ function twice, once for the 10 underscores (which gets used twice), once for the 10 equal signs, so having it in a function saves me a byte. And unless I'm using template strings wrong, using them instead of concatenation is 3 bytes more.
1 Jared Smith 07/31/2017
@WallyWest thanks for the tip, that and removing some unneeded parens saved 14 bytes.
1 Jared Smith 08/01/2017
@Zacharý done. If I didn't enjoy making strangers on the internet happy, I wouldn't be on SE in the first place.

HighResolutionMusic.com - Download Hi-Res Songs

1 Martin Garrix

Yottabyte flac

Martin Garrix. 2018. Writer: Martin Garrix.
2 Dyro

Latency flac

Dyro. 2018. Writer: Martin Garrix;Dyro.
3 Martin Garrix

Access flac

Martin Garrix. 2018. Writer: Martin Garrix.
4 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
5 Sia

I'm Still Here flac

Sia. 2018. Writer: Sia.
6 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
7 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
8 Blinders

Breach (Walk Alone) flac

Blinders. 2018. Writer: Dewain Whitmore;Ilsey Juber;Blinders;Martin Garrix.
9 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
10 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
11 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
12 Kelsea Ballerini

This Feeling flac

Kelsea Ballerini. 2018. Writer: Andrew Taggart;Alex Pall;Emily Warren.
13 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
14 Avril Lavigne

Head Above Water flac

Avril Lavigne. 2018. Writer: Stephan Moccio;Travis Clark;Avril Lavigne.
15 Lady Gaga

Look What I Found flac

Lady Gaga. 2018. Writer: DJ White Shadow;Nick Monson;Mark Nilan Jr;Lady Gaga.
16 Billie Eilish

When The Party's Over flac

Billie Eilish. 2018. Writer: Billie Eilish;FINNEAS.
17 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
18 Rita Ora

Let You Love Me flac

Rita Ora. 2018. Writer: Rita Ora.
19 Diplo

Electricity flac

Diplo. 2018. Writer: Diplo;Mark Ronson;Picard Brothers;Wynter Gordon;Romy Madley Croft;Florence Welch.
20 Charli XCX

1999 flac

Charli XCX. 2018. Writer: Charli XCX;Troye Sivan;Leland;Oscar Holter;Noonie Bao.

Related questions

Hot questions

Language

Popular Tags