Make them sum to 10,000
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
We've recently reached the threshold of 10,000 questions on PPCG. Hooray! Let's celebrate this with a simple challenge.
Input
Two integers $A$ and $B$, both in $[1..9999]$, such that $A+B<10000$.
Task
Your task is to add one single digit to one these integers or one single digit to both of them such that $A+B=10000$.
The new digit can be added at the beginning, at the end or anywhere in the middle of the original integer. However, you can't add a leading zero.
Example:
For $A=923$, the following transformations are valid:
$$colorred1923\92colorred73\923colorred8$$
But these ones are invalid:
$$colorred0923\colorred10923\9colorred42colorred73$$
Given $A=923$ and $B=72$, there are two possible solutions:
$$923colorred8 + 7colorred62 = 10000\92colorred73 + 72colorred7 = 10000$$
Output
You must print or output a list of all possible solutions.
For the above example, the expected output would be [[9238,762],[9273,727]]
.
Rules
- I/O can be processed in any reasonable, unambiguous format. You may use strings, lists of digits, etc. instead of integers.
- The input is guaranteed to have at least one solution.
- You are allowed not to deduplicate the output. However, it would be appreciated if the test code is deduplicating it with some post-processing, for instance in the footer section of TIO.
- This is a code-golf challenge.
Test cases
Input --> Output
934, 654 --> [[9346,654]]
737, 628 --> [[7372,2628]]
9122, 88 --> [[9122,878]]
923, 72 --> [[9238,762],[9273,727]]
998, 3 --> [[9968,32],[9987,13]]
363, 632 --> [[3673,6327],[3638,6362]]
288, 711 --> [[2881,7119],[2882,7118],[2883,7117],[2884,7116],[2885,7115],[2886,7114],
[2887,7113],[2888,7112],[2889,7111]]
365, 635 --> [[365,9635],[1365,8635],[2365,7635],[3365,6635],[4365,5635],[5365,4635],
[6365,3635],[7365,2635],[8365,1635],[9365,635],[3065,6935],[3165,6835],
[3265,6735],[3465,6535],[3565,6435],[3665,6335],[3765,6235],[3865,6135],
[3965,6035],[3605,6395],[3615,6385],[3625,6375],[3635,6365],[3645,6355],
[3655,6345],[3675,6325],[3685,6315],[3695,6305],[3650,6350]]
code-golf integer
add a comment |Â
up vote
6
down vote
favorite
We've recently reached the threshold of 10,000 questions on PPCG. Hooray! Let's celebrate this with a simple challenge.
Input
Two integers $A$ and $B$, both in $[1..9999]$, such that $A+B<10000$.
Task
Your task is to add one single digit to one these integers or one single digit to both of them such that $A+B=10000$.
The new digit can be added at the beginning, at the end or anywhere in the middle of the original integer. However, you can't add a leading zero.
Example:
For $A=923$, the following transformations are valid:
$$colorred1923\92colorred73\923colorred8$$
But these ones are invalid:
$$colorred0923\colorred10923\9colorred42colorred73$$
Given $A=923$ and $B=72$, there are two possible solutions:
$$923colorred8 + 7colorred62 = 10000\92colorred73 + 72colorred7 = 10000$$
Output
You must print or output a list of all possible solutions.
For the above example, the expected output would be [[9238,762],[9273,727]]
.
Rules
- I/O can be processed in any reasonable, unambiguous format. You may use strings, lists of digits, etc. instead of integers.
- The input is guaranteed to have at least one solution.
- You are allowed not to deduplicate the output. However, it would be appreciated if the test code is deduplicating it with some post-processing, for instance in the footer section of TIO.
- This is a code-golf challenge.
Test cases
Input --> Output
934, 654 --> [[9346,654]]
737, 628 --> [[7372,2628]]
9122, 88 --> [[9122,878]]
923, 72 --> [[9238,762],[9273,727]]
998, 3 --> [[9968,32],[9987,13]]
363, 632 --> [[3673,6327],[3638,6362]]
288, 711 --> [[2881,7119],[2882,7118],[2883,7117],[2884,7116],[2885,7115],[2886,7114],
[2887,7113],[2888,7112],[2889,7111]]
365, 635 --> [[365,9635],[1365,8635],[2365,7635],[3365,6635],[4365,5635],[5365,4635],
[6365,3635],[7365,2635],[8365,1635],[9365,635],[3065,6935],[3165,6835],
[3265,6735],[3465,6535],[3565,6435],[3665,6335],[3765,6235],[3865,6135],
[3965,6035],[3605,6395],[3615,6385],[3625,6375],[3635,6365],[3645,6355],
[3655,6345],[3675,6325],[3685,6315],[3695,6305],[3650,6350]]
code-golf integer
ItâÂÂs not a simple challenge if I canâÂÂt type it out and be confident it works while in my car. ;p
â Quintec
1 hour ago
1
@Quintec I'd recommend against typing anything while you're in your car. :p
â Arnauld
1 hour ago
@Arnauld He didn't say he's the driver. ;-) (Serious note: 4 off-topic comments so far, my 3-comment handicap for those purposes is beeping loudly. :P)
â Erik the Outgolfer
1 hour ago
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
We've recently reached the threshold of 10,000 questions on PPCG. Hooray! Let's celebrate this with a simple challenge.
Input
Two integers $A$ and $B$, both in $[1..9999]$, such that $A+B<10000$.
Task
Your task is to add one single digit to one these integers or one single digit to both of them such that $A+B=10000$.
The new digit can be added at the beginning, at the end or anywhere in the middle of the original integer. However, you can't add a leading zero.
Example:
For $A=923$, the following transformations are valid:
$$colorred1923\92colorred73\923colorred8$$
But these ones are invalid:
$$colorred0923\colorred10923\9colorred42colorred73$$
Given $A=923$ and $B=72$, there are two possible solutions:
$$923colorred8 + 7colorred62 = 10000\92colorred73 + 72colorred7 = 10000$$
Output
You must print or output a list of all possible solutions.
For the above example, the expected output would be [[9238,762],[9273,727]]
.
Rules
- I/O can be processed in any reasonable, unambiguous format. You may use strings, lists of digits, etc. instead of integers.
- The input is guaranteed to have at least one solution.
- You are allowed not to deduplicate the output. However, it would be appreciated if the test code is deduplicating it with some post-processing, for instance in the footer section of TIO.
- This is a code-golf challenge.
Test cases
Input --> Output
934, 654 --> [[9346,654]]
737, 628 --> [[7372,2628]]
9122, 88 --> [[9122,878]]
923, 72 --> [[9238,762],[9273,727]]
998, 3 --> [[9968,32],[9987,13]]
363, 632 --> [[3673,6327],[3638,6362]]
288, 711 --> [[2881,7119],[2882,7118],[2883,7117],[2884,7116],[2885,7115],[2886,7114],
[2887,7113],[2888,7112],[2889,7111]]
365, 635 --> [[365,9635],[1365,8635],[2365,7635],[3365,6635],[4365,5635],[5365,4635],
[6365,3635],[7365,2635],[8365,1635],[9365,635],[3065,6935],[3165,6835],
[3265,6735],[3465,6535],[3565,6435],[3665,6335],[3765,6235],[3865,6135],
[3965,6035],[3605,6395],[3615,6385],[3625,6375],[3635,6365],[3645,6355],
[3655,6345],[3675,6325],[3685,6315],[3695,6305],[3650,6350]]
code-golf integer
We've recently reached the threshold of 10,000 questions on PPCG. Hooray! Let's celebrate this with a simple challenge.
Input
Two integers $A$ and $B$, both in $[1..9999]$, such that $A+B<10000$.
Task
Your task is to add one single digit to one these integers or one single digit to both of them such that $A+B=10000$.
The new digit can be added at the beginning, at the end or anywhere in the middle of the original integer. However, you can't add a leading zero.
Example:
For $A=923$, the following transformations are valid:
$$colorred1923\92colorred73\923colorred8$$
But these ones are invalid:
$$colorred0923\colorred10923\9colorred42colorred73$$
Given $A=923$ and $B=72$, there are two possible solutions:
$$923colorred8 + 7colorred62 = 10000\92colorred73 + 72colorred7 = 10000$$
Output
You must print or output a list of all possible solutions.
For the above example, the expected output would be [[9238,762],[9273,727]]
.
Rules
- I/O can be processed in any reasonable, unambiguous format. You may use strings, lists of digits, etc. instead of integers.
- The input is guaranteed to have at least one solution.
- You are allowed not to deduplicate the output. However, it would be appreciated if the test code is deduplicating it with some post-processing, for instance in the footer section of TIO.
- This is a code-golf challenge.
Test cases
Input --> Output
934, 654 --> [[9346,654]]
737, 628 --> [[7372,2628]]
9122, 88 --> [[9122,878]]
923, 72 --> [[9238,762],[9273,727]]
998, 3 --> [[9968,32],[9987,13]]
363, 632 --> [[3673,6327],[3638,6362]]
288, 711 --> [[2881,7119],[2882,7118],[2883,7117],[2884,7116],[2885,7115],[2886,7114],
[2887,7113],[2888,7112],[2889,7111]]
365, 635 --> [[365,9635],[1365,8635],[2365,7635],[3365,6635],[4365,5635],[5365,4635],
[6365,3635],[7365,2635],[8365,1635],[9365,635],[3065,6935],[3165,6835],
[3265,6735],[3465,6535],[3565,6435],[3665,6335],[3765,6235],[3865,6135],
[3965,6035],[3605,6395],[3615,6385],[3625,6375],[3635,6365],[3645,6355],
[3655,6345],[3675,6325],[3685,6315],[3695,6305],[3650,6350]]
code-golf integer
code-golf integer
edited 1 hour ago
asked 1 hour ago
Arnauld
65.3k581275
65.3k581275
ItâÂÂs not a simple challenge if I canâÂÂt type it out and be confident it works while in my car. ;p
â Quintec
1 hour ago
1
@Quintec I'd recommend against typing anything while you're in your car. :p
â Arnauld
1 hour ago
@Arnauld He didn't say he's the driver. ;-) (Serious note: 4 off-topic comments so far, my 3-comment handicap for those purposes is beeping loudly. :P)
â Erik the Outgolfer
1 hour ago
add a comment |Â
ItâÂÂs not a simple challenge if I canâÂÂt type it out and be confident it works while in my car. ;p
â Quintec
1 hour ago
1
@Quintec I'd recommend against typing anything while you're in your car. :p
â Arnauld
1 hour ago
@Arnauld He didn't say he's the driver. ;-) (Serious note: 4 off-topic comments so far, my 3-comment handicap for those purposes is beeping loudly. :P)
â Erik the Outgolfer
1 hour ago
ItâÂÂs not a simple challenge if I canâÂÂt type it out and be confident it works while in my car. ;p
â Quintec
1 hour ago
ItâÂÂs not a simple challenge if I canâÂÂt type it out and be confident it works while in my car. ;p
â Quintec
1 hour ago
1
1
@Quintec I'd recommend against typing anything while you're in your car. :p
â Arnauld
1 hour ago
@Quintec I'd recommend against typing anything while you're in your car. :p
â Arnauld
1 hour ago
@Arnauld He didn't say he's the driver. ;-) (Serious note: 4 off-topic comments so far, my 3-comment handicap for those purposes is beeping loudly. :P)
â Erik the Outgolfer
1 hour ago
@Arnauld He didn't say he's the driver. ;-) (Serious note: 4 off-topic comments so far, my 3-comment handicap for those purposes is beeping loudly. :P)
â Erik the Outgolfer
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
Pyth, 28 27 25 bytes
fq10000+FT*FmvMsmXLkdUThl
Try it online here, or verify all the test cases here - the test suite deduplicates the result by prepending a {
.
Input is as a list of strings.
fq10000+FT*FmvMsmXLkdUThldQ Implicit: Q=eval(input()), T=10
Trailing d, Q inferred
m Q Map each input string, as d, using:
ld Take the length of d
m h Map 0 to the above (inclusive), as k, using:
X d Insert into d...
k ... at position k...
L UT ... each number [0-9]
s Flatten the result
vM Convert each back to an integer
*F Take the cartesian product of the result
(this generates all possible pairs of mutated numbers)
f Keep the pairs, as T, where...
+FT ... the sum of the pair...
q10000 ... is equal to 10,000
If input as a list of strings isn't allowed, my previous 27-byte solution performs string conversions manually:
fq10000+FT*FmvMsmXLk`dUThl`
Try it online here.
Am I wrong, or does your program allow adding leading zeros (which is forbidden in the challenge statement)?
â Delfad0r
50 mins ago
I don't know Pyth too well, but if it has a builtin for 10 and**
, can't you do something like10**4
instead of the literal10000
?
â Kevin Cruijssen
50 mins ago
1
@KevinCruijssen it does indeed, 10 is usuallyT
, but in function blocks the variables are re-purposed to act as iteration variables instead - in the filter block the iteration variable just so happens to beT
, so it can't be used. This means that10 ^ 4
would be^10 4
, which is 5 bytes long, so no shorter unfortunately
â Sok
44 mins ago
@Delfad0r It's OK to add leading zeros while processing the answer, as long as they don't appear in the output. (Since the strings are converted back to integers, that's fine.)
â Arnauld
44 mins ago
1
@Sok Ah ok. So theT
inUT
is still 10, for the[0,10)
range. But atf...T
theT
has become an iteration variable for the filter. Thanks for the explanation, that makes sense! And doingT4^
earlier, saving it in a variable, and using that variable in the filter is (at least) 5 bytes as well of course.
â Kevin Cruijssen
36 mins ago
 |Â
show 2 more comments
up vote
1
down vote
Perl 6, 127 bytes
$^a;$^b;grep .[0]+.[1]==1e4&&all map 2>$^d.comb-$^c.comb&&~$câÂÂ$d.comb.combinations>>.join,$a,.[0],$b,.[1],[X] ^1e4,^1e4
Try it online!
Super long brute force method (which can definitely be golfed). To prove it actually works, here's a version for numbers adding up to 1000 instead. Try it online!
Rather than fiddle about with inserting the digits in, this solution checks every combination of numbers that sum to 10000 and filters that the given numbers are part of the pair. Unfortunately, that means it testing 10000*10000
possible pairs and takes a rather long time to complete.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Pyth, 28 27 25 bytes
fq10000+FT*FmvMsmXLkdUThl
Try it online here, or verify all the test cases here - the test suite deduplicates the result by prepending a {
.
Input is as a list of strings.
fq10000+FT*FmvMsmXLkdUThldQ Implicit: Q=eval(input()), T=10
Trailing d, Q inferred
m Q Map each input string, as d, using:
ld Take the length of d
m h Map 0 to the above (inclusive), as k, using:
X d Insert into d...
k ... at position k...
L UT ... each number [0-9]
s Flatten the result
vM Convert each back to an integer
*F Take the cartesian product of the result
(this generates all possible pairs of mutated numbers)
f Keep the pairs, as T, where...
+FT ... the sum of the pair...
q10000 ... is equal to 10,000
If input as a list of strings isn't allowed, my previous 27-byte solution performs string conversions manually:
fq10000+FT*FmvMsmXLk`dUThl`
Try it online here.
Am I wrong, or does your program allow adding leading zeros (which is forbidden in the challenge statement)?
â Delfad0r
50 mins ago
I don't know Pyth too well, but if it has a builtin for 10 and**
, can't you do something like10**4
instead of the literal10000
?
â Kevin Cruijssen
50 mins ago
1
@KevinCruijssen it does indeed, 10 is usuallyT
, but in function blocks the variables are re-purposed to act as iteration variables instead - in the filter block the iteration variable just so happens to beT
, so it can't be used. This means that10 ^ 4
would be^10 4
, which is 5 bytes long, so no shorter unfortunately
â Sok
44 mins ago
@Delfad0r It's OK to add leading zeros while processing the answer, as long as they don't appear in the output. (Since the strings are converted back to integers, that's fine.)
â Arnauld
44 mins ago
1
@Sok Ah ok. So theT
inUT
is still 10, for the[0,10)
range. But atf...T
theT
has become an iteration variable for the filter. Thanks for the explanation, that makes sense! And doingT4^
earlier, saving it in a variable, and using that variable in the filter is (at least) 5 bytes as well of course.
â Kevin Cruijssen
36 mins ago
 |Â
show 2 more comments
up vote
4
down vote
Pyth, 28 27 25 bytes
fq10000+FT*FmvMsmXLkdUThl
Try it online here, or verify all the test cases here - the test suite deduplicates the result by prepending a {
.
Input is as a list of strings.
fq10000+FT*FmvMsmXLkdUThldQ Implicit: Q=eval(input()), T=10
Trailing d, Q inferred
m Q Map each input string, as d, using:
ld Take the length of d
m h Map 0 to the above (inclusive), as k, using:
X d Insert into d...
k ... at position k...
L UT ... each number [0-9]
s Flatten the result
vM Convert each back to an integer
*F Take the cartesian product of the result
(this generates all possible pairs of mutated numbers)
f Keep the pairs, as T, where...
+FT ... the sum of the pair...
q10000 ... is equal to 10,000
If input as a list of strings isn't allowed, my previous 27-byte solution performs string conversions manually:
fq10000+FT*FmvMsmXLk`dUThl`
Try it online here.
Am I wrong, or does your program allow adding leading zeros (which is forbidden in the challenge statement)?
â Delfad0r
50 mins ago
I don't know Pyth too well, but if it has a builtin for 10 and**
, can't you do something like10**4
instead of the literal10000
?
â Kevin Cruijssen
50 mins ago
1
@KevinCruijssen it does indeed, 10 is usuallyT
, but in function blocks the variables are re-purposed to act as iteration variables instead - in the filter block the iteration variable just so happens to beT
, so it can't be used. This means that10 ^ 4
would be^10 4
, which is 5 bytes long, so no shorter unfortunately
â Sok
44 mins ago
@Delfad0r It's OK to add leading zeros while processing the answer, as long as they don't appear in the output. (Since the strings are converted back to integers, that's fine.)
â Arnauld
44 mins ago
1
@Sok Ah ok. So theT
inUT
is still 10, for the[0,10)
range. But atf...T
theT
has become an iteration variable for the filter. Thanks for the explanation, that makes sense! And doingT4^
earlier, saving it in a variable, and using that variable in the filter is (at least) 5 bytes as well of course.
â Kevin Cruijssen
36 mins ago
 |Â
show 2 more comments
up vote
4
down vote
up vote
4
down vote
Pyth, 28 27 25 bytes
fq10000+FT*FmvMsmXLkdUThl
Try it online here, or verify all the test cases here - the test suite deduplicates the result by prepending a {
.
Input is as a list of strings.
fq10000+FT*FmvMsmXLkdUThldQ Implicit: Q=eval(input()), T=10
Trailing d, Q inferred
m Q Map each input string, as d, using:
ld Take the length of d
m h Map 0 to the above (inclusive), as k, using:
X d Insert into d...
k ... at position k...
L UT ... each number [0-9]
s Flatten the result
vM Convert each back to an integer
*F Take the cartesian product of the result
(this generates all possible pairs of mutated numbers)
f Keep the pairs, as T, where...
+FT ... the sum of the pair...
q10000 ... is equal to 10,000
If input as a list of strings isn't allowed, my previous 27-byte solution performs string conversions manually:
fq10000+FT*FmvMsmXLk`dUThl`
Try it online here.
Pyth, 28 27 25 bytes
fq10000+FT*FmvMsmXLkdUThl
Try it online here, or verify all the test cases here - the test suite deduplicates the result by prepending a {
.
Input is as a list of strings.
fq10000+FT*FmvMsmXLkdUThldQ Implicit: Q=eval(input()), T=10
Trailing d, Q inferred
m Q Map each input string, as d, using:
ld Take the length of d
m h Map 0 to the above (inclusive), as k, using:
X d Insert into d...
k ... at position k...
L UT ... each number [0-9]
s Flatten the result
vM Convert each back to an integer
*F Take the cartesian product of the result
(this generates all possible pairs of mutated numbers)
f Keep the pairs, as T, where...
+FT ... the sum of the pair...
q10000 ... is equal to 10,000
If input as a list of strings isn't allowed, my previous 27-byte solution performs string conversions manually:
fq10000+FT*FmvMsmXLk`dUThl`
Try it online here.
edited 28 mins ago
answered 55 mins ago
Sok
2,991722
2,991722
Am I wrong, or does your program allow adding leading zeros (which is forbidden in the challenge statement)?
â Delfad0r
50 mins ago
I don't know Pyth too well, but if it has a builtin for 10 and**
, can't you do something like10**4
instead of the literal10000
?
â Kevin Cruijssen
50 mins ago
1
@KevinCruijssen it does indeed, 10 is usuallyT
, but in function blocks the variables are re-purposed to act as iteration variables instead - in the filter block the iteration variable just so happens to beT
, so it can't be used. This means that10 ^ 4
would be^10 4
, which is 5 bytes long, so no shorter unfortunately
â Sok
44 mins ago
@Delfad0r It's OK to add leading zeros while processing the answer, as long as they don't appear in the output. (Since the strings are converted back to integers, that's fine.)
â Arnauld
44 mins ago
1
@Sok Ah ok. So theT
inUT
is still 10, for the[0,10)
range. But atf...T
theT
has become an iteration variable for the filter. Thanks for the explanation, that makes sense! And doingT4^
earlier, saving it in a variable, and using that variable in the filter is (at least) 5 bytes as well of course.
â Kevin Cruijssen
36 mins ago
 |Â
show 2 more comments
Am I wrong, or does your program allow adding leading zeros (which is forbidden in the challenge statement)?
â Delfad0r
50 mins ago
I don't know Pyth too well, but if it has a builtin for 10 and**
, can't you do something like10**4
instead of the literal10000
?
â Kevin Cruijssen
50 mins ago
1
@KevinCruijssen it does indeed, 10 is usuallyT
, but in function blocks the variables are re-purposed to act as iteration variables instead - in the filter block the iteration variable just so happens to beT
, so it can't be used. This means that10 ^ 4
would be^10 4
, which is 5 bytes long, so no shorter unfortunately
â Sok
44 mins ago
@Delfad0r It's OK to add leading zeros while processing the answer, as long as they don't appear in the output. (Since the strings are converted back to integers, that's fine.)
â Arnauld
44 mins ago
1
@Sok Ah ok. So theT
inUT
is still 10, for the[0,10)
range. But atf...T
theT
has become an iteration variable for the filter. Thanks for the explanation, that makes sense! And doingT4^
earlier, saving it in a variable, and using that variable in the filter is (at least) 5 bytes as well of course.
â Kevin Cruijssen
36 mins ago
Am I wrong, or does your program allow adding leading zeros (which is forbidden in the challenge statement)?
â Delfad0r
50 mins ago
Am I wrong, or does your program allow adding leading zeros (which is forbidden in the challenge statement)?
â Delfad0r
50 mins ago
I don't know Pyth too well, but if it has a builtin for 10 and
**
, can't you do something like 10**4
instead of the literal 10000
?â Kevin Cruijssen
50 mins ago
I don't know Pyth too well, but if it has a builtin for 10 and
**
, can't you do something like 10**4
instead of the literal 10000
?â Kevin Cruijssen
50 mins ago
1
1
@KevinCruijssen it does indeed, 10 is usually
T
, but in function blocks the variables are re-purposed to act as iteration variables instead - in the filter block the iteration variable just so happens to be T
, so it can't be used. This means that 10 ^ 4
would be ^10 4
, which is 5 bytes long, so no shorter unfortunatelyâ Sok
44 mins ago
@KevinCruijssen it does indeed, 10 is usually
T
, but in function blocks the variables are re-purposed to act as iteration variables instead - in the filter block the iteration variable just so happens to be T
, so it can't be used. This means that 10 ^ 4
would be ^10 4
, which is 5 bytes long, so no shorter unfortunatelyâ Sok
44 mins ago
@Delfad0r It's OK to add leading zeros while processing the answer, as long as they don't appear in the output. (Since the strings are converted back to integers, that's fine.)
â Arnauld
44 mins ago
@Delfad0r It's OK to add leading zeros while processing the answer, as long as they don't appear in the output. (Since the strings are converted back to integers, that's fine.)
â Arnauld
44 mins ago
1
1
@Sok Ah ok. So the
T
in UT
is still 10, for the [0,10)
range. But at f...T
the T
has become an iteration variable for the filter. Thanks for the explanation, that makes sense! And doing T4^
earlier, saving it in a variable, and using that variable in the filter is (at least) 5 bytes as well of course.â Kevin Cruijssen
36 mins ago
@Sok Ah ok. So the
T
in UT
is still 10, for the [0,10)
range. But at f...T
the T
has become an iteration variable for the filter. Thanks for the explanation, that makes sense! And doing T4^
earlier, saving it in a variable, and using that variable in the filter is (at least) 5 bytes as well of course.â Kevin Cruijssen
36 mins ago
 |Â
show 2 more comments
up vote
1
down vote
Perl 6, 127 bytes
$^a;$^b;grep .[0]+.[1]==1e4&&all map 2>$^d.comb-$^c.comb&&~$câÂÂ$d.comb.combinations>>.join,$a,.[0],$b,.[1],[X] ^1e4,^1e4
Try it online!
Super long brute force method (which can definitely be golfed). To prove it actually works, here's a version for numbers adding up to 1000 instead. Try it online!
Rather than fiddle about with inserting the digits in, this solution checks every combination of numbers that sum to 10000 and filters that the given numbers are part of the pair. Unfortunately, that means it testing 10000*10000
possible pairs and takes a rather long time to complete.
add a comment |Â
up vote
1
down vote
Perl 6, 127 bytes
$^a;$^b;grep .[0]+.[1]==1e4&&all map 2>$^d.comb-$^c.comb&&~$câÂÂ$d.comb.combinations>>.join,$a,.[0],$b,.[1],[X] ^1e4,^1e4
Try it online!
Super long brute force method (which can definitely be golfed). To prove it actually works, here's a version for numbers adding up to 1000 instead. Try it online!
Rather than fiddle about with inserting the digits in, this solution checks every combination of numbers that sum to 10000 and filters that the given numbers are part of the pair. Unfortunately, that means it testing 10000*10000
possible pairs and takes a rather long time to complete.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Perl 6, 127 bytes
$^a;$^b;grep .[0]+.[1]==1e4&&all map 2>$^d.comb-$^c.comb&&~$câÂÂ$d.comb.combinations>>.join,$a,.[0],$b,.[1],[X] ^1e4,^1e4
Try it online!
Super long brute force method (which can definitely be golfed). To prove it actually works, here's a version for numbers adding up to 1000 instead. Try it online!
Rather than fiddle about with inserting the digits in, this solution checks every combination of numbers that sum to 10000 and filters that the given numbers are part of the pair. Unfortunately, that means it testing 10000*10000
possible pairs and takes a rather long time to complete.
Perl 6, 127 bytes
$^a;$^b;grep .[0]+.[1]==1e4&&all map 2>$^d.comb-$^c.comb&&~$câÂÂ$d.comb.combinations>>.join,$a,.[0],$b,.[1],[X] ^1e4,^1e4
Try it online!
Super long brute force method (which can definitely be golfed). To prove it actually works, here's a version for numbers adding up to 1000 instead. Try it online!
Rather than fiddle about with inserting the digits in, this solution checks every combination of numbers that sum to 10000 and filters that the given numbers are part of the pair. Unfortunately, that means it testing 10000*10000
possible pairs and takes a rather long time to complete.
edited 22 mins ago
answered 43 mins ago
Jo King
16.2k24189
16.2k24189
add a comment |Â
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%2f172985%2fmake-them-sum-to-10-000%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
ItâÂÂs not a simple challenge if I canâÂÂt type it out and be confident it works while in my car. ;p
â Quintec
1 hour ago
1
@Quintec I'd recommend against typing anything while you're in your car. :p
â Arnauld
1 hour ago
@Arnauld He didn't say he's the driver. ;-) (Serious note: 4 off-topic comments so far, my 3-comment handicap for those purposes is beeping loudly. :P)
â Erik the Outgolfer
1 hour ago