33
\$\begingroup\$

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.
\$\endgroup\$

13 Answers 13

39
\$\begingroup\$

><>, 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 ><>.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Writing this solution in Fish is inspired... \$\endgroup\$ Jul 30, 2017 at 6:00
  • \$\begingroup\$ How does the fish playground work? I can't get it to run. Where do I place the input? \$\endgroup\$
    – JAD
    Jul 31, 2017 at 8:51
  • \$\begingroup\$ @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.) \$\endgroup\$
    – Not a tree
    Jul 31, 2017 at 9:14
  • 1
    \$\begingroup\$ Awesome :D Must be nice during debugging too \$\endgroup\$
    – JAD
    Jul 31, 2017 at 9:19
15
\$\begingroup\$

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 "''=========='"
    {
  }
}
👵
\$\endgroup\$
3
  • 2
    \$\begingroup\$ Never come across Emojicode before but that is a mind f**k and a half... Crazy! Love it! \$\endgroup\$ Jul 30, 2017 at 10:22
  • \$\begingroup\$ ... why does this language even exist? I mean, I like it, but why? and how long did it take you to learn it? \$\endgroup\$ Jul 31, 2017 at 16:33
  • 1
    \$\begingroup\$ @TaylorScott 1) dunno, i didn't create it. 2) a few hours really \$\endgroup\$
    – betseg
    Jul 31, 2017 at 17:30
6
\$\begingroup\$

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

\$\endgroup\$
8
  • 1
    \$\begingroup\$ 174 bytes (sorta got ninja'd by @officialaimm there). \$\endgroup\$
    – notjagan
    Jul 30, 2017 at 4:00
  • 1
    \$\begingroup\$ Got it down further to 161 bytes! \$\endgroup\$
    – notjagan
    Jul 30, 2017 at 4:07
  • 1
    \$\begingroup\$ @notjagan Lambda for 155 \$\endgroup\$ Jul 30, 2017 at 4:10
  • 1
    \$\begingroup\$ @officialaimm intrestingly enough, if supplied with a negative value, it extends the size of the tin, but doesn't put sardines in. \$\endgroup\$
    – Pavel
    Jul 30, 2017 at 4:23
  • 3
    \$\begingroup\$ @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 \$\endgroup\$ Jul 30, 2017 at 4:49
6
\$\begingroup\$

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)

\$\endgroup\$
2
  • \$\begingroup\$ The C and D syntax looks like it's contributing to the bloat... Is there any shorthand available to reduce that? \$\endgroup\$ Aug 11, 2017 at 0:13
  • \$\begingroup\$ Actually scratch that, looks like they're integral to the code... Interesting choice of language! :) \$\endgroup\$ Aug 11, 2017 at 0:18
4
\$\begingroup\$

Charcoal, 49 bytes

A⌈⟦Iθ³⟧ζBχ²_←↓(↓ζ'×=χ''↖P↑ζ←↑ζ@%FN“#∨‹VB“«ji”FN‖T

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

\$\endgroup\$
2
  • \$\begingroup\$ Great work, Neil. Thanks for supplying a compiler link! \$\endgroup\$ Jul 30, 2017 at 20:22
  • 2
    \$\begingroup\$ Don't thank me, thank @Dennis for creating TIO which generates all of the boilerplate for you. \$\endgroup\$
    – Neil
    Jul 30, 2017 at 20:55
3
\$\begingroup\$

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
\$\endgroup\$
0
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Ian H.
    Aug 1, 2017 at 7:39
2
\$\begingroup\$

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ý

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can you remove the parentheses in #define directive? I didn't test it but it seems that there's no need for them. \$\endgroup\$
    – user72349
    Aug 1, 2017 at 12:51
  • 1
    \$\begingroup\$ Can c!=82 be c-82 in every case where you use it? \$\endgroup\$
    – Adalynn
    Aug 1, 2017 at 14:05
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Great attempt nonetheless! \$\endgroup\$ Jul 30, 2017 at 3:58
1
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

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!

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

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

\$\endgroup\$
14
  • \$\begingroup\$ Welcome to PPCG! We hope you like it here... Let's see what we can do to golf your score down... Great commencing effort! \$\endgroup\$ Jul 31, 2017 at 20:17
  • \$\begingroup\$ @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... \$\endgroup\$ Jul 31, 2017 at 20:44
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Jul 31, 2017 at 21:01
  • 1
    \$\begingroup\$ @WallyWest thanks for the tip, that and removing some unneeded parens saved 14 bytes. \$\endgroup\$ Jul 31, 2017 at 21:25
  • 1
    \$\begingroup\$ @Zacharý done. If I didn't enjoy making strangers on the internet happy, I wouldn't be on SE in the first place. \$\endgroup\$ Aug 1, 2017 at 14:52
1
\$\begingroup\$

Vyxal j, 91 bytes

ð\_₀*+ðd+⅛\(\_₀*`@%`++⅛⁰3WG(\|n⁰≥[ð₀*|`<*)_____><`]\|d++⅛)\'\=₀*\'d++⅛¾¹\R=[ƛṘ`<>()``><)(`Ŀ

Try it Online!

=== Top row ===
ð\_₀*+ðd+⅛
ð          # A space
 \_₀*      # Ten underscores
     +     # Concatenated
      ðd+  # Two more spaces
         ⅛ # Push to global array
=== Next row ===
\(\_₀*`@%`++⅛
\(            # The parenthesis
  \_₀*        # Ten underscores
      `@%`    # Literal
          ++⅛ # Concatenated and pushed to global array
=== The fishes ===
⁰3WG(\|n⁰≥[ð₀*|`<*)_____><`]\|d++⅛)
⁰3WG                                # Max(3,fish)
    (                             ) # times....
     \|                             # Push pipe
          [                ]        # If...
       n⁰≥                          # Iteration number is greater than or equal to input (missing fish)
           ð₀*                      # Ten spaces
              |                     # Else...
               `<*)_____><`         # A fish
                            \|d     # `||`
                               ++⅛  # Concatenate and push to global array
=== The final row === 
\'\=₀*\'d++⅛
\'           # Literal
  \=₀*       # Ten equalses
      \'d    # Two more apostrophes
             # Concatenated and pushed to global array
=== Flipping + Formatting === 
¾¹\R=[ƛṘ`<>()``><)(`Ŀ
¾                     # Push global array
     [                # If...
 ¹\R=                 # Input is R
      ƛ               # Foreach...
       Ṙ              # Reverse...
        `<>()``><)(`Ŀ # Flip brackets
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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