Amo las sardinas

33

Me encantan las sardinas, no puedo tener suficiente de ellas, y también lo hace mi computadora, la Omnilang 5000, que es independiente del lenguaje.

Para darle a mi computadora la alegría de experimentar las sardinas, he decidido alimentarlo con una serie de programas que son capaces de mostrar en la pantalla latas de sardinas en varias orientaciones y mostrar hasta diez sardinas.

En este desafío, usted será responsable de crear los programas basados ​​en estos parámetros:

La entrada

Un número (entre 0 y 10) y una letra de uno de los siguientes "LR" (que representan Izquierda o Derecha respectivamente) Por ejemplo: 3Lo 5R; cómo esto se ingresa al programa depende de usted.

Salida

Una lata abierta de sardinas con las sardinas mirando hacia la dirección indicada, con la llave (representada por el " %" carácter) y la tapa pelada (lata enrollada al final representada por el carácter " @") ubicada en la parte superior de la lata.

  • Todas las sardinas deben mirar en la dirección indicada por la entrada.
  • Todas las sardinas tendrán cuerpos de cinco caracteres entre la branquia (" )" o " (") y la cola " ><"
  • La llave y el rollo de la tapa pelada siempre estarán orientados en la dirección opuesta a las sardinas.
  • La lata debe tener un aspecto tridimensional como se muestra a continuación en los ejemplos.
  • La altura mínima de la lata es de 3 sardinas de altura. Entonces, si un número es menor que 3, se debe mostrar una lata de 3 sardinas en altura, con el número ingresado de sardinas. De lo contrario, la lata debe ser el número de sardinas alto indicado en la entrada. Entonces, la entrada de 0Ro 0Lmostrará una lata de sardina vacía.
  • Cualquier otra entrada que no se pueda validar no mostrará nada.

Por ejemplo, para " 3L"

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

Para " 7R"

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

Para " 2L"

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

Para " 0R"

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

" 0L"

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

La entrada no válida no devolverá nada ...

  • Este es el código de golf, por lo que el menor número de personajes ganará este desafío.
  • No hay lagunas como de costumbre.
WallyWest
fuente

Respuestas:

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<

¡Pruébelo en línea o mírelo en el área de juegos para peces ! Lee la "L" o la "R" de STDIN y asume que la cantidad de sardinas ya está en la pila (necesita un -vindicador para +3 bytes).

Porque, por supuesto, tuve que escribir esto en> <>.

No un arbol
fuente
3
Writing this solution in Fish is inspired...
WallyWest
How does the fish playground work? I can't get it to run. Where do I place the input?
JAD
@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
1
Awesome :D Must be nice during debugging too
JAD
15

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 "''=========='"
    {
  }
}
👵
betseg
fuente
2
Never come across Emojicode before but that is a mind f**k and a half... Crazy! Love it!
WallyWest
... 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
1
@TaylorScott 1) dunno, i didn't create it. 2) a few hours really
betseg
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
fuente
1
174 bytes (sorta got ninja'd by @officialaimm there).
notjagan
1
Got it down further to 161 bytes!
notjagan
1
@notjagan Lambda for 155
officialaimm
1
@officialaimm intrestingly enough, if supplied with a negative value, it extends the size of the tin, but doesn't put sardines in.
Pavel
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
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
fuente
The C and D syntax looks like it's contributing to the bloat... Is there any shorthand available to reduce that?
WallyWest
Actually scratch that, looks like they're integral to the code... Interesting choice of language! :)
WallyWest
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
fuente
Great work, Neil. Thanks for supplying a compiler link!
WallyWest
2
Don't thank me, thank @Dennis for creating TIO which generates all of the boilerplate for you.
Neil
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
fuente
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
fuente
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.
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
fuente
1
Can you remove the parentheses in #define directive? I didn't test it but it seems that there's no need for them.
1
Can c!=82 be c-82 in every case where you use it?
Zacharý
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
fuente
Great attempt nonetheless!
WallyWest
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.
fuente
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
fuente
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
fuente
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
@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
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
1
@WallyWest thanks for the tip, that and removing some unneeded parens saved 14 bytes.
Jared Smith
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