Double it your wayI double the source, you double the output!Third time the charmDouble-time is not double timePrint out the first N characters of your codeDouble-slit QuineBeatles Songs and HexagonsHow did I end up with this FizzBuzz?I double the source, you double the output!Double-time is not double timeThird time the charmunRSA: solve the private keyLongest Repeating Subsequence of a Single Digit
Have there been any countries that voted themselves out of existence?
Why don't I get the correct limit of a sequence, regardless of how I arrange it (the sequence), while following the rules for solving limits?
Sol Ⅲ = Earth: What is the origin of this planetary naming scheme?
Writing a worded mathematical expression
Is there a standard terminology for female equivalents of terms such as 'Kingdom' and if so, what are the most common terms?
Is Salesforce Classic being deprecated?
Seized engine due to being run without oil
Are programming languages necessary/useful for operations research practitioner?
How can I protect myself in case of a human attack like the murders of the hikers Jespersen and Ueland in Morocco?
Are there any space probes or landers which regained communication after being lost?
Creating a Master Image to roll out to 30 new Machines Licensing Issues
Defining a function which returns a function pointer which also returns a function pointer without typedefs
A Little Riddle
Why is the T-1000 humanoid?
Why did they ever make smaller than full-frame sensors?
Is it possible to PIVOT on a LIKE statement
Gas pipes - why does gas burn "outwards?"
Relevance of the Resurrection
Can a new chain significantly improve the riding experience? If yes - what else can?
What does "synoptic" mean in avionics?
Should I leave the first authourship of our paper to the student who did the project whereas I solved it?
Exact Brexit date and consequences
Kingdom Map and Travel Pace
How seriously should I take a CBP interview where I was told I have a red flag and could only stay for 30 days?
Double it your way
I double the source, you double the output!Third time the charmDouble-time is not double timePrint out the first N characters of your codeDouble-slit QuineBeatles Songs and HexagonsHow did I end up with this FizzBuzz?I double the source, you double the output!Double-time is not double timeThird time the charmunRSA: solve the private keyLongest Repeating Subsequence of a Single Digit
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Double it your way
There have been a couple of challenges involving doubling source code: here and here. The task we have here is a bit harder, but should be doable in almost every language.
In this challenge, you will take in an arbitrary positive integer. Your program must output that integer doubled.
When your source code is doubled, it will take in a positive integer, and output it squared.
How is your source code doubled? Well, you can have it your way.
That is to say, you can split your source code up into strings of bytes or characters (or tokens in tokenized langs) of any equal length you want, and repeat each chunk twice in succession.
For an initial program of ABCDEFGHIJKL
, (length 12) here are all possible doubled programs:
Chunk length | Doubled source code
-------------+-------------------------
1 | AABBCCDDEEFFGGHHIIJJKKLL
2 | ABABCDCDEFEFGHGHIJIJKLKL
3 | ABCABCDEFDEFGHIGHIJKLJKL
4 | ABCDABCDEFGHEFGHIJKLIJKL
6 | ABCDEFABCDEFGHIJKLGHIJKL
12 | ABCDEFGHIJKLABCDEFGHIJKL
Note that this means programs of prime lengths can only be doubled two ways: every character doubled, or the full program is repeated twice.
Rules:
- Code must be a full program or function.
- Standard loopholes are forbidden.
- Standard I/O methods are allowed.
- All characters/bytes, including whitespace and newlines, are counted in the length of the code and contribute to chunks.
- You may assume that the input and its square can be represented by your language's int/integer type.
- You may not assume a trailing newline or other character.
- Provide your chunk size in the heading after the byte count.
- This is code-golf, so shorter programs are better! If two programs are the same length, the one which uses the smaller chunk length wins. (If you have a longer program which uses a smaller chunk length, that is worth posting too!)
- If your program requires a second input/line, you may make no assumptions on its value. In particular, your program should work if the second input is empty, the same as the first, or a different integer. If your program does not require a second input/line, you may ignore this restriction.
Sandbox link
code-golf integer source-layout
$endgroup$
add a comment |
$begingroup$
Double it your way
There have been a couple of challenges involving doubling source code: here and here. The task we have here is a bit harder, but should be doable in almost every language.
In this challenge, you will take in an arbitrary positive integer. Your program must output that integer doubled.
When your source code is doubled, it will take in a positive integer, and output it squared.
How is your source code doubled? Well, you can have it your way.
That is to say, you can split your source code up into strings of bytes or characters (or tokens in tokenized langs) of any equal length you want, and repeat each chunk twice in succession.
For an initial program of ABCDEFGHIJKL
, (length 12) here are all possible doubled programs:
Chunk length | Doubled source code
-------------+-------------------------
1 | AABBCCDDEEFFGGHHIIJJKKLL
2 | ABABCDCDEFEFGHGHIJIJKLKL
3 | ABCABCDEFDEFGHIGHIJKLJKL
4 | ABCDABCDEFGHEFGHIJKLIJKL
6 | ABCDEFABCDEFGHIJKLGHIJKL
12 | ABCDEFGHIJKLABCDEFGHIJKL
Note that this means programs of prime lengths can only be doubled two ways: every character doubled, or the full program is repeated twice.
Rules:
- Code must be a full program or function.
- Standard loopholes are forbidden.
- Standard I/O methods are allowed.
- All characters/bytes, including whitespace and newlines, are counted in the length of the code and contribute to chunks.
- You may assume that the input and its square can be represented by your language's int/integer type.
- You may not assume a trailing newline or other character.
- Provide your chunk size in the heading after the byte count.
- This is code-golf, so shorter programs are better! If two programs are the same length, the one which uses the smaller chunk length wins. (If you have a longer program which uses a smaller chunk length, that is worth posting too!)
- If your program requires a second input/line, you may make no assumptions on its value. In particular, your program should work if the second input is empty, the same as the first, or a different integer. If your program does not require a second input/line, you may ignore this restriction.
Sandbox link
code-golf integer source-layout
$endgroup$
2
$begingroup$
@Arnauld okay, I undid that. I like the smaller-chunk solutions, but I'll leave the criteria as it is.
$endgroup$
– GammaFunction
11 hours ago
add a comment |
$begingroup$
Double it your way
There have been a couple of challenges involving doubling source code: here and here. The task we have here is a bit harder, but should be doable in almost every language.
In this challenge, you will take in an arbitrary positive integer. Your program must output that integer doubled.
When your source code is doubled, it will take in a positive integer, and output it squared.
How is your source code doubled? Well, you can have it your way.
That is to say, you can split your source code up into strings of bytes or characters (or tokens in tokenized langs) of any equal length you want, and repeat each chunk twice in succession.
For an initial program of ABCDEFGHIJKL
, (length 12) here are all possible doubled programs:
Chunk length | Doubled source code
-------------+-------------------------
1 | AABBCCDDEEFFGGHHIIJJKKLL
2 | ABABCDCDEFEFGHGHIJIJKLKL
3 | ABCABCDEFDEFGHIGHIJKLJKL
4 | ABCDABCDEFGHEFGHIJKLIJKL
6 | ABCDEFABCDEFGHIJKLGHIJKL
12 | ABCDEFGHIJKLABCDEFGHIJKL
Note that this means programs of prime lengths can only be doubled two ways: every character doubled, or the full program is repeated twice.
Rules:
- Code must be a full program or function.
- Standard loopholes are forbidden.
- Standard I/O methods are allowed.
- All characters/bytes, including whitespace and newlines, are counted in the length of the code and contribute to chunks.
- You may assume that the input and its square can be represented by your language's int/integer type.
- You may not assume a trailing newline or other character.
- Provide your chunk size in the heading after the byte count.
- This is code-golf, so shorter programs are better! If two programs are the same length, the one which uses the smaller chunk length wins. (If you have a longer program which uses a smaller chunk length, that is worth posting too!)
- If your program requires a second input/line, you may make no assumptions on its value. In particular, your program should work if the second input is empty, the same as the first, or a different integer. If your program does not require a second input/line, you may ignore this restriction.
Sandbox link
code-golf integer source-layout
$endgroup$
Double it your way
There have been a couple of challenges involving doubling source code: here and here. The task we have here is a bit harder, but should be doable in almost every language.
In this challenge, you will take in an arbitrary positive integer. Your program must output that integer doubled.
When your source code is doubled, it will take in a positive integer, and output it squared.
How is your source code doubled? Well, you can have it your way.
That is to say, you can split your source code up into strings of bytes or characters (or tokens in tokenized langs) of any equal length you want, and repeat each chunk twice in succession.
For an initial program of ABCDEFGHIJKL
, (length 12) here are all possible doubled programs:
Chunk length | Doubled source code
-------------+-------------------------
1 | AABBCCDDEEFFGGHHIIJJKKLL
2 | ABABCDCDEFEFGHGHIJIJKLKL
3 | ABCABCDEFDEFGHIGHIJKLJKL
4 | ABCDABCDEFGHEFGHIJKLIJKL
6 | ABCDEFABCDEFGHIJKLGHIJKL
12 | ABCDEFGHIJKLABCDEFGHIJKL
Note that this means programs of prime lengths can only be doubled two ways: every character doubled, or the full program is repeated twice.
Rules:
- Code must be a full program or function.
- Standard loopholes are forbidden.
- Standard I/O methods are allowed.
- All characters/bytes, including whitespace and newlines, are counted in the length of the code and contribute to chunks.
- You may assume that the input and its square can be represented by your language's int/integer type.
- You may not assume a trailing newline or other character.
- Provide your chunk size in the heading after the byte count.
- This is code-golf, so shorter programs are better! If two programs are the same length, the one which uses the smaller chunk length wins. (If you have a longer program which uses a smaller chunk length, that is worth posting too!)
- If your program requires a second input/line, you may make no assumptions on its value. In particular, your program should work if the second input is empty, the same as the first, or a different integer. If your program does not require a second input/line, you may ignore this restriction.
Sandbox link
code-golf integer source-layout
code-golf integer source-layout
edited 12 hours ago
GammaFunction
asked 17 hours ago
GammaFunctionGammaFunction
1,4101 silver badge14 bronze badges
1,4101 silver badge14 bronze badges
2
$begingroup$
@Arnauld okay, I undid that. I like the smaller-chunk solutions, but I'll leave the criteria as it is.
$endgroup$
– GammaFunction
11 hours ago
add a comment |
2
$begingroup$
@Arnauld okay, I undid that. I like the smaller-chunk solutions, but I'll leave the criteria as it is.
$endgroup$
– GammaFunction
11 hours ago
2
2
$begingroup$
@Arnauld okay, I undid that. I like the smaller-chunk solutions, but I'll leave the criteria as it is.
$endgroup$
– GammaFunction
11 hours ago
$begingroup$
@Arnauld okay, I undid that. I like the smaller-chunk solutions, but I'll leave the criteria as it is.
$endgroup$
– GammaFunction
11 hours ago
add a comment |
17 Answers
17
active
oldest
votes
$begingroup$
05AB1E, 4 bytes (chunk size 2 or 4)
·Inr
Try it online or doubled as a single 4-byte chunk or doubled as two 2-byte chunks.
· # double the implicit input
In # square the input
r # reverse the stack
# stack is now [input ** 2, input * 2]
# if we stop here, the top (input * 2) is implicitly outputted
· # double the top of the stack (giving 4 * input, not that it matters)
In # square the input
r # reverse the stack, putting the first
# stack is now [input ** 2, input * 4, input ** 2]
# input ** 2 is implicitly outputted
$endgroup$
add a comment |
$begingroup$
Perl 5, 8 bytes (chunk size 4)
$_*=~~+2
Try it online, or try the doubled version.
Unary ~
is the bitwise negate, so applying it twice is a noop. Thus, the base program simply multiplies $_
(the implicit input-output variable) by 2.
Binary ~~
is smartmatch, which returns a boolean. ~~+2~~+2
parses as (~~+2) ~~ (+2)
. Since 2 equals 2, this yields true (1). Thus, the doubled program first multiplies $_
by 1, then multiplies $_
by itself.
$endgroup$
add a comment |
$begingroup$
Befunge-98 (FBBI), 8 bytes (chunk length 2)
;&:#* +q
Try it online!
;&;&:#:#* * +q+q
Try it online! (doubled)
Excluding control flow, the first program executes &:+q
(input, duplicate top of stack, add, exit with return code), and the second executes &:*+q
(input, duplicate top of stack, multiply, add (sums with an implicit 0), exit with return code)
$endgroup$
add a comment |
$begingroup$
Python 3, 32 30 28 bytes (chunk size 16 15 14)
lambda n:bool(0)*n*n or 2*n
Try it online!
-4 bytes thanks to @negativeSeven
Doubled:
lambda n:bool(lambda n:bool(0)*n*n or 2*n0)*n*n or 2*n
Try it online!
The function takes advantage of the unique chunk rule of this challenge.
$endgroup$
1
$begingroup$
26: TIO
$endgroup$
– Grimy
7 hours ago
$begingroup$
@Grimy Nice approach. I think it is different enough and deserves its own post.
$endgroup$
– Joel
5 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 24 22 bytes
Despite its unusual format, this is the definition of an anonymous function, which can be either called directly or assigned to a variable.
+(g=x=>x*x)?g:(x=>x*2)
Try it online!
+(g=x=>x*x)?g:(x=>x*2)+(g=x=>x*x)?g:(x=>x*2)
Try it online doubled!
How?
Applying the unary +
to a function is interpreted as an attempt to coerce it to a number and results in NaN. Therefore, the leading +(g=x=>x*x)
is falsy in both versions.
On the other hand, applying the binary +
between 2 functions results in a string. Therefore, (x=>x*2)+(g=x=>x*x)
is truthy in the doubled version.
$endgroup$
add a comment |
$begingroup$
Runic Enchantments, 9 bytes (chunk size 3)
i3?:*@:+@
Try it online!
Try it doubled!
The 3?
skips the next 3 instructions, resulting in an (executed) i3?...:+@
. When doubled it results in an executed i3?...:*@
where .
represents the 3 NOP'd instructions. @
is "print entire stack and terminate."
$endgroup$
add a comment |
$begingroup$
Charcoal, 13 bytes
PI×Iθ⎇υIθ²⊞υω
Try it online! Explanation: The predefined empty list is falsey so the input is multiplied by 2. When doubled the second pass sees the empty string has been pushed to the list so it multiplies the input by itself instead. Try it online! In verbose syntax this corresponds to Multiprint(Cast(Times(Cast(q), Ternary(u, Cast(q), 2)))); Push(u, w);
.
$endgroup$
add a comment |
$begingroup$
R, 59 bytes (chunk size 59)
c(`*`,`^`)[[1+length(readLines())]](scan(file("stdin")),2)
Try it online!
Note the trailing newline. This forces scan
to read from stdin
rather than the source file (which is what stdin()
redirects to....), and use readLines()
to ignore all additional copies of the source, inspired by this answer to a similar challenge.
This isn't particularly interesting, but doubtless something clever manipulating the chunk size will be dreamed up.
$endgroup$
add a comment |
$begingroup$
Japt, 7 5 bytes
*N²jJ
Try it | Doubled
²
pushes 2 to the array of inputs N
then j
removes & returns the element at index J=-1
(i.e., the newly inserted 2
) and multiplies the input by that.
When doubled it results in J
being multiplied by 2
, so the element at index -2
(i.e., the input) is returned by j
and used as the multiplier.
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler) / Javascript, 22 bytes, chunk size 11
m=>/* /2*m//*/m*2
Try it online!
$endgroup$
$begingroup$
Also works in JavaScript
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
Perl 6, 8 bytes (chunk size 1)
* *<1 2>
Try it online! Try it doubled!
A Whatever/HyperWhatever lambda that takes a number and returns a number for the first program and a singleton list for the second program. Basically this keeps the exact same logic, except that the multiplication operator (*
) is replaced by the exponential one (**
).
The Whatever literal (confusingly also represented by a *
) are doubled up to a HyperWhatever (**
) which is basically the same except it maps over lists. The space is needed to separate the Whatever literal from the multiplication and is ignored when doubled up. Instead of just 2
(which would get doubled to 22
) we use a list containing two elements, which evaluates to 2 in a numeric context). The <>
can be doubled to a list with interpolation, and the two elements inside are doubled, but neither of those change the length of the list.
$endgroup$
add a comment |
$begingroup$
Brain-Flak (BrainHack), 76 bytes, 76 byte chunks
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Doubled (with newline for clarity)
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Here is a version that uses a more complex doubling procedure. It does 5 chunks of size 15. The code here is 46 bytes however due to the required padding it is substantially longer.
105 bytes, 15 byte chunks
( <>< <>>()([()])<><(()())><> )<>
Try it online!
Doubled (with newlines for clarity)
( (
<>< <><
<>>()([()])<>>()([()])
<><(()())><> <><(()())><>
)<> )<>
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 (-p
), 22 15 bytes
-7 bytes thanks to Grimy
$_*=$'/4||2;//;
TIO
$endgroup$
$begingroup$
15: TIO
$endgroup$
– Grimy
15 hours ago
$begingroup$
looking at your solution, I'd just found a 22 bytes solution
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
understood, first input*=2, then by input*=input/4
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
another 16 bytes (-a)$_*=/@F/?2:$_/4;
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
Down to 8 (posted as a separate answer since it's very different).
$endgroup$
– Grimy
15 hours ago
add a comment |
$begingroup$
Python 3, 56 53 bytes
print(eval(input()+"**2"[len(*open(__file__))%2:])) #
My python skills kinda suck, so can definitely be golfed.. Based on the Python answer in the "I double the source, you double the output!" challenge.
Chunk length 53.
Try it online or try it online doubled.
$endgroup$
add a comment |
$begingroup$
Java 8, 62 bytes
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
Chunk length 62.
Try it online or try it online doubled.
Explanation:
n-> // Method with integer as both parameter and return-type
n* // The input, multiplied by:
(Byte.SIZE>8? // If Byte.SIZE is larger than 8:
n // Multiply by the input itself
: // Else:
2); // Multiply by 2
class Byte // Class which overwrites Byte
static int SIZE=9; // And sets the SIZE to 9
In Java, the available comments are // comment
and /* comment */
. Which are combined here to overwrite certain parts. See how these comments work thanks to the Java highlighting:
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
The doubled program created a custom Byte
class and its value SIZE=9
, which overwrites the default java.lang.Byte
class and its value SIZE=8
.
$endgroup$
add a comment |
$begingroup$
Jelly, 8 6 bytes (chunk length 3)
Ḥ;²3ị
Try it online!
Doubled
$endgroup$
add a comment |
$begingroup$
J, 17 bytes
*:@[`(+:@[)@.(=~)
Try it online!
Doubled version: Try it online!
In the single version, we have a single verb which uses Agenda @.
to do the if... then logic: If the argument is equal to itself =~
, then take the argument and double it (+:@[)
.
However, when we double the code, we get a J hook. Call the verb f
and the input y
. Then the hook f f
executes like this:
y f (f y)
Which means that now the original input is the left arg, and the right arg is the doubled input. Since these will not be equal, =~
will return false this time, and now we'll execute the other fork of the Agenda, ie, *:@[
, which means "square the left arg." And since that's the original input, we have what we need.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f191580%2fdouble-it-your-way%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
17 Answers
17
active
oldest
votes
17 Answers
17
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
05AB1E, 4 bytes (chunk size 2 or 4)
·Inr
Try it online or doubled as a single 4-byte chunk or doubled as two 2-byte chunks.
· # double the implicit input
In # square the input
r # reverse the stack
# stack is now [input ** 2, input * 2]
# if we stop here, the top (input * 2) is implicitly outputted
· # double the top of the stack (giving 4 * input, not that it matters)
In # square the input
r # reverse the stack, putting the first
# stack is now [input ** 2, input * 4, input ** 2]
# input ** 2 is implicitly outputted
$endgroup$
add a comment |
$begingroup$
05AB1E, 4 bytes (chunk size 2 or 4)
·Inr
Try it online or doubled as a single 4-byte chunk or doubled as two 2-byte chunks.
· # double the implicit input
In # square the input
r # reverse the stack
# stack is now [input ** 2, input * 2]
# if we stop here, the top (input * 2) is implicitly outputted
· # double the top of the stack (giving 4 * input, not that it matters)
In # square the input
r # reverse the stack, putting the first
# stack is now [input ** 2, input * 4, input ** 2]
# input ** 2 is implicitly outputted
$endgroup$
add a comment |
$begingroup$
05AB1E, 4 bytes (chunk size 2 or 4)
·Inr
Try it online or doubled as a single 4-byte chunk or doubled as two 2-byte chunks.
· # double the implicit input
In # square the input
r # reverse the stack
# stack is now [input ** 2, input * 2]
# if we stop here, the top (input * 2) is implicitly outputted
· # double the top of the stack (giving 4 * input, not that it matters)
In # square the input
r # reverse the stack, putting the first
# stack is now [input ** 2, input * 4, input ** 2]
# input ** 2 is implicitly outputted
$endgroup$
05AB1E, 4 bytes (chunk size 2 or 4)
·Inr
Try it online or doubled as a single 4-byte chunk or doubled as two 2-byte chunks.
· # double the implicit input
In # square the input
r # reverse the stack
# stack is now [input ** 2, input * 2]
# if we stop here, the top (input * 2) is implicitly outputted
· # double the top of the stack (giving 4 * input, not that it matters)
In # square the input
r # reverse the stack, putting the first
# stack is now [input ** 2, input * 4, input ** 2]
# input ** 2 is implicitly outputted
edited 16 hours ago
answered 16 hours ago
GrimyGrimy
7,21016 silver badges33 bronze badges
7,21016 silver badges33 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 5, 8 bytes (chunk size 4)
$_*=~~+2
Try it online, or try the doubled version.
Unary ~
is the bitwise negate, so applying it twice is a noop. Thus, the base program simply multiplies $_
(the implicit input-output variable) by 2.
Binary ~~
is smartmatch, which returns a boolean. ~~+2~~+2
parses as (~~+2) ~~ (+2)
. Since 2 equals 2, this yields true (1). Thus, the doubled program first multiplies $_
by 1, then multiplies $_
by itself.
$endgroup$
add a comment |
$begingroup$
Perl 5, 8 bytes (chunk size 4)
$_*=~~+2
Try it online, or try the doubled version.
Unary ~
is the bitwise negate, so applying it twice is a noop. Thus, the base program simply multiplies $_
(the implicit input-output variable) by 2.
Binary ~~
is smartmatch, which returns a boolean. ~~+2~~+2
parses as (~~+2) ~~ (+2)
. Since 2 equals 2, this yields true (1). Thus, the doubled program first multiplies $_
by 1, then multiplies $_
by itself.
$endgroup$
add a comment |
$begingroup$
Perl 5, 8 bytes (chunk size 4)
$_*=~~+2
Try it online, or try the doubled version.
Unary ~
is the bitwise negate, so applying it twice is a noop. Thus, the base program simply multiplies $_
(the implicit input-output variable) by 2.
Binary ~~
is smartmatch, which returns a boolean. ~~+2~~+2
parses as (~~+2) ~~ (+2)
. Since 2 equals 2, this yields true (1). Thus, the doubled program first multiplies $_
by 1, then multiplies $_
by itself.
$endgroup$
Perl 5, 8 bytes (chunk size 4)
$_*=~~+2
Try it online, or try the doubled version.
Unary ~
is the bitwise negate, so applying it twice is a noop. Thus, the base program simply multiplies $_
(the implicit input-output variable) by 2.
Binary ~~
is smartmatch, which returns a boolean. ~~+2~~+2
parses as (~~+2) ~~ (+2)
. Since 2 equals 2, this yields true (1). Thus, the doubled program first multiplies $_
by 1, then multiplies $_
by itself.
edited 14 hours ago
answered 15 hours ago
GrimyGrimy
7,21016 silver badges33 bronze badges
7,21016 silver badges33 bronze badges
add a comment |
add a comment |
$begingroup$
Befunge-98 (FBBI), 8 bytes (chunk length 2)
;&:#* +q
Try it online!
;&;&:#:#* * +q+q
Try it online! (doubled)
Excluding control flow, the first program executes &:+q
(input, duplicate top of stack, add, exit with return code), and the second executes &:*+q
(input, duplicate top of stack, multiply, add (sums with an implicit 0), exit with return code)
$endgroup$
add a comment |
$begingroup$
Befunge-98 (FBBI), 8 bytes (chunk length 2)
;&:#* +q
Try it online!
;&;&:#:#* * +q+q
Try it online! (doubled)
Excluding control flow, the first program executes &:+q
(input, duplicate top of stack, add, exit with return code), and the second executes &:*+q
(input, duplicate top of stack, multiply, add (sums with an implicit 0), exit with return code)
$endgroup$
add a comment |
$begingroup$
Befunge-98 (FBBI), 8 bytes (chunk length 2)
;&:#* +q
Try it online!
;&;&:#:#* * +q+q
Try it online! (doubled)
Excluding control flow, the first program executes &:+q
(input, duplicate top of stack, add, exit with return code), and the second executes &:*+q
(input, duplicate top of stack, multiply, add (sums with an implicit 0), exit with return code)
$endgroup$
Befunge-98 (FBBI), 8 bytes (chunk length 2)
;&:#* +q
Try it online!
;&;&:#:#* * +q+q
Try it online! (doubled)
Excluding control flow, the first program executes &:+q
(input, duplicate top of stack, add, exit with return code), and the second executes &:*+q
(input, duplicate top of stack, multiply, add (sums with an implicit 0), exit with return code)
edited 12 hours ago
answered 13 hours ago
negative sevennegative seven
1,6011 gold badge3 silver badges13 bronze badges
1,6011 gold badge3 silver badges13 bronze badges
add a comment |
add a comment |
$begingroup$
Python 3, 32 30 28 bytes (chunk size 16 15 14)
lambda n:bool(0)*n*n or 2*n
Try it online!
-4 bytes thanks to @negativeSeven
Doubled:
lambda n:bool(lambda n:bool(0)*n*n or 2*n0)*n*n or 2*n
Try it online!
The function takes advantage of the unique chunk rule of this challenge.
$endgroup$
1
$begingroup$
26: TIO
$endgroup$
– Grimy
7 hours ago
$begingroup$
@Grimy Nice approach. I think it is different enough and deserves its own post.
$endgroup$
– Joel
5 hours ago
add a comment |
$begingroup$
Python 3, 32 30 28 bytes (chunk size 16 15 14)
lambda n:bool(0)*n*n or 2*n
Try it online!
-4 bytes thanks to @negativeSeven
Doubled:
lambda n:bool(lambda n:bool(0)*n*n or 2*n0)*n*n or 2*n
Try it online!
The function takes advantage of the unique chunk rule of this challenge.
$endgroup$
1
$begingroup$
26: TIO
$endgroup$
– Grimy
7 hours ago
$begingroup$
@Grimy Nice approach. I think it is different enough and deserves its own post.
$endgroup$
– Joel
5 hours ago
add a comment |
$begingroup$
Python 3, 32 30 28 bytes (chunk size 16 15 14)
lambda n:bool(0)*n*n or 2*n
Try it online!
-4 bytes thanks to @negativeSeven
Doubled:
lambda n:bool(lambda n:bool(0)*n*n or 2*n0)*n*n or 2*n
Try it online!
The function takes advantage of the unique chunk rule of this challenge.
$endgroup$
Python 3, 32 30 28 bytes (chunk size 16 15 14)
lambda n:bool(0)*n*n or 2*n
Try it online!
-4 bytes thanks to @negativeSeven
Doubled:
lambda n:bool(lambda n:bool(0)*n*n or 2*n0)*n*n or 2*n
Try it online!
The function takes advantage of the unique chunk rule of this challenge.
edited 10 hours ago
answered 11 hours ago
JoelJoel
1,1118 bronze badges
1,1118 bronze badges
1
$begingroup$
26: TIO
$endgroup$
– Grimy
7 hours ago
$begingroup$
@Grimy Nice approach. I think it is different enough and deserves its own post.
$endgroup$
– Joel
5 hours ago
add a comment |
1
$begingroup$
26: TIO
$endgroup$
– Grimy
7 hours ago
$begingroup$
@Grimy Nice approach. I think it is different enough and deserves its own post.
$endgroup$
– Joel
5 hours ago
1
1
$begingroup$
26: TIO
$endgroup$
– Grimy
7 hours ago
$begingroup$
26: TIO
$endgroup$
– Grimy
7 hours ago
$begingroup$
@Grimy Nice approach. I think it is different enough and deserves its own post.
$endgroup$
– Joel
5 hours ago
$begingroup$
@Grimy Nice approach. I think it is different enough and deserves its own post.
$endgroup$
– Joel
5 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 24 22 bytes
Despite its unusual format, this is the definition of an anonymous function, which can be either called directly or assigned to a variable.
+(g=x=>x*x)?g:(x=>x*2)
Try it online!
+(g=x=>x*x)?g:(x=>x*2)+(g=x=>x*x)?g:(x=>x*2)
Try it online doubled!
How?
Applying the unary +
to a function is interpreted as an attempt to coerce it to a number and results in NaN. Therefore, the leading +(g=x=>x*x)
is falsy in both versions.
On the other hand, applying the binary +
between 2 functions results in a string. Therefore, (x=>x*2)+(g=x=>x*x)
is truthy in the doubled version.
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 24 22 bytes
Despite its unusual format, this is the definition of an anonymous function, which can be either called directly or assigned to a variable.
+(g=x=>x*x)?g:(x=>x*2)
Try it online!
+(g=x=>x*x)?g:(x=>x*2)+(g=x=>x*x)?g:(x=>x*2)
Try it online doubled!
How?
Applying the unary +
to a function is interpreted as an attempt to coerce it to a number and results in NaN. Therefore, the leading +(g=x=>x*x)
is falsy in both versions.
On the other hand, applying the binary +
between 2 functions results in a string. Therefore, (x=>x*2)+(g=x=>x*x)
is truthy in the doubled version.
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 24 22 bytes
Despite its unusual format, this is the definition of an anonymous function, which can be either called directly or assigned to a variable.
+(g=x=>x*x)?g:(x=>x*2)
Try it online!
+(g=x=>x*x)?g:(x=>x*2)+(g=x=>x*x)?g:(x=>x*2)
Try it online doubled!
How?
Applying the unary +
to a function is interpreted as an attempt to coerce it to a number and results in NaN. Therefore, the leading +(g=x=>x*x)
is falsy in both versions.
On the other hand, applying the binary +
between 2 functions results in a string. Therefore, (x=>x*2)+(g=x=>x*x)
is truthy in the doubled version.
$endgroup$
JavaScript (ES6), 24 22 bytes
Despite its unusual format, this is the definition of an anonymous function, which can be either called directly or assigned to a variable.
+(g=x=>x*x)?g:(x=>x*2)
Try it online!
+(g=x=>x*x)?g:(x=>x*2)+(g=x=>x*x)?g:(x=>x*2)
Try it online doubled!
How?
Applying the unary +
to a function is interpreted as an attempt to coerce it to a number and results in NaN. Therefore, the leading +(g=x=>x*x)
is falsy in both versions.
On the other hand, applying the binary +
between 2 functions results in a string. Therefore, (x=>x*2)+(g=x=>x*x)
is truthy in the doubled version.
edited 14 hours ago
answered 14 hours ago
ArnauldArnauld
92.3k7 gold badges108 silver badges376 bronze badges
92.3k7 gold badges108 silver badges376 bronze badges
add a comment |
add a comment |
$begingroup$
Runic Enchantments, 9 bytes (chunk size 3)
i3?:*@:+@
Try it online!
Try it doubled!
The 3?
skips the next 3 instructions, resulting in an (executed) i3?...:+@
. When doubled it results in an executed i3?...:*@
where .
represents the 3 NOP'd instructions. @
is "print entire stack and terminate."
$endgroup$
add a comment |
$begingroup$
Runic Enchantments, 9 bytes (chunk size 3)
i3?:*@:+@
Try it online!
Try it doubled!
The 3?
skips the next 3 instructions, resulting in an (executed) i3?...:+@
. When doubled it results in an executed i3?...:*@
where .
represents the 3 NOP'd instructions. @
is "print entire stack and terminate."
$endgroup$
add a comment |
$begingroup$
Runic Enchantments, 9 bytes (chunk size 3)
i3?:*@:+@
Try it online!
Try it doubled!
The 3?
skips the next 3 instructions, resulting in an (executed) i3?...:+@
. When doubled it results in an executed i3?...:*@
where .
represents the 3 NOP'd instructions. @
is "print entire stack and terminate."
$endgroup$
Runic Enchantments, 9 bytes (chunk size 3)
i3?:*@:+@
Try it online!
Try it doubled!
The 3?
skips the next 3 instructions, resulting in an (executed) i3?...:+@
. When doubled it results in an executed i3?...:*@
where .
represents the 3 NOP'd instructions. @
is "print entire stack and terminate."
answered 12 hours ago
Draco18sDraco18s
2,3237 silver badges21 bronze badges
2,3237 silver badges21 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 13 bytes
PI×Iθ⎇υIθ²⊞υω
Try it online! Explanation: The predefined empty list is falsey so the input is multiplied by 2. When doubled the second pass sees the empty string has been pushed to the list so it multiplies the input by itself instead. Try it online! In verbose syntax this corresponds to Multiprint(Cast(Times(Cast(q), Ternary(u, Cast(q), 2)))); Push(u, w);
.
$endgroup$
add a comment |
$begingroup$
Charcoal, 13 bytes
PI×Iθ⎇υIθ²⊞υω
Try it online! Explanation: The predefined empty list is falsey so the input is multiplied by 2. When doubled the second pass sees the empty string has been pushed to the list so it multiplies the input by itself instead. Try it online! In verbose syntax this corresponds to Multiprint(Cast(Times(Cast(q), Ternary(u, Cast(q), 2)))); Push(u, w);
.
$endgroup$
add a comment |
$begingroup$
Charcoal, 13 bytes
PI×Iθ⎇υIθ²⊞υω
Try it online! Explanation: The predefined empty list is falsey so the input is multiplied by 2. When doubled the second pass sees the empty string has been pushed to the list so it multiplies the input by itself instead. Try it online! In verbose syntax this corresponds to Multiprint(Cast(Times(Cast(q), Ternary(u, Cast(q), 2)))); Push(u, w);
.
$endgroup$
Charcoal, 13 bytes
PI×Iθ⎇υIθ²⊞υω
Try it online! Explanation: The predefined empty list is falsey so the input is multiplied by 2. When doubled the second pass sees the empty string has been pushed to the list so it multiplies the input by itself instead. Try it online! In verbose syntax this corresponds to Multiprint(Cast(Times(Cast(q), Ternary(u, Cast(q), 2)))); Push(u, w);
.
answered 15 hours ago
NeilNeil
88.8k8 gold badges46 silver badges188 bronze badges
88.8k8 gold badges46 silver badges188 bronze badges
add a comment |
add a comment |
$begingroup$
R, 59 bytes (chunk size 59)
c(`*`,`^`)[[1+length(readLines())]](scan(file("stdin")),2)
Try it online!
Note the trailing newline. This forces scan
to read from stdin
rather than the source file (which is what stdin()
redirects to....), and use readLines()
to ignore all additional copies of the source, inspired by this answer to a similar challenge.
This isn't particularly interesting, but doubtless something clever manipulating the chunk size will be dreamed up.
$endgroup$
add a comment |
$begingroup$
R, 59 bytes (chunk size 59)
c(`*`,`^`)[[1+length(readLines())]](scan(file("stdin")),2)
Try it online!
Note the trailing newline. This forces scan
to read from stdin
rather than the source file (which is what stdin()
redirects to....), and use readLines()
to ignore all additional copies of the source, inspired by this answer to a similar challenge.
This isn't particularly interesting, but doubtless something clever manipulating the chunk size will be dreamed up.
$endgroup$
add a comment |
$begingroup$
R, 59 bytes (chunk size 59)
c(`*`,`^`)[[1+length(readLines())]](scan(file("stdin")),2)
Try it online!
Note the trailing newline. This forces scan
to read from stdin
rather than the source file (which is what stdin()
redirects to....), and use readLines()
to ignore all additional copies of the source, inspired by this answer to a similar challenge.
This isn't particularly interesting, but doubtless something clever manipulating the chunk size will be dreamed up.
$endgroup$
R, 59 bytes (chunk size 59)
c(`*`,`^`)[[1+length(readLines())]](scan(file("stdin")),2)
Try it online!
Note the trailing newline. This forces scan
to read from stdin
rather than the source file (which is what stdin()
redirects to....), and use readLines()
to ignore all additional copies of the source, inspired by this answer to a similar challenge.
This isn't particularly interesting, but doubtless something clever manipulating the chunk size will be dreamed up.
answered 11 hours ago
GiuseppeGiuseppe
19.1k3 gold badges16 silver badges70 bronze badges
19.1k3 gold badges16 silver badges70 bronze badges
add a comment |
add a comment |
$begingroup$
Japt, 7 5 bytes
*N²jJ
Try it | Doubled
²
pushes 2 to the array of inputs N
then j
removes & returns the element at index J=-1
(i.e., the newly inserted 2
) and multiplies the input by that.
When doubled it results in J
being multiplied by 2
, so the element at index -2
(i.e., the input) is returned by j
and used as the multiplier.
$endgroup$
add a comment |
$begingroup$
Japt, 7 5 bytes
*N²jJ
Try it | Doubled
²
pushes 2 to the array of inputs N
then j
removes & returns the element at index J=-1
(i.e., the newly inserted 2
) and multiplies the input by that.
When doubled it results in J
being multiplied by 2
, so the element at index -2
(i.e., the input) is returned by j
and used as the multiplier.
$endgroup$
add a comment |
$begingroup$
Japt, 7 5 bytes
*N²jJ
Try it | Doubled
²
pushes 2 to the array of inputs N
then j
removes & returns the element at index J=-1
(i.e., the newly inserted 2
) and multiplies the input by that.
When doubled it results in J
being multiplied by 2
, so the element at index -2
(i.e., the input) is returned by j
and used as the multiplier.
$endgroup$
Japt, 7 5 bytes
*N²jJ
Try it | Doubled
²
pushes 2 to the array of inputs N
then j
removes & returns the element at index J=-1
(i.e., the newly inserted 2
) and multiplies the input by that.
When doubled it results in J
being multiplied by 2
, so the element at index -2
(i.e., the input) is returned by j
and used as the multiplier.
edited 7 hours ago
answered 10 hours ago
ShaggyShaggy
21.4k3 gold badges21 silver badges72 bronze badges
21.4k3 gold badges21 silver badges72 bronze badges
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler) / Javascript, 22 bytes, chunk size 11
m=>/* /2*m//*/m*2
Try it online!
$endgroup$
$begingroup$
Also works in JavaScript
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler) / Javascript, 22 bytes, chunk size 11
m=>/* /2*m//*/m*2
Try it online!
$endgroup$
$begingroup$
Also works in JavaScript
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler) / Javascript, 22 bytes, chunk size 11
m=>/* /2*m//*/m*2
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler) / Javascript, 22 bytes, chunk size 11
m=>/* /2*m//*/m*2
Try it online!
edited 5 hours ago
answered 8 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
5,3062 silver badges31 bronze badges
5,3062 silver badges31 bronze badges
$begingroup$
Also works in JavaScript
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
Also works in JavaScript
$endgroup$
– Shaggy
7 hours ago
$begingroup$
Also works in JavaScript
$endgroup$
– Shaggy
7 hours ago
$begingroup$
Also works in JavaScript
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
Perl 6, 8 bytes (chunk size 1)
* *<1 2>
Try it online! Try it doubled!
A Whatever/HyperWhatever lambda that takes a number and returns a number for the first program and a singleton list for the second program. Basically this keeps the exact same logic, except that the multiplication operator (*
) is replaced by the exponential one (**
).
The Whatever literal (confusingly also represented by a *
) are doubled up to a HyperWhatever (**
) which is basically the same except it maps over lists. The space is needed to separate the Whatever literal from the multiplication and is ignored when doubled up. Instead of just 2
(which would get doubled to 22
) we use a list containing two elements, which evaluates to 2 in a numeric context). The <>
can be doubled to a list with interpolation, and the two elements inside are doubled, but neither of those change the length of the list.
$endgroup$
add a comment |
$begingroup$
Perl 6, 8 bytes (chunk size 1)
* *<1 2>
Try it online! Try it doubled!
A Whatever/HyperWhatever lambda that takes a number and returns a number for the first program and a singleton list for the second program. Basically this keeps the exact same logic, except that the multiplication operator (*
) is replaced by the exponential one (**
).
The Whatever literal (confusingly also represented by a *
) are doubled up to a HyperWhatever (**
) which is basically the same except it maps over lists. The space is needed to separate the Whatever literal from the multiplication and is ignored when doubled up. Instead of just 2
(which would get doubled to 22
) we use a list containing two elements, which evaluates to 2 in a numeric context). The <>
can be doubled to a list with interpolation, and the two elements inside are doubled, but neither of those change the length of the list.
$endgroup$
add a comment |
$begingroup$
Perl 6, 8 bytes (chunk size 1)
* *<1 2>
Try it online! Try it doubled!
A Whatever/HyperWhatever lambda that takes a number and returns a number for the first program and a singleton list for the second program. Basically this keeps the exact same logic, except that the multiplication operator (*
) is replaced by the exponential one (**
).
The Whatever literal (confusingly also represented by a *
) are doubled up to a HyperWhatever (**
) which is basically the same except it maps over lists. The space is needed to separate the Whatever literal from the multiplication and is ignored when doubled up. Instead of just 2
(which would get doubled to 22
) we use a list containing two elements, which evaluates to 2 in a numeric context). The <>
can be doubled to a list with interpolation, and the two elements inside are doubled, but neither of those change the length of the list.
$endgroup$
Perl 6, 8 bytes (chunk size 1)
* *<1 2>
Try it online! Try it doubled!
A Whatever/HyperWhatever lambda that takes a number and returns a number for the first program and a singleton list for the second program. Basically this keeps the exact same logic, except that the multiplication operator (*
) is replaced by the exponential one (**
).
The Whatever literal (confusingly also represented by a *
) are doubled up to a HyperWhatever (**
) which is basically the same except it maps over lists. The space is needed to separate the Whatever literal from the multiplication and is ignored when doubled up. Instead of just 2
(which would get doubled to 22
) we use a list containing two elements, which evaluates to 2 in a numeric context). The <>
can be doubled to a list with interpolation, and the two elements inside are doubled, but neither of those change the length of the list.
edited 2 hours ago
answered 2 hours ago
Jo KingJo King
30.9k4 gold badges72 silver badges139 bronze badges
30.9k4 gold badges72 silver badges139 bronze badges
add a comment |
add a comment |
$begingroup$
Brain-Flak (BrainHack), 76 bytes, 76 byte chunks
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Doubled (with newline for clarity)
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Here is a version that uses a more complex doubling procedure. It does 5 chunks of size 15. The code here is 46 bytes however due to the required padding it is substantially longer.
105 bytes, 15 byte chunks
( <>< <>>()([()])<><(()())><> )<>
Try it online!
Doubled (with newlines for clarity)
( (
<>< <><
<>>()([()])<>>()([()])
<><(()())><> <><(()())><>
)<> )<>
Try it online!
$endgroup$
add a comment |
$begingroup$
Brain-Flak (BrainHack), 76 bytes, 76 byte chunks
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Doubled (with newline for clarity)
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Here is a version that uses a more complex doubling procedure. It does 5 chunks of size 15. The code here is 46 bytes however due to the required padding it is substantially longer.
105 bytes, 15 byte chunks
( <>< <>>()([()])<><(()())><> )<>
Try it online!
Doubled (with newlines for clarity)
( (
<>< <><
<>>()([()])<>>()([()])
<><(()())><> <><(()())><>
)<> )<>
Try it online!
$endgroup$
add a comment |
$begingroup$
Brain-Flak (BrainHack), 76 bytes, 76 byte chunks
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Doubled (with newline for clarity)
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Here is a version that uses a more complex doubling procedure. It does 5 chunks of size 15. The code here is 46 bytes however due to the required padding it is substantially longer.
105 bytes, 15 byte chunks
( <>< <>>()([()])<><(()())><> )<>
Try it online!
Doubled (with newlines for clarity)
( (
<>< <><
<>>()([()])<>>()([()])
<><(()())><> <><(()())><>
)<> )<>
Try it online!
$endgroup$
Brain-Flak (BrainHack), 76 bytes, 76 byte chunks
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Doubled (with newline for clarity)
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
(<>)(()[([][()])](<(()([()])<>)<>>))(()()<>)(<>)<>
Try it online!
Here is a version that uses a more complex doubling procedure. It does 5 chunks of size 15. The code here is 46 bytes however due to the required padding it is substantially longer.
105 bytes, 15 byte chunks
( <>< <>>()([()])<><(()())><> )<>
Try it online!
Doubled (with newlines for clarity)
( (
<>< <><
<>>()([()])<>>()([()])
<><(()())><> <><(()())><>
)<> )<>
Try it online!
edited 1 hour ago
answered 7 hours ago
Sriotchilism O'ZaicSriotchilism O'Zaic
37.9k10 gold badges169 silver badges383 bronze badges
37.9k10 gold badges169 silver badges383 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 5 (-p
), 22 15 bytes
-7 bytes thanks to Grimy
$_*=$'/4||2;//;
TIO
$endgroup$
$begingroup$
15: TIO
$endgroup$
– Grimy
15 hours ago
$begingroup$
looking at your solution, I'd just found a 22 bytes solution
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
understood, first input*=2, then by input*=input/4
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
another 16 bytes (-a)$_*=/@F/?2:$_/4;
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
Down to 8 (posted as a separate answer since it's very different).
$endgroup$
– Grimy
15 hours ago
add a comment |
$begingroup$
Perl 5 (-p
), 22 15 bytes
-7 bytes thanks to Grimy
$_*=$'/4||2;//;
TIO
$endgroup$
$begingroup$
15: TIO
$endgroup$
– Grimy
15 hours ago
$begingroup$
looking at your solution, I'd just found a 22 bytes solution
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
understood, first input*=2, then by input*=input/4
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
another 16 bytes (-a)$_*=/@F/?2:$_/4;
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
Down to 8 (posted as a separate answer since it's very different).
$endgroup$
– Grimy
15 hours ago
add a comment |
$begingroup$
Perl 5 (-p
), 22 15 bytes
-7 bytes thanks to Grimy
$_*=$'/4||2;//;
TIO
$endgroup$
Perl 5 (-p
), 22 15 bytes
-7 bytes thanks to Grimy
$_*=$'/4||2;//;
TIO
edited 15 hours ago
answered 16 hours ago
Nahuel FouilleulNahuel Fouilleul
4,1371 gold badge4 silver badges14 bronze badges
4,1371 gold badge4 silver badges14 bronze badges
$begingroup$
15: TIO
$endgroup$
– Grimy
15 hours ago
$begingroup$
looking at your solution, I'd just found a 22 bytes solution
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
understood, first input*=2, then by input*=input/4
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
another 16 bytes (-a)$_*=/@F/?2:$_/4;
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
Down to 8 (posted as a separate answer since it's very different).
$endgroup$
– Grimy
15 hours ago
add a comment |
$begingroup$
15: TIO
$endgroup$
– Grimy
15 hours ago
$begingroup$
looking at your solution, I'd just found a 22 bytes solution
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
understood, first input*=2, then by input*=input/4
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
another 16 bytes (-a)$_*=/@F/?2:$_/4;
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
Down to 8 (posted as a separate answer since it's very different).
$endgroup$
– Grimy
15 hours ago
$begingroup$
15: TIO
$endgroup$
– Grimy
15 hours ago
$begingroup$
15: TIO
$endgroup$
– Grimy
15 hours ago
$begingroup$
looking at your solution, I'd just found a 22 bytes solution
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
looking at your solution, I'd just found a 22 bytes solution
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
understood, first input*=2, then by input*=input/4
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
understood, first input*=2, then by input*=input/4
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
another 16 bytes (-a)
$_*=/@F/?2:$_/4;
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
another 16 bytes (-a)
$_*=/@F/?2:$_/4;
$endgroup$
– Nahuel Fouilleul
15 hours ago
$begingroup$
Down to 8 (posted as a separate answer since it's very different).
$endgroup$
– Grimy
15 hours ago
$begingroup$
Down to 8 (posted as a separate answer since it's very different).
$endgroup$
– Grimy
15 hours ago
add a comment |
$begingroup$
Python 3, 56 53 bytes
print(eval(input()+"**2"[len(*open(__file__))%2:])) #
My python skills kinda suck, so can definitely be golfed.. Based on the Python answer in the "I double the source, you double the output!" challenge.
Chunk length 53.
Try it online or try it online doubled.
$endgroup$
add a comment |
$begingroup$
Python 3, 56 53 bytes
print(eval(input()+"**2"[len(*open(__file__))%2:])) #
My python skills kinda suck, so can definitely be golfed.. Based on the Python answer in the "I double the source, you double the output!" challenge.
Chunk length 53.
Try it online or try it online doubled.
$endgroup$
add a comment |
$begingroup$
Python 3, 56 53 bytes
print(eval(input()+"**2"[len(*open(__file__))%2:])) #
My python skills kinda suck, so can definitely be golfed.. Based on the Python answer in the "I double the source, you double the output!" challenge.
Chunk length 53.
Try it online or try it online doubled.
$endgroup$
Python 3, 56 53 bytes
print(eval(input()+"**2"[len(*open(__file__))%2:])) #
My python skills kinda suck, so can definitely be golfed.. Based on the Python answer in the "I double the source, you double the output!" challenge.
Chunk length 53.
Try it online or try it online doubled.
edited 15 hours ago
answered 15 hours ago
Kevin CruijssenKevin Cruijssen
50.7k7 gold badges85 silver badges247 bronze badges
50.7k7 gold badges85 silver badges247 bronze badges
add a comment |
add a comment |
$begingroup$
Java 8, 62 bytes
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
Chunk length 62.
Try it online or try it online doubled.
Explanation:
n-> // Method with integer as both parameter and return-type
n* // The input, multiplied by:
(Byte.SIZE>8? // If Byte.SIZE is larger than 8:
n // Multiply by the input itself
: // Else:
2); // Multiply by 2
class Byte // Class which overwrites Byte
static int SIZE=9; // And sets the SIZE to 9
In Java, the available comments are // comment
and /* comment */
. Which are combined here to overwrite certain parts. See how these comments work thanks to the Java highlighting:
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
The doubled program created a custom Byte
class and its value SIZE=9
, which overwrites the default java.lang.Byte
class and its value SIZE=8
.
$endgroup$
add a comment |
$begingroup$
Java 8, 62 bytes
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
Chunk length 62.
Try it online or try it online doubled.
Explanation:
n-> // Method with integer as both parameter and return-type
n* // The input, multiplied by:
(Byte.SIZE>8? // If Byte.SIZE is larger than 8:
n // Multiply by the input itself
: // Else:
2); // Multiply by 2
class Byte // Class which overwrites Byte
static int SIZE=9; // And sets the SIZE to 9
In Java, the available comments are // comment
and /* comment */
. Which are combined here to overwrite certain parts. See how these comments work thanks to the Java highlighting:
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
The doubled program created a custom Byte
class and its value SIZE=9
, which overwrites the default java.lang.Byte
class and its value SIZE=8
.
$endgroup$
add a comment |
$begingroup$
Java 8, 62 bytes
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
Chunk length 62.
Try it online or try it online doubled.
Explanation:
n-> // Method with integer as both parameter and return-type
n* // The input, multiplied by:
(Byte.SIZE>8? // If Byte.SIZE is larger than 8:
n // Multiply by the input itself
: // Else:
2); // Multiply by 2
class Byte // Class which overwrites Byte
static int SIZE=9; // And sets the SIZE to 9
In Java, the available comments are // comment
and /* comment */
. Which are combined here to overwrite certain parts. See how these comments work thanks to the Java highlighting:
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
The doubled program created a custom Byte
class and its value SIZE=9
, which overwrites the default java.lang.Byte
class and its value SIZE=8
.
$endgroup$
Java 8, 62 bytes
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
Chunk length 62.
Try it online or try it online doubled.
Explanation:
n-> // Method with integer as both parameter and return-type
n* // The input, multiplied by:
(Byte.SIZE>8? // If Byte.SIZE is larger than 8:
n // Multiply by the input itself
: // Else:
2); // Multiply by 2
class Byte // Class which overwrites Byte
static int SIZE=9; // And sets the SIZE to 9
In Java, the available comments are // comment
and /* comment */
. Which are combined here to overwrite certain parts. See how these comments work thanks to the Java highlighting:
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///n->n*(Byte.SIZE>8?n:2);/*
class Bytestatic int SIZE=9;/**///
The doubled program created a custom Byte
class and its value SIZE=9
, which overwrites the default java.lang.Byte
class and its value SIZE=8
.
edited 14 hours ago
answered 14 hours ago
Kevin CruijssenKevin Cruijssen
50.7k7 gold badges85 silver badges247 bronze badges
50.7k7 gold badges85 silver badges247 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 8 6 bytes (chunk length 3)
Ḥ;²3ị
Try it online!
Doubled
$endgroup$
add a comment |
$begingroup$
Jelly, 8 6 bytes (chunk length 3)
Ḥ;²3ị
Try it online!
Doubled
$endgroup$
add a comment |
$begingroup$
Jelly, 8 6 bytes (chunk length 3)
Ḥ;²3ị
Try it online!
Doubled
$endgroup$
Jelly, 8 6 bytes (chunk length 3)
Ḥ;²3ị
Try it online!
Doubled
edited 7 hours ago
answered 8 hours ago
Nick KennedyNick Kennedy
6,4851 gold badge9 silver badges15 bronze badges
6,4851 gold badge9 silver badges15 bronze badges
add a comment |
add a comment |
$begingroup$
J, 17 bytes
*:@[`(+:@[)@.(=~)
Try it online!
Doubled version: Try it online!
In the single version, we have a single verb which uses Agenda @.
to do the if... then logic: If the argument is equal to itself =~
, then take the argument and double it (+:@[)
.
However, when we double the code, we get a J hook. Call the verb f
and the input y
. Then the hook f f
executes like this:
y f (f y)
Which means that now the original input is the left arg, and the right arg is the doubled input. Since these will not be equal, =~
will return false this time, and now we'll execute the other fork of the Agenda, ie, *:@[
, which means "square the left arg." And since that's the original input, we have what we need.
$endgroup$
add a comment |
$begingroup$
J, 17 bytes
*:@[`(+:@[)@.(=~)
Try it online!
Doubled version: Try it online!
In the single version, we have a single verb which uses Agenda @.
to do the if... then logic: If the argument is equal to itself =~
, then take the argument and double it (+:@[)
.
However, when we double the code, we get a J hook. Call the verb f
and the input y
. Then the hook f f
executes like this:
y f (f y)
Which means that now the original input is the left arg, and the right arg is the doubled input. Since these will not be equal, =~
will return false this time, and now we'll execute the other fork of the Agenda, ie, *:@[
, which means "square the left arg." And since that's the original input, we have what we need.
$endgroup$
add a comment |
$begingroup$
J, 17 bytes
*:@[`(+:@[)@.(=~)
Try it online!
Doubled version: Try it online!
In the single version, we have a single verb which uses Agenda @.
to do the if... then logic: If the argument is equal to itself =~
, then take the argument and double it (+:@[)
.
However, when we double the code, we get a J hook. Call the verb f
and the input y
. Then the hook f f
executes like this:
y f (f y)
Which means that now the original input is the left arg, and the right arg is the doubled input. Since these will not be equal, =~
will return false this time, and now we'll execute the other fork of the Agenda, ie, *:@[
, which means "square the left arg." And since that's the original input, we have what we need.
$endgroup$
J, 17 bytes
*:@[`(+:@[)@.(=~)
Try it online!
Doubled version: Try it online!
In the single version, we have a single verb which uses Agenda @.
to do the if... then logic: If the argument is equal to itself =~
, then take the argument and double it (+:@[)
.
However, when we double the code, we get a J hook. Call the verb f
and the input y
. Then the hook f f
executes like this:
y f (f y)
Which means that now the original input is the left arg, and the right arg is the doubled input. Since these will not be equal, =~
will return false this time, and now we'll execute the other fork of the Agenda, ie, *:@[
, which means "square the left arg." And since that's the original input, we have what we need.
answered 1 hour ago
JonahJonah
4,7222 gold badges12 silver badges22 bronze badges
4,7222 gold badges12 silver badges22 bronze badges
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f191580%2fdouble-it-your-way%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
@Arnauld okay, I undid that. I like the smaller-chunk solutions, but I'll leave the criteria as it is.
$endgroup$
– GammaFunction
11 hours ago