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: 3L
o 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
0R
o0L
mostrará 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.
-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.)Emojicode,
456448 bytesTakes 2 arguments: first one is lines, second one is direction (0 or 1).
Try it online!
"Readable" ungolfed version and pseudocode version:
fuente
Python 2, 155 bytes
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
fuente
0 to 10
. P.S.` -10` would print empty tin, becuase it signifies that there were10
sardines, but you already ate them. :DFishing, 1311 bytes
Takes input from
stdin
in the form: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):(This was created using an interpreter that I made; there are no publicly available programs that "visualize" Fishing, as far as I know)
fuente
Charcoal, 49 bytes
Try it online! Link is to verbose version of code. First argument is number of sardines, second is direction (0 = left, 1 = right).
fuente
SOGL V0.12,
5148 bytesTry it Here!
Expects input as the 1st one being the count and the 2nd one - left or right represented by 1 or 0.
Explanation:
fuente
R,
334 bytes311 bytesFunction 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.
fuente
C++,
307296292 bytesUsage :
-11 bytes saved thanks to user ThePirateBay -4 bytes thanks to Zacharý
fuente
#define
directive? I didn't test it but it seems that there's no need for them.c!=82
bec-82
in every case where you use it?Python 2, 287 bytes
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.
fuente
C# (.NET Core), 289 bytes
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 withnew string(char, length)
wouldn't have been worth the byte cost.The algorithm works as follows:
h > i
, we put a sardine inside of it. Ifi >= h
, there will be an empty space where a sardine would normally be.fuente
Perl 5, 167 + 1 (-n) = 168 bytes
Try it online!
fuente
JavaScript (ES6),
283273269251 bytesSaved 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 andd
for direction. Throws ifd
is not "L" or "R".Try it online
fuente
if...else if
to nested ternaries with a destructuring assignment. I'm out of ideas though..._
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.