Cycle my input please
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Input
A string s
of printable ASCII characters, newlines, and spaces (0x20 ( )
to 0x7E (~)
), and a non-negative integer n
.
Challenge
To write a program that outputs either another program, or s
depending on n
. If n = 1
, Then your code should output code which outputs s
. If n = 2
, Your code should output code which outputs code which outputs s
and so on.
All outputted code should be in the same language as the language of the original submission.
Test Cases
Format: s, n -> output
Assuming your submission is written in JavaScript:
No cycles, 0 -> No cycles
Hello, 1 -> console.log("Hello");
Cycle!, 3 -> console.log("console.log("console.log(\"Cycle!\")")");
:), 3 -> console.log("console.log('console.log(`:)`)')");
Scoring
This is code-golf, so aim for shortest code in bytes.
Additional Rules
- I/O format is flexible
- Default rules and standard loopholes apply.
- The output of your submission must be valid.
- You can use any language, even if it was created after this challenge, as long as it wasn't created for the purpose of this challenge
- This isn't a polyglot challenge. A JavaScript submission shouldn't output Ruby code.
- Input is guaranteed to be valid as defined in the
Input
section
Validation
Here's a quick tip to test your answers:
For n=0
, output=s
For n=1
, eval(output)=s
For n=2
, eval(eval(output))=s
Where n
and s
are inputs
code-golf string
add a comment |Â
up vote
1
down vote
favorite
Input
A string s
of printable ASCII characters, newlines, and spaces (0x20 ( )
to 0x7E (~)
), and a non-negative integer n
.
Challenge
To write a program that outputs either another program, or s
depending on n
. If n = 1
, Then your code should output code which outputs s
. If n = 2
, Your code should output code which outputs code which outputs s
and so on.
All outputted code should be in the same language as the language of the original submission.
Test Cases
Format: s, n -> output
Assuming your submission is written in JavaScript:
No cycles, 0 -> No cycles
Hello, 1 -> console.log("Hello");
Cycle!, 3 -> console.log("console.log("console.log(\"Cycle!\")")");
:), 3 -> console.log("console.log('console.log(`:)`)')");
Scoring
This is code-golf, so aim for shortest code in bytes.
Additional Rules
- I/O format is flexible
- Default rules and standard loopholes apply.
- The output of your submission must be valid.
- You can use any language, even if it was created after this challenge, as long as it wasn't created for the purpose of this challenge
- This isn't a polyglot challenge. A JavaScript submission shouldn't output Ruby code.
- Input is guaranteed to be valid as defined in the
Input
section
Validation
Here's a quick tip to test your answers:
For n=0
, output=s
For n=1
, eval(output)=s
For n=2
, eval(eval(output))=s
Where n
and s
are inputs
code-golf string
Are functions that output programs or functions allowed?
â nwellnhof
2 hours ago
3
related duplicate?
â Emigna
2 hours ago
@nwellnhof According to the default rules, yes.
â FireCubez
2 hours ago
@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
â FireCubez
2 hours ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Input
A string s
of printable ASCII characters, newlines, and spaces (0x20 ( )
to 0x7E (~)
), and a non-negative integer n
.
Challenge
To write a program that outputs either another program, or s
depending on n
. If n = 1
, Then your code should output code which outputs s
. If n = 2
, Your code should output code which outputs code which outputs s
and so on.
All outputted code should be in the same language as the language of the original submission.
Test Cases
Format: s, n -> output
Assuming your submission is written in JavaScript:
No cycles, 0 -> No cycles
Hello, 1 -> console.log("Hello");
Cycle!, 3 -> console.log("console.log("console.log(\"Cycle!\")")");
:), 3 -> console.log("console.log('console.log(`:)`)')");
Scoring
This is code-golf, so aim for shortest code in bytes.
Additional Rules
- I/O format is flexible
- Default rules and standard loopholes apply.
- The output of your submission must be valid.
- You can use any language, even if it was created after this challenge, as long as it wasn't created for the purpose of this challenge
- This isn't a polyglot challenge. A JavaScript submission shouldn't output Ruby code.
- Input is guaranteed to be valid as defined in the
Input
section
Validation
Here's a quick tip to test your answers:
For n=0
, output=s
For n=1
, eval(output)=s
For n=2
, eval(eval(output))=s
Where n
and s
are inputs
code-golf string
Input
A string s
of printable ASCII characters, newlines, and spaces (0x20 ( )
to 0x7E (~)
), and a non-negative integer n
.
Challenge
To write a program that outputs either another program, or s
depending on n
. If n = 1
, Then your code should output code which outputs s
. If n = 2
, Your code should output code which outputs code which outputs s
and so on.
All outputted code should be in the same language as the language of the original submission.
Test Cases
Format: s, n -> output
Assuming your submission is written in JavaScript:
No cycles, 0 -> No cycles
Hello, 1 -> console.log("Hello");
Cycle!, 3 -> console.log("console.log("console.log(\"Cycle!\")")");
:), 3 -> console.log("console.log('console.log(`:)`)')");
Scoring
This is code-golf, so aim for shortest code in bytes.
Additional Rules
- I/O format is flexible
- Default rules and standard loopholes apply.
- The output of your submission must be valid.
- You can use any language, even if it was created after this challenge, as long as it wasn't created for the purpose of this challenge
- This isn't a polyglot challenge. A JavaScript submission shouldn't output Ruby code.
- Input is guaranteed to be valid as defined in the
Input
section
Validation
Here's a quick tip to test your answers:
For n=0
, output=s
For n=1
, eval(output)=s
For n=2
, eval(eval(output))=s
Where n
and s
are inputs
code-golf string
code-golf string
edited 1 hour ago
asked 3 hours ago
FireCubez
1267
1267
Are functions that output programs or functions allowed?
â nwellnhof
2 hours ago
3
related duplicate?
â Emigna
2 hours ago
@nwellnhof According to the default rules, yes.
â FireCubez
2 hours ago
@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
â FireCubez
2 hours ago
add a comment |Â
Are functions that output programs or functions allowed?
â nwellnhof
2 hours ago
3
related duplicate?
â Emigna
2 hours ago
@nwellnhof According to the default rules, yes.
â FireCubez
2 hours ago
@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
â FireCubez
2 hours ago
Are functions that output programs or functions allowed?
â nwellnhof
2 hours ago
Are functions that output programs or functions allowed?
â nwellnhof
2 hours ago
3
3
related duplicate?
â Emigna
2 hours ago
related duplicate?
â Emigna
2 hours ago
@nwellnhof According to the default rules, yes.
â FireCubez
2 hours ago
@nwellnhof According to the default rules, yes.
â FireCubez
2 hours ago
@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
â FireCubez
2 hours ago
@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
â FireCubez
2 hours ago
add a comment |Â
9 Answers
9
active
oldest
votes
up vote
3
down vote
R, 43 bytes
f=function(s,n)"if"(n,function()f(s,n-1),s)
Try it online!
Returns a zero-argument function that recursively calls f
with n
set to n-1
. n
successive function applications returns s
.
add a comment |Â
up vote
1
down vote
PHP, 69 bytes
function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;
Try it online!
From the documentation about var_export
:
var_export â Outputs or returns a parsable string representation of a variable
This function calls var_export
prepends echo
and appends ;
$n
times.
Could you provide an explanation?
â FireCubez
2 hours ago
1) There´s no need for a space betweenreturn
and$s
. 2) recursive function, 67 bytesfunction f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s;
3) full program, 63 bytes:for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s;
(run with-r
)
â Titus
1 hour ago
I'd have to include-r
in the byte count, don't I?
â oktupol
1 hour ago
add a comment |Â
up vote
1
down vote
V, 3 bytes
ÃÂII
Try it online!
Takes string as input, prepends as many I
as stated in the first argument.
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 43 bytes
Outputs a program that outputs a program that outp.... until b=1
f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''
Try it online!
This does not match the test cases, the output forf("hello", 2)
should beconsole.log("console.log("hello")")
orconsole.log("console.log('hello')")
â FireCubez
2 hours ago
Yes it is... it just outputsconsole.log("hello")
â FireCubez
2 hours ago
Does not work forn=0
â FireCubez
2 hours ago
Nevermind, it's just 1-indexed
â FireCubez
2 hours ago
add a comment |Â
up vote
0
down vote
Haskell, 42 bytes
s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))
Try it online!
I think...0<1=show$s#(n-1)
is enough, because we treat values in Haskell as functions.
â nimi
1 hour ago
add a comment |Â
up vote
0
down vote
Perl 6, 25 bytes
'Që'x$^n~$^s~'û'x$n
Try it online!
Function returning function code. Uses Që û
to quote unescaped ASCII strings.
add a comment |Â
up vote
0
down vote
PHP, 12+1 bytes, not competing
plain text is a valid PHP program, but, if N
is not 0
, this fails for text containing <?
with short tags enabled and for text containing <?php
or <?=
in any case:
<?=$argv[1];
call with php -R '<code>' '<string>' <n>
;
call the output with php -R '<code>'
add a comment |Â
up vote
0
down vote
Google Sheets, 96 bytes
=Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))
Inputs are in cells A1
(s
) and B1
(n
).
(Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)
The formula concatenates 3 pieces into a single string. The first piece is the most complicated.
If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)
If If
statement drops the prefix if n=0
so you end up with No cycles
instead of ="No cycles
. The ArrayFormula
creates an array of equal signs followed by some number quotes. That number is 2^(x-1)
where x
counts up from 1 to n
thanks to the Row(Offset(~))
combination.
The next piece (A1
) adds in s
and the final piece (Rept("""",2^B1-1)
) adds in 2^n-1
quotes at the end.
add a comment |Â
up vote
0
down vote
Jelly, 2 bytes
Ṿá
Try it online!
Explanation? How does this wor
â FireCubez
1 hour ago
@FireCubez It simply executes the value â string representation functionn
times.
â Erik the Outgolfer
53 mins ago
And does executing the string representation of a value print the value?
â FireCubez
52 mins ago
@FireCubez The eval function (V
) simply evaluates the code within a string. It doesn't implicitly print anything.
â Erik the Outgolfer
50 mins ago
add a comment |Â
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
R, 43 bytes
f=function(s,n)"if"(n,function()f(s,n-1),s)
Try it online!
Returns a zero-argument function that recursively calls f
with n
set to n-1
. n
successive function applications returns s
.
add a comment |Â
up vote
3
down vote
R, 43 bytes
f=function(s,n)"if"(n,function()f(s,n-1),s)
Try it online!
Returns a zero-argument function that recursively calls f
with n
set to n-1
. n
successive function applications returns s
.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
R, 43 bytes
f=function(s,n)"if"(n,function()f(s,n-1),s)
Try it online!
Returns a zero-argument function that recursively calls f
with n
set to n-1
. n
successive function applications returns s
.
R, 43 bytes
f=function(s,n)"if"(n,function()f(s,n-1),s)
Try it online!
Returns a zero-argument function that recursively calls f
with n
set to n-1
. n
successive function applications returns s
.
answered 2 hours ago
Giuseppe
15.4k31051
15.4k31051
add a comment |Â
add a comment |Â
up vote
1
down vote
PHP, 69 bytes
function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;
Try it online!
From the documentation about var_export
:
var_export â Outputs or returns a parsable string representation of a variable
This function calls var_export
prepends echo
and appends ;
$n
times.
Could you provide an explanation?
â FireCubez
2 hours ago
1) There´s no need for a space betweenreturn
and$s
. 2) recursive function, 67 bytesfunction f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s;
3) full program, 63 bytes:for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s;
(run with-r
)
â Titus
1 hour ago
I'd have to include-r
in the byte count, don't I?
â oktupol
1 hour ago
add a comment |Â
up vote
1
down vote
PHP, 69 bytes
function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;
Try it online!
From the documentation about var_export
:
var_export â Outputs or returns a parsable string representation of a variable
This function calls var_export
prepends echo
and appends ;
$n
times.
Could you provide an explanation?
â FireCubez
2 hours ago
1) There´s no need for a space betweenreturn
and$s
. 2) recursive function, 67 bytesfunction f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s;
3) full program, 63 bytes:for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s;
(run with-r
)
â Titus
1 hour ago
I'd have to include-r
in the byte count, don't I?
â oktupol
1 hour ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
PHP, 69 bytes
function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;
Try it online!
From the documentation about var_export
:
var_export â Outputs or returns a parsable string representation of a variable
This function calls var_export
prepends echo
and appends ;
$n
times.
PHP, 69 bytes
function($s,$n)while($n--)$s='echo'.var_export($s,1).';';return $s;
Try it online!
From the documentation about var_export
:
var_export â Outputs or returns a parsable string representation of a variable
This function calls var_export
prepends echo
and appends ;
$n
times.
edited 2 hours ago
answered 2 hours ago
oktupol
4618
4618
Could you provide an explanation?
â FireCubez
2 hours ago
1) There´s no need for a space betweenreturn
and$s
. 2) recursive function, 67 bytesfunction f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s;
3) full program, 63 bytes:for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s;
(run with-r
)
â Titus
1 hour ago
I'd have to include-r
in the byte count, don't I?
â oktupol
1 hour ago
add a comment |Â
Could you provide an explanation?
â FireCubez
2 hours ago
1) There´s no need for a space betweenreturn
and$s
. 2) recursive function, 67 bytesfunction f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s;
3) full program, 63 bytes:for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s;
(run with-r
)
â Titus
1 hour ago
I'd have to include-r
in the byte count, don't I?
â oktupol
1 hour ago
Could you provide an explanation?
â FireCubez
2 hours ago
Could you provide an explanation?
â FireCubez
2 hours ago
1) There´s no need for a space between
return
and $s
. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s;
3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s;
(run with -r
)â Titus
1 hour ago
1) There´s no need for a space between
return
and $s
. 2) recursive function, 67 bytes function f($s,$n)return$n?f('echo'.var_export($s,1).';',$n-1):$s;
3) full program, 63 bytes: for([,$s,$n]=$argv;$n--;)$s="echo".var_export($s,1).";";echo$s;
(run with -r
)â Titus
1 hour ago
I'd have to include
-r
in the byte count, don't I?â oktupol
1 hour ago
I'd have to include
-r
in the byte count, don't I?â oktupol
1 hour ago
add a comment |Â
up vote
1
down vote
V, 3 bytes
ÃÂII
Try it online!
Takes string as input, prepends as many I
as stated in the first argument.
add a comment |Â
up vote
1
down vote
V, 3 bytes
ÃÂII
Try it online!
Takes string as input, prepends as many I
as stated in the first argument.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
V, 3 bytes
ÃÂII
Try it online!
Takes string as input, prepends as many I
as stated in the first argument.
V, 3 bytes
ÃÂII
Try it online!
Takes string as input, prepends as many I
as stated in the first argument.
answered 2 hours ago
oktupol
4618
4618
add a comment |Â
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 43 bytes
Outputs a program that outputs a program that outp.... until b=1
f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''
Try it online!
This does not match the test cases, the output forf("hello", 2)
should beconsole.log("console.log("hello")")
orconsole.log("console.log('hello')")
â FireCubez
2 hours ago
Yes it is... it just outputsconsole.log("hello")
â FireCubez
2 hours ago
Does not work forn=0
â FireCubez
2 hours ago
Nevermind, it's just 1-indexed
â FireCubez
2 hours ago
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 43 bytes
Outputs a program that outputs a program that outp.... until b=1
f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''
Try it online!
This does not match the test cases, the output forf("hello", 2)
should beconsole.log("console.log("hello")")
orconsole.log("console.log('hello')")
â FireCubez
2 hours ago
Yes it is... it just outputsconsole.log("hello")
â FireCubez
2 hours ago
Does not work forn=0
â FireCubez
2 hours ago
Nevermind, it's just 1-indexed
â FireCubez
2 hours ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
JavaScript (Node.js), 43 bytes
Outputs a program that outputs a program that outp.... until b=1
f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''
Try it online!
JavaScript (Node.js), 43 bytes
Outputs a program that outputs a program that outp.... until b=1
f=(a,b)=>b?--b?`(f=$f)('$a',$b)`:a:''
Try it online!
edited 2 hours ago
answered 2 hours ago
Luis felipe De jesus Munoz
3,24611049
3,24611049
This does not match the test cases, the output forf("hello", 2)
should beconsole.log("console.log("hello")")
orconsole.log("console.log('hello')")
â FireCubez
2 hours ago
Yes it is... it just outputsconsole.log("hello")
â FireCubez
2 hours ago
Does not work forn=0
â FireCubez
2 hours ago
Nevermind, it's just 1-indexed
â FireCubez
2 hours ago
add a comment |Â
This does not match the test cases, the output forf("hello", 2)
should beconsole.log("console.log("hello")")
orconsole.log("console.log('hello')")
â FireCubez
2 hours ago
Yes it is... it just outputsconsole.log("hello")
â FireCubez
2 hours ago
Does not work forn=0
â FireCubez
2 hours ago
Nevermind, it's just 1-indexed
â FireCubez
2 hours ago
This does not match the test cases, the output for
f("hello", 2)
should be console.log("console.log("hello")")
or console.log("console.log('hello')")
â FireCubez
2 hours ago
This does not match the test cases, the output for
f("hello", 2)
should be console.log("console.log("hello")")
or console.log("console.log('hello')")
â FireCubez
2 hours ago
Yes it is... it just outputs
console.log("hello")
â FireCubez
2 hours ago
Yes it is... it just outputs
console.log("hello")
â FireCubez
2 hours ago
Does not work for
n=0
â FireCubez
2 hours ago
Does not work for
n=0
â FireCubez
2 hours ago
Nevermind, it's just 1-indexed
â FireCubez
2 hours ago
Nevermind, it's just 1-indexed
â FireCubez
2 hours ago
add a comment |Â
up vote
0
down vote
Haskell, 42 bytes
s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))
Try it online!
I think...0<1=show$s#(n-1)
is enough, because we treat values in Haskell as functions.
â nimi
1 hour ago
add a comment |Â
up vote
0
down vote
Haskell, 42 bytes
s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))
Try it online!
I think...0<1=show$s#(n-1)
is enough, because we treat values in Haskell as functions.
â nimi
1 hour ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Haskell, 42 bytes
s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))
Try it online!
Haskell, 42 bytes
s#n|n<1=s|0<1="main=putStr"++show(s#(n-1))
Try it online!
answered 2 hours ago
Max Yekhlakov
3016
3016
I think...0<1=show$s#(n-1)
is enough, because we treat values in Haskell as functions.
â nimi
1 hour ago
add a comment |Â
I think...0<1=show$s#(n-1)
is enough, because we treat values in Haskell as functions.
â nimi
1 hour ago
I think
...0<1=show$s#(n-1)
is enough, because we treat values in Haskell as functions.â nimi
1 hour ago
I think
...0<1=show$s#(n-1)
is enough, because we treat values in Haskell as functions.â nimi
1 hour ago
add a comment |Â
up vote
0
down vote
Perl 6, 25 bytes
'Që'x$^n~$^s~'û'x$n
Try it online!
Function returning function code. Uses Që û
to quote unescaped ASCII strings.
add a comment |Â
up vote
0
down vote
Perl 6, 25 bytes
'Që'x$^n~$^s~'û'x$n
Try it online!
Function returning function code. Uses Që û
to quote unescaped ASCII strings.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Perl 6, 25 bytes
'Që'x$^n~$^s~'û'x$n
Try it online!
Function returning function code. Uses Që û
to quote unescaped ASCII strings.
Perl 6, 25 bytes
'Që'x$^n~$^s~'û'x$n
Try it online!
Function returning function code. Uses Që û
to quote unescaped ASCII strings.
edited 2 hours ago
answered 2 hours ago
nwellnhof
4,307817
4,307817
add a comment |Â
add a comment |Â
up vote
0
down vote
PHP, 12+1 bytes, not competing
plain text is a valid PHP program, but, if N
is not 0
, this fails for text containing <?
with short tags enabled and for text containing <?php
or <?=
in any case:
<?=$argv[1];
call with php -R '<code>' '<string>' <n>
;
call the output with php -R '<code>'
add a comment |Â
up vote
0
down vote
PHP, 12+1 bytes, not competing
plain text is a valid PHP program, but, if N
is not 0
, this fails for text containing <?
with short tags enabled and for text containing <?php
or <?=
in any case:
<?=$argv[1];
call with php -R '<code>' '<string>' <n>
;
call the output with php -R '<code>'
add a comment |Â
up vote
0
down vote
up vote
0
down vote
PHP, 12+1 bytes, not competing
plain text is a valid PHP program, but, if N
is not 0
, this fails for text containing <?
with short tags enabled and for text containing <?php
or <?=
in any case:
<?=$argv[1];
call with php -R '<code>' '<string>' <n>
;
call the output with php -R '<code>'
PHP, 12+1 bytes, not competing
plain text is a valid PHP program, but, if N
is not 0
, this fails for text containing <?
with short tags enabled and for text containing <?php
or <?=
in any case:
<?=$argv[1];
call with php -R '<code>' '<string>' <n>
;
call the output with php -R '<code>'
answered 1 hour ago
Titus
12.6k11236
12.6k11236
add a comment |Â
add a comment |Â
up vote
0
down vote
Google Sheets, 96 bytes
=Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))
Inputs are in cells A1
(s
) and B1
(n
).
(Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)
The formula concatenates 3 pieces into a single string. The first piece is the most complicated.
If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)
If If
statement drops the prefix if n=0
so you end up with No cycles
instead of ="No cycles
. The ArrayFormula
creates an array of equal signs followed by some number quotes. That number is 2^(x-1)
where x
counts up from 1 to n
thanks to the Row(Offset(~))
combination.
The next piece (A1
) adds in s
and the final piece (Rept("""",2^B1-1)
) adds in 2^n-1
quotes at the end.
add a comment |Â
up vote
0
down vote
Google Sheets, 96 bytes
=Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))
Inputs are in cells A1
(s
) and B1
(n
).
(Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)
The formula concatenates 3 pieces into a single string. The first piece is the most complicated.
If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)
If If
statement drops the prefix if n=0
so you end up with No cycles
instead of ="No cycles
. The ArrayFormula
creates an array of equal signs followed by some number quotes. That number is 2^(x-1)
where x
counts up from 1 to n
thanks to the Row(Offset(~))
combination.
The next piece (A1
) adds in s
and the final piece (Rept("""",2^B1-1)
) adds in 2^n-1
quotes at the end.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Google Sheets, 96 bytes
=Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))
Inputs are in cells A1
(s
) and B1
(n
).
(Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)
The formula concatenates 3 pieces into a single string. The first piece is the most complicated.
If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)
If If
statement drops the prefix if n=0
so you end up with No cycles
instead of ="No cycles
. The ArrayFormula
creates an array of equal signs followed by some number quotes. That number is 2^(x-1)
where x
counts up from 1 to n
thanks to the Row(Offset(~))
combination.
The next piece (A1
) adds in s
and the final piece (Rept("""",2^B1-1)
) adds in 2^n-1
quotes at the end.
Google Sheets, 96 bytes
=Join("",If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),),A1,Rept("""",2^B1-1))
Inputs are in cells A1
(s
) and B1
(n
).
(Columns D, E, and F show the result if you copy the output from the column to its left and input it as a formula.)
The formula concatenates 3 pieces into a single string. The first piece is the most complicated.
If(B1,ArrayFormula("="&Rept("""",2^(Row(Offset(A1,0,0,B1))-1))),)
If If
statement drops the prefix if n=0
so you end up with No cycles
instead of ="No cycles
. The ArrayFormula
creates an array of equal signs followed by some number quotes. That number is 2^(x-1)
where x
counts up from 1 to n
thanks to the Row(Offset(~))
combination.
The next piece (A1
) adds in s
and the final piece (Rept("""",2^B1-1)
) adds in 2^n-1
quotes at the end.
answered 1 hour ago
Engineer Toast
4,9641136
4,9641136
add a comment |Â
add a comment |Â
up vote
0
down vote
Jelly, 2 bytes
Ṿá
Try it online!
Explanation? How does this wor
â FireCubez
1 hour ago
@FireCubez It simply executes the value â string representation functionn
times.
â Erik the Outgolfer
53 mins ago
And does executing the string representation of a value print the value?
â FireCubez
52 mins ago
@FireCubez The eval function (V
) simply evaluates the code within a string. It doesn't implicitly print anything.
â Erik the Outgolfer
50 mins ago
add a comment |Â
up vote
0
down vote
Jelly, 2 bytes
Ṿá
Try it online!
Explanation? How does this wor
â FireCubez
1 hour ago
@FireCubez It simply executes the value â string representation functionn
times.
â Erik the Outgolfer
53 mins ago
And does executing the string representation of a value print the value?
â FireCubez
52 mins ago
@FireCubez The eval function (V
) simply evaluates the code within a string. It doesn't implicitly print anything.
â Erik the Outgolfer
50 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Jelly, 2 bytes
Ṿá
Try it online!
Jelly, 2 bytes
Ṿá
Try it online!
answered 1 hour ago
Erik the Outgolfer
29.8k42899
29.8k42899
Explanation? How does this wor
â FireCubez
1 hour ago
@FireCubez It simply executes the value â string representation functionn
times.
â Erik the Outgolfer
53 mins ago
And does executing the string representation of a value print the value?
â FireCubez
52 mins ago
@FireCubez The eval function (V
) simply evaluates the code within a string. It doesn't implicitly print anything.
â Erik the Outgolfer
50 mins ago
add a comment |Â
Explanation? How does this wor
â FireCubez
1 hour ago
@FireCubez It simply executes the value â string representation functionn
times.
â Erik the Outgolfer
53 mins ago
And does executing the string representation of a value print the value?
â FireCubez
52 mins ago
@FireCubez The eval function (V
) simply evaluates the code within a string. It doesn't implicitly print anything.
â Erik the Outgolfer
50 mins ago
Explanation? How does this wor
â FireCubez
1 hour ago
Explanation? How does this wor
â FireCubez
1 hour ago
@FireCubez It simply executes the value â string representation function
n
times.â Erik the Outgolfer
53 mins ago
@FireCubez It simply executes the value â string representation function
n
times.â Erik the Outgolfer
53 mins ago
And does executing the string representation of a value print the value?
â FireCubez
52 mins ago
And does executing the string representation of a value print the value?
â FireCubez
52 mins ago
@FireCubez The eval function (
V
) simply evaluates the code within a string. It doesn't implicitly print anything.â Erik the Outgolfer
50 mins ago
@FireCubez The eval function (
V
) simply evaluates the code within a string. It doesn't implicitly print anything.â Erik the Outgolfer
50 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173915%2fcycle-my-input-please%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Are functions that output programs or functions allowed?
â nwellnhof
2 hours ago
3
related duplicate?
â Emigna
2 hours ago
@nwellnhof According to the default rules, yes.
â FireCubez
2 hours ago
@LuisfelipeDejesusMunoz Sorry, I mistyped, I meant the same language, not code
â FireCubez
2 hours ago