60
1
We have some new sheriffs moderators in town, Mego and DJMcMayhem. We need a challenge to properly honour them for their new positions, so there we go.
Here's something that has caught my attention when hovering over their profiles – their user IDs are \$31716\$ and \$45941\$. If you perform digit-wise subtraction, you'll notice something pretty exciting (of course, taking the absolute differences):
3|1|7|1|6
4|5|9|4|1
-+-+-+-+- (-)
1|4|2|3|5
The number generated by the above algorithm is \$14235\$. There is something special about this integer: It consists of consecutive digits only, sorted in ascending order, but exactly one of the digits is not placed correctly — \$4\$.
We will call a pair of positive integers \$(a, b)\$ a DJMcMego pair if the digit-wise absolute differences are consecutive integers, sorted in ascending order, but exactly one of them is not where it belongs. That is, it is possible to move exactly one digit of the result of digit-wise subtraction to another position, such that the integer obtained only has consecutive digits, sorted in ascending order.
In our example above, the pair \$(31716, 45941)\$ is a DJMcMego pair, because if \$4\$ is moved between \$3\$ and \$5\$, the result is \$12345\$, which fulfils the criteria. Note that the digits of the resulting number do not need to start at \$1\$, they just ought to be consecutive. When one is unsure about what decision they should make, they can always rely on the other's help to sort things out.
Your task is to output a truthy/falsy value depending on whether a pair of positive integers given as input is a DJMcMego pair.
You are guaranteed that \$a\$ and \$b\$ will have the same number of digits, always at least 4.
You can take the integers in any reasonable format (i.e. native integers, strings, lists of digits, etc.)
You can compete in any programming language and can take input and provide output through any standard method, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (in bytes) for every language wins.
Test cases
a, b -> Output
31716, 45941 -> Truthy
12354, 11111 -> Truthy
56798, 22222 -> Truthy
23564, 11111 -> Truthy
1759, 2435 -> Truthy
12345, 11111 -> Falsy
3333, 2101 -> Falsy
22354, 22222 -> Falsy
31717, 45941 -> Falsy
14325, 11111 -> Falsy
89789, 78865 -> Falsy
14954, 61713 -> Falsy
25631, 11114 -> Falsy
Or, in another format.
Can we output truthy for non-DJMcMego pairs and falsy for DJMcMego pairs? Also do the truthy/falsy values need to be consistent? – dylnan – 2018-02-23T00:20:17.430
Mego can have my upvote if he writes a solution in Actually. – SIGSTACKFAULT – 2018-02-23T00:53:38.530
6
@Blacksilver I think I've beaten him to it :P
– James – 2018-02-23T01:04:26.273@dylnan 1) They do not have to be from 1 to n, they just have to be consecutive. The test cases already cover that. 2) Swapping the truthy / falsy values is allowed by default 3) The truthy/ falsy values need not to be consistent by default. – Mr. Xcoder – 2018-02-23T06:05:26.493
2@Mr.Xcoder "Swapping the truthy / falsy values is allowed by default" Is that actually a thing? – Martin Ender – 2018-02-23T08:46:14.890
@MartinEnder I lost the count of *Returns False if the input is an X number, True otherwise* I've seen so far. Yes I believe it is allowed, otherwise I'm going to allow it for this challenge anyway – Mr. Xcoder – 2018-02-23T08:50:26.720
2@Mr.Xcoder Sure, many challenges allow it, but saying "it's allowed by default" implies to me that there's a meta post about it somewhere. – Martin Ender – 2018-02-23T08:51:05.120
@MartinEnder I do think there is a meta post about it. I'll try searching for it shortly, and if I don't find anything, I'll just ask myself. – Mr. Xcoder – 2018-02-23T08:52:01.523
Could we output one consistent value for
true
and a different but inconsistent value forfalse
? For example,1
fortrue
and any other number forfalse
. – Shaggy – 2018-02-23T10:18:06.883@Shaggy Your output must satisfy the standard definition of truthy / falsy. If all other numbers except for
– Mr. Xcoder – 2018-02-23T10:23:20.0201
are falsy in your language (i.e. in 05AB1E, only1
is truthy), then that is allowed. If that's not the case, I am afraid that's not allowed (that would disadvantage the existing answers). So you need to include==1
or a variation thereof in your byte count :)MegoMayhem
pairs hehehe...Me Go Mayhem
. – Magic Octopus Urn – 2018-02-23T13:59:38.030@Mr.Xcoder (1) may have been covered in the examples but it wasn't clear from the challenge specifications. I've had a challenge closed for that before. Not saying this challenge should have been closed I just think all specs should be written explicitly. – dylnan – 2018-02-23T17:11:21.040
1Maybe add
25631, 11114
as example. The differences are14523
which confuses several of the current programs – Ton Hospel – 2018-02-27T15:27:58.230Please add 14325, 11111 as a test case. – Dennis – 2018-06-10T20:12:28.330
What you're doing is similar to Ramanujan's "taxicab numbers": he was able to find an interesting property (the smallest number expressible as two cubes in multiple ways) in coincidental data (his taxicab number, 1729). Strangely enough, the OEIS sequence number for the taxicab numbers is 1235, which looks almost like one of these sequences :P
– Esolanging Fruit – 2018-06-11T06:05:15.763