I Love Sardines

33

2

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.

WallyWest

Posted 2017-07-30T02:26:16.637

Reputation: 6 949

Answers

39

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

Not a tree

Posted 2017-07-30T02:26:16.637

Reputation: 3 106

3Writing this solution in Fish is inspired... – WallyWest – 2017-07-30T06:00:07.750

How does the fish playground work? I can't get it to run. Where do I place the input? – JAD – 2017-07-31T08:51:07.237

@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.) – Not a tree – 2017-07-31T09:14:30.690

1Awesome :D Must be nice during debugging too – JAD – 2017-07-31T09:19:55.793

15

Emojicode, 456 448 bytes

da0da __________❌n(__________@%  __________❌n%@__________)i⏩0a|<*)_____><||||><_____(*>|▶️4i⏩0➖3a|          ||||          |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 "''=========='"
    {
  }
}

betseg

Posted 2017-07-30T02:26:16.637

Reputation: 8 493

2Never come across Emojicode before but that is a mind f**k and a half... Crazy! Love it! – WallyWest – 2017-07-30T10:22:01.833

... why does this language even exist? I mean, I like it, but why? and how long did it take you to learn it? – Taylor Scott – 2017-07-31T16:33:48.377

1@TaylorScott 1) dunno, i didn't create it. 2) a few hours really – betseg – 2017-07-31T17:30:48.687

6

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

HyperNeutrino

Posted 2017-07-30T02:26:16.637

Reputation: 26 575

Great stuff, love the result and the testing site... – WallyWest – 2017-07-30T03:01:18.550

1174 bytes (sorta got ninja'd by @officialaimm there). – notjagan – 2017-07-30T04:00:58.107

1

Got it down further to 161 bytes!

– notjagan – 2017-07-30T04:07:44.850

1

@notjagan Lambda for 155

– officialaimm – 2017-07-30T04:10:49.203

1@officialaimm intrestingly enough, if supplied with a negative value, it extends the size of the tin, but doesn't put sardines in. – Pavel – 2017-07-30T04:23:28.060

3@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 – officialaimm – 2017-07-30T04:49:35.403

@officialaimm Post the Lambda for 155? – WallyWest – 2017-07-30T11:17:44.760

@notjagan Thanks for the golfs :) – HyperNeutrino – 2017-07-30T16:10:45.407

5

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)

insert_name_here

Posted 2017-07-30T02:26:16.637

Reputation: 816

The C and D syntax looks like it's contributing to the bloat... Is there any shorthand available to reduce that? – WallyWest – 2017-08-11T00:13:06.437

Actually scratch that, looks like they're integral to the code... Interesting choice of language! :) – WallyWest – 2017-08-11T00:18:39.300

4

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

Neil

Posted 2017-07-30T02:26:16.637

Reputation: 95 035

Great work, Neil. Thanks for supplying a compiler link! – WallyWest – 2017-07-30T20:22:18.183

2Don't thank me, thank @Dennis for creating TIO which generates all of the boilerplate for you. – Neil – 2017-07-30T20:55:18.243

3

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

dzaima

Posted 2017-07-30T02:26:16.637

Reputation: 19 048

2

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ý

HatsuPointerKun

Posted 2017-07-30T02:26:16.637

Reputation: 1 891

1Can you remove the parentheses in #define directive? I didn't test it but it seems that there's no need for them. – None – 2017-08-01T12:51:13.087

1Can c!=82 be c-82 in every case where you use it? – Zacharý – 2017-08-01T14:05:23.710

2

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.

Mark

Posted 2017-07-30T02:26:16.637

Reputation: 411

1

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.

– Ian H. – 2017-08-01T07:39:31.087

1

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.

totallyhuman

Posted 2017-07-30T02:26:16.637

Reputation: 15 378

Great attempt nonetheless! – WallyWest – 2017-07-30T03:58:46.477

1

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.

Ian H.

Posted 2017-07-30T02:26:16.637

Reputation: 2 431

1

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!

Xcali

Posted 2017-07-30T02:26:16.637

Reputation: 7 671

1

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

Jared Smith

Posted 2017-07-30T02:26:16.637

Reputation: 111

Welcome to PPCG! We hope you like it here... Let's see what we can do to golf your score down... Great commencing effort! – WallyWest – 2017-07-31T20:17:30.197

@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... – Jared Smith – 2017-07-31T20:44:59.637

If you're using ES6, change all your instances of ('') to `` – WallyWest – 2017-07-31T20:47:25.613

1

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

– Jared Smith – 2017-07-31T21:01:48.173

I noticed that after I posted, and subsequently delayed that previous comment... – WallyWest – 2017-07-31T21:03:05.263

And the back ticks, for example: using split`` instead of split('') – WallyWest – 2017-07-31T21:04:01.423

1@WallyWest thanks for the tip, that and removing some unneeded parens saved 14 bytes. – Jared Smith – 2017-07-31T21:25:55.777

Strings are technically arrays of one character strings. Would changing s("@%") to r("%@") and eliminating the s() declaration help? – WallyWest – 2017-07-31T22:43:12.063

You can save 18 bytes by rearranging your identifiers. See the result here.

– None – 2017-07-31T23:34:55.377

@WallyWest unfortunately strings and arrays are not sufficiently interchangeable in this case in JavaScript as they don't have the same method. If strings had a built-in reverse method I could probably do that but defining one on String.prototype is longer than the function I wrote by a lot. – Jared Smith – 2017-08-01T11:14:11.047

Are these possible? _('_') => _\``, s(\@%`)=>s`@%``, and `(`=`)=>_`=``? (Talk about overkill on the backticks, wow) – Zacharý – 2017-08-01T14:09:56.590

@Zacharý no if you do it with custom functions like f=s=>s.repeat(10) and call it f\_`` then for some reason it wraps the parameter in an array so I'd have to add an array access or convert it to a string. – Jared Smith – 2017-08-01T14:37:37.267

Well, can you change _('_') to _(\_`)`? (that's really bugging me, one pair of strings in single quotes) – Zacharý – 2017-08-01T14:42:49.570

1@Zacharý done. If I didn't enjoy making strangers on the internet happy, I wouldn't be on SE in the first place. – Jared Smith – 2017-08-01T14:52:23.820