12 байт Редактировать: В моей первой версии я забыл, что приведение к Vyxal (Square
#>&:*.@ // is a comment
~2-1??
~ // evaluates the input string
2-1? /* calculates 2^-1 = 1/2 (GolfScript does not support non-integers, but
due to a missed int cast in the interpreter, they can be generated with
the exponent function */
? // calculates x^1/2 = sqrt(x)
// the stack is output implicitly
#>&:*.@
#> // jumps over the arrow
& // takes an integer as input
:* // multiplies the top of the stack by itself
. // outputs as integer
@ // halts
~2-1?? // is not executed
#>&:*.@
~2-1??
and C++ produces
RTa
²
.
0.5
0
, Python 3.x produces 1/2
.
double f(int a){return Math.pow(a, 1/2==0?2:0.5);}
/
2
1/2or 2
0
||answer||
1/2
0.5
1/2or 2
0.5
) and implicitly outputs it.
1/2
(1/2or 2).__rpow__
is the square function, and /bin/bash prog.sh 4
/bin/sh prog.sh 4
/bin/sh
are both undefined, so the program just squares the implicitly read input and implicitly outputs it.
/bin/bash
/bin/sh
flag (+3)
sqrt
, C99 produces bc
sqrt(n)
version ought to take less code, but it insists on implicitly declaring the n^2
bc -l<<<"sqrt($1^(($(kill -l|wc -l)*3-3)/7+1))"
s, so this is the best I could manage.
p=^4 :
echo "sqrt($1)$p"|bc
<<<
||answer||
dash
/
sh
<<<
):
bash
:
):
p
bash
:
.
^4
(empty array) is a falsy value, while in JavaScript it is a truthy value (objects (except p
sh
is truthy!).
bash
( sh
p=^4 :
bc<<<"sqrt($1)$p"
).
**
, while JavaScript yields (function(x) x)(42) === 42
.
0//1or exec("function=lambda a:(lambda b:a);x=0")
y=2//2/2
f=(function(x)(x**y))//1 or(lambda x:x**y)
, to get the code of the right language.
:*n;
½
, which is stdin
#/*
n=int(input());print(n**2);"""*/
print(sqrt(input))\\"""
is parsed as the NULL-byte) and '
'
won't be parsed as the NULL-byte, comparing the literal string input a
?a^2'^.25
/ mirror up, then right
>in:o#p;
i read line of input
n cast to number
:o# square root
p print
; terminate
.
/&:*.@
/ divide top two (no-op)
& read decimal input
: duplicate
* square
. output
@ terminate
s the code required.
/&:*.@
>in:o#p;
(equivalent to y
y
, which displays the squared number in an y
.
1
-
(y)=y
f
y
Y
a
RTa
in Forth. Python can have a named function x = f(y)
y
in front of the lambda.
y
) would be written like this:
f(y)
||answer||
YRTa
f(y)=yy
mq
||answer||
/
rd
).
];
ECHO"$argv[1]"**2;#
||answer||
#
v
in the mission folder, then call it with $argv[1]
.
, 10
$argv[1]
would remove precision in the Vyxal code. Added +2 bytes to fix it.
-r
ECHO"$argv[1]"**2;#];rdmq
Попробуйте онлайн в Vyxal!
Грок (Квадрат):
I√ # Push '√' to the register
`# # Skip ‘#’ command
: # Take input from STDIN
Yp # Duplicate
*z # Multiply and output as int
q # Quit
`_ # Never gets executed
Попробуйте онлайн в Гроке!