Jumping Numbers
$begingroup$
A jumping number is defined as a positive number n which all pairs of consecutive decimal digits differ by 1. Also, all single digit numbers are considered jumping numbers. eg. 3, 45676, 212 are jumping numbers but 414 and 13 are not. The difference between 9 and 0 is not considered as 1
The challenge
Create a program that output one of the following results:
- Given an input
noutput the firstnjumping numbers. - Given an input
noutput thenth term of the sequence.
Note
- Any valid I/O format is allowed
- 1-index or 0-index is allowed (please specify)
Here are some jumping numbers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98, 101, 121, 123, 210, 212, 232, 234, 321, 323, 343, 345, 432, 434, 454, 456, 543, 545, 565, 567, 654, 656, 676, 678, 765, 767, 787, 789, 876, ...
This is also A033075
code-golf number sequence
$endgroup$
add a comment |
$begingroup$
A jumping number is defined as a positive number n which all pairs of consecutive decimal digits differ by 1. Also, all single digit numbers are considered jumping numbers. eg. 3, 45676, 212 are jumping numbers but 414 and 13 are not. The difference between 9 and 0 is not considered as 1
The challenge
Create a program that output one of the following results:
- Given an input
noutput the firstnjumping numbers. - Given an input
noutput thenth term of the sequence.
Note
- Any valid I/O format is allowed
- 1-index or 0-index is allowed (please specify)
Here are some jumping numbers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98, 101, 121, 123, 210, 212, 232, 234, 321, 323, 343, 345, 432, 434, 454, 456, 543, 545, 565, 567, 654, 656, 676, 678, 765, 767, 787, 789, 876, ...
This is also A033075
code-golf number sequence
$endgroup$
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
Mar 1 at 17:19
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the inputnthen it is up to you.
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 17:20
$begingroup$
I'm guessing "Any valid I/O format is allowed" includes outputting the numbers as lists of decimal digits, but just wanted to confirm - ?
$endgroup$
– Jonathan Allan
Mar 1 at 18:04
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 18:27
add a comment |
$begingroup$
A jumping number is defined as a positive number n which all pairs of consecutive decimal digits differ by 1. Also, all single digit numbers are considered jumping numbers. eg. 3, 45676, 212 are jumping numbers but 414 and 13 are not. The difference between 9 and 0 is not considered as 1
The challenge
Create a program that output one of the following results:
- Given an input
noutput the firstnjumping numbers. - Given an input
noutput thenth term of the sequence.
Note
- Any valid I/O format is allowed
- 1-index or 0-index is allowed (please specify)
Here are some jumping numbers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98, 101, 121, 123, 210, 212, 232, 234, 321, 323, 343, 345, 432, 434, 454, 456, 543, 545, 565, 567, 654, 656, 676, 678, 765, 767, 787, 789, 876, ...
This is also A033075
code-golf number sequence
$endgroup$
A jumping number is defined as a positive number n which all pairs of consecutive decimal digits differ by 1. Also, all single digit numbers are considered jumping numbers. eg. 3, 45676, 212 are jumping numbers but 414 and 13 are not. The difference between 9 and 0 is not considered as 1
The challenge
Create a program that output one of the following results:
- Given an input
noutput the firstnjumping numbers. - Given an input
noutput thenth term of the sequence.
Note
- Any valid I/O format is allowed
- 1-index or 0-index is allowed (please specify)
Here are some jumping numbers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98, 101, 121, 123, 210, 212, 232, 234, 321, 323, 343, 345, 432, 434, 454, 456, 543, 545, 565, 567, 654, 656, 676, 678, 765, 767, 787, 789, 876, ...
This is also A033075
code-golf number sequence
code-golf number sequence
edited Mar 1 at 23:52
DLosc
19.4k33889
19.4k33889
asked Mar 1 at 17:11
Luis felipe De jesus MunozLuis felipe De jesus Munoz
5,57821670
5,57821670
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
Mar 1 at 17:19
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the inputnthen it is up to you.
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 17:20
$begingroup$
I'm guessing "Any valid I/O format is allowed" includes outputting the numbers as lists of decimal digits, but just wanted to confirm - ?
$endgroup$
– Jonathan Allan
Mar 1 at 18:04
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 18:27
add a comment |
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
Mar 1 at 17:19
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the inputnthen it is up to you.
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 17:20
$begingroup$
I'm guessing "Any valid I/O format is allowed" includes outputting the numbers as lists of decimal digits, but just wanted to confirm - ?
$endgroup$
– Jonathan Allan
Mar 1 at 18:04
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 18:27
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
Mar 1 at 17:19
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
Mar 1 at 17:19
1
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the input
n then it is up to you.$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 17:20
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the input
n then it is up to you.$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 17:20
$begingroup$
I'm guessing "Any valid I/O format is allowed" includes outputting the numbers as lists of decimal digits, but just wanted to confirm - ?
$endgroup$
– Jonathan Allan
Mar 1 at 18:04
$begingroup$
I'm guessing "Any valid I/O format is allowed" includes outputting the numbers as lists of decimal digits, but just wanted to confirm - ?
$endgroup$
– Jonathan Allan
Mar 1 at 18:04
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 18:27
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 18:27
add a comment |
18 Answers
18
active
oldest
votes
$begingroup$
Haskell, 57 bytes
(l!!)
l=[1..9]++[x*10+t|x<-l,t<-[0..9],(mod x 10-t)^2==1]
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1DI*`ƑƊ#
A full program accepting an integer, n, from STDIN which prints a list of the first n positive jumping numbers.
Try it online!
How?
Acceptable incremental differences between digits are 1 and -1 while others from [-9,-2]+[2,9] are not. This lines up with integers which are invariant when raised to themselves. i.e. $x^x=x$ since:
$$0^0=1$$
$$1^1=1$$
$$2^2=4$$
$$cdots$$
$$-1^{-1}=-1$$
$$-2^{-2}=-frac{1}{4}$$
$$cdots$$
1DI*`ƑƊ# - Main Link: no arguments (accepts a line of input from STDIN)
# - count up keeping the first (input) n matches...
1 - ...start with n equal to: 1
Ɗ - ...match function: last three links as a monad: e.g. 245 777 7656
D - convert to a list of decimal digits [2,4,5] [7,7,7] [7,6,5,6]
I - incremental differences [2,1] [0,0] [-1,-1,1]
Ƒ - invariant under?:
` - using left argument as both inputs of:
* - exponentiation (vectorises) [4,1] [1,1] [-1,-1,1]
- --so we: discard discard keep
- implicitly print the list of collected values of n
$endgroup$
add a comment |
$begingroup$
05AB1E (legacy), 5 bytes
The input is 1-indexed.
Code:
µN¥ÄP
Uses the 05AB1E encoding. Try it online!
Explanation
µ # Get the nth number, starting from 0, such that...
Ä # The absolute values
N¥ # Of the delta's of N
P # Are all 1 (product function, basically acts as a reduce by AND)
$endgroup$
$begingroup$
Right tool for the job.
$endgroup$
– lirtosiast
Mar 2 at 1:53
add a comment |
$begingroup$
Python 2, 79 75 bytes
-4 bytes by xnor
f=lambda n,i=1:n and-~f(n-g(i),i+1)
g=lambda i:i<10or i%100%11%9==g(i/10)>0
Try it online!
Derived from Chas Brown's answer. The helper function g(i) returns whether i is a jumping number. Iff the last two digits of a number n have absolute difference 1, then n%100%11 will be either 1 or 10, so n%100%11%9 will be 1.
$endgroup$
$begingroup$
Nice trick with the%11. You can dof=lambda n,i=1:n and-~f(n-g(i),i+1)if you switch to one-indexing.
$endgroup$
– xnor
Mar 2 at 5:01
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
1-indexed. Thanks to dzaima for their help with golfing this.
Edit: -15 bytes from ngn.
1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
Try it online!
Explanation
We have f⍣g⍣h, where, as ⍣ is an operator, APL translates this to (f⍣g)⍣h. (In contrast with functions where 2×3+1 is translated 2×(3+1))
1+⍣{...}⍣⎕⊢0 This is equivalent to
"do {check} we find the n-th integer that fulfils {check}"
1+⍣{...} ⊢0 Start with 0 and keep adding 1s until the dfn
(our jumping number check in {}) returns true.
⍣⎕ We take input n (⎕) and repeat (⍣) the above n times
to get the n-th jumping number.
{∧/1=|2-/⍎¨⍕⍺} The dfn that checks for jumping numbers.
⍎¨⍕⍺ We take the base-10 digits of our left argument
by evaluating each character of the string representation of ⍺.
|2-/ Then we take the absolute value of the pairwise differences of the digits
∧/1= and check if all of the differences are equal to 1.
$endgroup$
$begingroup$
10⊥⍣¯1⊢⍺->⍎¨⍕⍺
$endgroup$
– ngn
Mar 6 at 10:52
$begingroup$
it's much shorter with⍣instead of recursion:{1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⍵⊢0}or1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
$endgroup$
– ngn
Mar 6 at 11:05
$begingroup$
"⍣ is an operand" - it's an "operator" (i this mistake in chat and corrected it, but it seems you picked up the initial version. sorry)
$endgroup$
– ngn
Mar 6 at 18:53
add a comment |
$begingroup$
C (gcc), 90 bytes
f(n,K,b,k){for(K=0;n;b&&printf("%d,",K,n--))for(b=k=++K;k/10;)b*=abs(k%10-(k/=10)%10)==1;}
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 14 bytes
Outputs the first nth term, 1-indexed.
_ì äa dÉ ªU´}f
Try it
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$endgroup$
$begingroup$
Haha, maybe go learn a new golfing language to cure your withdrawal. :P
$endgroup$
– Quintec
Mar 1 at 20:09
add a comment |
$begingroup$
Python 2, 88 87 bytes
f=lambda n,i=2:n and f(n-g(i),i+1)or~-i
g=lambda i:i<10or abs(i/10%10-i%10)==1==g(i/10)
Try it online!
Returns the 0-indexed jumping number (i.e., f(0) => 1, etc).
$endgroup$
$begingroup$
@lirtosiast : That's OK, please donate your answer to your favorite charity :). It's sufficiently different to merit a separate response (as well as being cross-language appropriate).
$endgroup$
– Chas Brown
Mar 2 at 2:57
add a comment |
$begingroup$
Haskell, 69 bytes
- Thanks to Joseph Sible for enforcing the challenge rules and saving three bytes.
- Saved two bytes thanks to nimi.
(filter(all((==1).abs).(zipWith(-)<*>tail).map fromEnum.show)[1..]!!)
Try it online!
$endgroup$
1
$begingroup$
This appears to answer the question "is this a jumping number?" for a given input number, which isn't what the challenge asked for.
$endgroup$
– Joseph Sible
Mar 1 at 18:57
$begingroup$
@JosephSible You are correct. Thank you for noting.
$endgroup$
– Jonathan Frech
Mar 1 at 23:34
$begingroup$
Also, now that that's fixed, you can makeg3 bytes shorter by rewriting it to be pointfree, then using<*>:g=all((==1).abs).(zipWith(-)<*>tail).map(read.pure).show
$endgroup$
– Joseph Sible
Mar 2 at 4:02
$begingroup$
@JosephSible Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 4:19
$begingroup$
@nimi Done. Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 7:57
add a comment |
$begingroup$
JavaScript (ES7), 60 bytes
Returns the $n$th term of the sequence (1-indexed).
f=(n,k)=>[...k+''].some(p=x=>(p-(p=x))**2-1)||n--?f(n,-~k):k
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 9 bytes
-1 by Jonathan Allan
1DạƝ=1ẠƲ#
Try it online!
1-indexed.
$endgroup$
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
Mar 1 at 18:15
add a comment |
$begingroup$
Swift, 228 bytes
func j(n:Int){
var r:[Int]=
for x in 0...n{
if x<=10{r.append(x)}else{
let t=String(x).compactMap{Int(String($0))}
var b=true
for i in 1...t.count-1{if abs(t[i-1]-t[i]) != 1{b=false}}
if b{r.append(x)}
}
}
print(r)
}
j(n:1000)
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 3, 122 121 bytes
g=lambda s:len(s)==1or 1==abs(ord(s[0])-ord(s[1]))and g(s[1:])
def f(n,i=1):
while n:
if g(str(i)):n-=1;yield i
i+=1
Try it online!
-1 byte by changing f from printing, to a generator function.
g is a recursive helper function which determines if a string s is a "jumping string" (this works since the character codes for 0 to 9 are in order and contiguous).
f is a generator function that takes in n and yields the first n jumping numbers.
$endgroup$
add a comment |
$begingroup$
R, 85 bytes
i=scan();j=0;while(i)if((j=j+1)<10|all(abs(diff(j%/%10^(0:log10(j))%%10))==1))i=i-1;j
Try it online!
Suspect this can be golfed more. Reads the number using scan() and outputs the appropriate jumping number.
$endgroup$
add a comment |
$begingroup$
Perl 5, 56 bytes
map{1while++$n=~s|.(?=(.))|abs$&-$1!=1|ger>9}1..<>;say$n
Try it online!
1-indexed, outputs the nth jumping number
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 85 bytes
If[#<10,#,t=n=1;While[t<=#,{-1,1}~SubsetQ~Differences@IntegerDigits@n++~If~t++];n-1]&
Try it online!
returns the n-th number
$endgroup$
add a comment |
$begingroup$
Factor, 129 bytes
: f ( x -- ) 1 [ [ dup 10 >base >array differences [ abs 1 = ] all? ] [ 1 + ] until
dup . 1 + [ 1 - ] dip over 0 > ] loop 2drop ;
Try it online!
Outputs the first n jumping numbers
$endgroup$
add a comment |
$begingroup$
Catholicon, 5 bytes
ρHṘḃǰ
Try it online!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
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/3.0/"u003ecc by-sa 3.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%2f180693%2fjumping-numbers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
18 Answers
18
active
oldest
votes
18 Answers
18
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Haskell, 57 bytes
(l!!)
l=[1..9]++[x*10+t|x<-l,t<-[0..9],(mod x 10-t)^2==1]
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 57 bytes
(l!!)
l=[1..9]++[x*10+t|x<-l,t<-[0..9],(mod x 10-t)^2==1]
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 57 bytes
(l!!)
l=[1..9]++[x*10+t|x<-l,t<-[0..9],(mod x 10-t)^2==1]
Try it online!
$endgroup$
Haskell, 57 bytes
(l!!)
l=[1..9]++[x*10+t|x<-l,t<-[0..9],(mod x 10-t)^2==1]
Try it online!
edited Mar 2 at 0:10
answered Mar 1 at 23:59
xnorxnor
91.9k18187445
91.9k18187445
add a comment |
add a comment |
$begingroup$
Jelly, 8 bytes
1DI*`ƑƊ#
A full program accepting an integer, n, from STDIN which prints a list of the first n positive jumping numbers.
Try it online!
How?
Acceptable incremental differences between digits are 1 and -1 while others from [-9,-2]+[2,9] are not. This lines up with integers which are invariant when raised to themselves. i.e. $x^x=x$ since:
$$0^0=1$$
$$1^1=1$$
$$2^2=4$$
$$cdots$$
$$-1^{-1}=-1$$
$$-2^{-2}=-frac{1}{4}$$
$$cdots$$
1DI*`ƑƊ# - Main Link: no arguments (accepts a line of input from STDIN)
# - count up keeping the first (input) n matches...
1 - ...start with n equal to: 1
Ɗ - ...match function: last three links as a monad: e.g. 245 777 7656
D - convert to a list of decimal digits [2,4,5] [7,7,7] [7,6,5,6]
I - incremental differences [2,1] [0,0] [-1,-1,1]
Ƒ - invariant under?:
` - using left argument as both inputs of:
* - exponentiation (vectorises) [4,1] [1,1] [-1,-1,1]
- --so we: discard discard keep
- implicitly print the list of collected values of n
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1DI*`ƑƊ#
A full program accepting an integer, n, from STDIN which prints a list of the first n positive jumping numbers.
Try it online!
How?
Acceptable incremental differences between digits are 1 and -1 while others from [-9,-2]+[2,9] are not. This lines up with integers which are invariant when raised to themselves. i.e. $x^x=x$ since:
$$0^0=1$$
$$1^1=1$$
$$2^2=4$$
$$cdots$$
$$-1^{-1}=-1$$
$$-2^{-2}=-frac{1}{4}$$
$$cdots$$
1DI*`ƑƊ# - Main Link: no arguments (accepts a line of input from STDIN)
# - count up keeping the first (input) n matches...
1 - ...start with n equal to: 1
Ɗ - ...match function: last three links as a monad: e.g. 245 777 7656
D - convert to a list of decimal digits [2,4,5] [7,7,7] [7,6,5,6]
I - incremental differences [2,1] [0,0] [-1,-1,1]
Ƒ - invariant under?:
` - using left argument as both inputs of:
* - exponentiation (vectorises) [4,1] [1,1] [-1,-1,1]
- --so we: discard discard keep
- implicitly print the list of collected values of n
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1DI*`ƑƊ#
A full program accepting an integer, n, from STDIN which prints a list of the first n positive jumping numbers.
Try it online!
How?
Acceptable incremental differences between digits are 1 and -1 while others from [-9,-2]+[2,9] are not. This lines up with integers which are invariant when raised to themselves. i.e. $x^x=x$ since:
$$0^0=1$$
$$1^1=1$$
$$2^2=4$$
$$cdots$$
$$-1^{-1}=-1$$
$$-2^{-2}=-frac{1}{4}$$
$$cdots$$
1DI*`ƑƊ# - Main Link: no arguments (accepts a line of input from STDIN)
# - count up keeping the first (input) n matches...
1 - ...start with n equal to: 1
Ɗ - ...match function: last three links as a monad: e.g. 245 777 7656
D - convert to a list of decimal digits [2,4,5] [7,7,7] [7,6,5,6]
I - incremental differences [2,1] [0,0] [-1,-1,1]
Ƒ - invariant under?:
` - using left argument as both inputs of:
* - exponentiation (vectorises) [4,1] [1,1] [-1,-1,1]
- --so we: discard discard keep
- implicitly print the list of collected values of n
$endgroup$
Jelly, 8 bytes
1DI*`ƑƊ#
A full program accepting an integer, n, from STDIN which prints a list of the first n positive jumping numbers.
Try it online!
How?
Acceptable incremental differences between digits are 1 and -1 while others from [-9,-2]+[2,9] are not. This lines up with integers which are invariant when raised to themselves. i.e. $x^x=x$ since:
$$0^0=1$$
$$1^1=1$$
$$2^2=4$$
$$cdots$$
$$-1^{-1}=-1$$
$$-2^{-2}=-frac{1}{4}$$
$$cdots$$
1DI*`ƑƊ# - Main Link: no arguments (accepts a line of input from STDIN)
# - count up keeping the first (input) n matches...
1 - ...start with n equal to: 1
Ɗ - ...match function: last three links as a monad: e.g. 245 777 7656
D - convert to a list of decimal digits [2,4,5] [7,7,7] [7,6,5,6]
I - incremental differences [2,1] [0,0] [-1,-1,1]
Ƒ - invariant under?:
` - using left argument as both inputs of:
* - exponentiation (vectorises) [4,1] [1,1] [-1,-1,1]
- --so we: discard discard keep
- implicitly print the list of collected values of n
edited Mar 1 at 19:13
answered Mar 1 at 18:13
Jonathan AllanJonathan Allan
52.6k535170
52.6k535170
add a comment |
add a comment |
$begingroup$
05AB1E (legacy), 5 bytes
The input is 1-indexed.
Code:
µN¥ÄP
Uses the 05AB1E encoding. Try it online!
Explanation
µ # Get the nth number, starting from 0, such that...
Ä # The absolute values
N¥ # Of the delta's of N
P # Are all 1 (product function, basically acts as a reduce by AND)
$endgroup$
$begingroup$
Right tool for the job.
$endgroup$
– lirtosiast
Mar 2 at 1:53
add a comment |
$begingroup$
05AB1E (legacy), 5 bytes
The input is 1-indexed.
Code:
µN¥ÄP
Uses the 05AB1E encoding. Try it online!
Explanation
µ # Get the nth number, starting from 0, such that...
Ä # The absolute values
N¥ # Of the delta's of N
P # Are all 1 (product function, basically acts as a reduce by AND)
$endgroup$
$begingroup$
Right tool for the job.
$endgroup$
– lirtosiast
Mar 2 at 1:53
add a comment |
$begingroup$
05AB1E (legacy), 5 bytes
The input is 1-indexed.
Code:
µN¥ÄP
Uses the 05AB1E encoding. Try it online!
Explanation
µ # Get the nth number, starting from 0, such that...
Ä # The absolute values
N¥ # Of the delta's of N
P # Are all 1 (product function, basically acts as a reduce by AND)
$endgroup$
05AB1E (legacy), 5 bytes
The input is 1-indexed.
Code:
µN¥ÄP
Uses the 05AB1E encoding. Try it online!
Explanation
µ # Get the nth number, starting from 0, such that...
Ä # The absolute values
N¥ # Of the delta's of N
P # Are all 1 (product function, basically acts as a reduce by AND)
edited Mar 1 at 20:10
answered Mar 1 at 19:58
AdnanAdnan
35.7k562225
35.7k562225
$begingroup$
Right tool for the job.
$endgroup$
– lirtosiast
Mar 2 at 1:53
add a comment |
$begingroup$
Right tool for the job.
$endgroup$
– lirtosiast
Mar 2 at 1:53
$begingroup$
Right tool for the job.
$endgroup$
– lirtosiast
Mar 2 at 1:53
$begingroup$
Right tool for the job.
$endgroup$
– lirtosiast
Mar 2 at 1:53
add a comment |
$begingroup$
Python 2, 79 75 bytes
-4 bytes by xnor
f=lambda n,i=1:n and-~f(n-g(i),i+1)
g=lambda i:i<10or i%100%11%9==g(i/10)>0
Try it online!
Derived from Chas Brown's answer. The helper function g(i) returns whether i is a jumping number. Iff the last two digits of a number n have absolute difference 1, then n%100%11 will be either 1 or 10, so n%100%11%9 will be 1.
$endgroup$
$begingroup$
Nice trick with the%11. You can dof=lambda n,i=1:n and-~f(n-g(i),i+1)if you switch to one-indexing.
$endgroup$
– xnor
Mar 2 at 5:01
add a comment |
$begingroup$
Python 2, 79 75 bytes
-4 bytes by xnor
f=lambda n,i=1:n and-~f(n-g(i),i+1)
g=lambda i:i<10or i%100%11%9==g(i/10)>0
Try it online!
Derived from Chas Brown's answer. The helper function g(i) returns whether i is a jumping number. Iff the last two digits of a number n have absolute difference 1, then n%100%11 will be either 1 or 10, so n%100%11%9 will be 1.
$endgroup$
$begingroup$
Nice trick with the%11. You can dof=lambda n,i=1:n and-~f(n-g(i),i+1)if you switch to one-indexing.
$endgroup$
– xnor
Mar 2 at 5:01
add a comment |
$begingroup$
Python 2, 79 75 bytes
-4 bytes by xnor
f=lambda n,i=1:n and-~f(n-g(i),i+1)
g=lambda i:i<10or i%100%11%9==g(i/10)>0
Try it online!
Derived from Chas Brown's answer. The helper function g(i) returns whether i is a jumping number. Iff the last two digits of a number n have absolute difference 1, then n%100%11 will be either 1 or 10, so n%100%11%9 will be 1.
$endgroup$
Python 2, 79 75 bytes
-4 bytes by xnor
f=lambda n,i=1:n and-~f(n-g(i),i+1)
g=lambda i:i<10or i%100%11%9==g(i/10)>0
Try it online!
Derived from Chas Brown's answer. The helper function g(i) returns whether i is a jumping number. Iff the last two digits of a number n have absolute difference 1, then n%100%11 will be either 1 or 10, so n%100%11%9 will be 1.
edited Mar 2 at 5:54
answered Mar 2 at 3:03
lirtosiastlirtosiast
18.2k438109
18.2k438109
$begingroup$
Nice trick with the%11. You can dof=lambda n,i=1:n and-~f(n-g(i),i+1)if you switch to one-indexing.
$endgroup$
– xnor
Mar 2 at 5:01
add a comment |
$begingroup$
Nice trick with the%11. You can dof=lambda n,i=1:n and-~f(n-g(i),i+1)if you switch to one-indexing.
$endgroup$
– xnor
Mar 2 at 5:01
$begingroup$
Nice trick with the
%11. You can do f=lambda n,i=1:n and-~f(n-g(i),i+1) if you switch to one-indexing.$endgroup$
– xnor
Mar 2 at 5:01
$begingroup$
Nice trick with the
%11. You can do f=lambda n,i=1:n and-~f(n-g(i),i+1) if you switch to one-indexing.$endgroup$
– xnor
Mar 2 at 5:01
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
1-indexed. Thanks to dzaima for their help with golfing this.
Edit: -15 bytes from ngn.
1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
Try it online!
Explanation
We have f⍣g⍣h, where, as ⍣ is an operator, APL translates this to (f⍣g)⍣h. (In contrast with functions where 2×3+1 is translated 2×(3+1))
1+⍣{...}⍣⎕⊢0 This is equivalent to
"do {check} we find the n-th integer that fulfils {check}"
1+⍣{...} ⊢0 Start with 0 and keep adding 1s until the dfn
(our jumping number check in {}) returns true.
⍣⎕ We take input n (⎕) and repeat (⍣) the above n times
to get the n-th jumping number.
{∧/1=|2-/⍎¨⍕⍺} The dfn that checks for jumping numbers.
⍎¨⍕⍺ We take the base-10 digits of our left argument
by evaluating each character of the string representation of ⍺.
|2-/ Then we take the absolute value of the pairwise differences of the digits
∧/1= and check if all of the differences are equal to 1.
$endgroup$
$begingroup$
10⊥⍣¯1⊢⍺->⍎¨⍕⍺
$endgroup$
– ngn
Mar 6 at 10:52
$begingroup$
it's much shorter with⍣instead of recursion:{1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⍵⊢0}or1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
$endgroup$
– ngn
Mar 6 at 11:05
$begingroup$
"⍣ is an operand" - it's an "operator" (i this mistake in chat and corrected it, but it seems you picked up the initial version. sorry)
$endgroup$
– ngn
Mar 6 at 18:53
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
1-indexed. Thanks to dzaima for their help with golfing this.
Edit: -15 bytes from ngn.
1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
Try it online!
Explanation
We have f⍣g⍣h, where, as ⍣ is an operator, APL translates this to (f⍣g)⍣h. (In contrast with functions where 2×3+1 is translated 2×(3+1))
1+⍣{...}⍣⎕⊢0 This is equivalent to
"do {check} we find the n-th integer that fulfils {check}"
1+⍣{...} ⊢0 Start with 0 and keep adding 1s until the dfn
(our jumping number check in {}) returns true.
⍣⎕ We take input n (⎕) and repeat (⍣) the above n times
to get the n-th jumping number.
{∧/1=|2-/⍎¨⍕⍺} The dfn that checks for jumping numbers.
⍎¨⍕⍺ We take the base-10 digits of our left argument
by evaluating each character of the string representation of ⍺.
|2-/ Then we take the absolute value of the pairwise differences of the digits
∧/1= and check if all of the differences are equal to 1.
$endgroup$
$begingroup$
10⊥⍣¯1⊢⍺->⍎¨⍕⍺
$endgroup$
– ngn
Mar 6 at 10:52
$begingroup$
it's much shorter with⍣instead of recursion:{1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⍵⊢0}or1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
$endgroup$
– ngn
Mar 6 at 11:05
$begingroup$
"⍣ is an operand" - it's an "operator" (i this mistake in chat and corrected it, but it seems you picked up the initial version. sorry)
$endgroup$
– ngn
Mar 6 at 18:53
add a comment |
$begingroup$
APL (Dyalog Unicode), 36 bytesSBCS
1-indexed. Thanks to dzaima for their help with golfing this.
Edit: -15 bytes from ngn.
1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
Try it online!
Explanation
We have f⍣g⍣h, where, as ⍣ is an operator, APL translates this to (f⍣g)⍣h. (In contrast with functions where 2×3+1 is translated 2×(3+1))
1+⍣{...}⍣⎕⊢0 This is equivalent to
"do {check} we find the n-th integer that fulfils {check}"
1+⍣{...} ⊢0 Start with 0 and keep adding 1s until the dfn
(our jumping number check in {}) returns true.
⍣⎕ We take input n (⎕) and repeat (⍣) the above n times
to get the n-th jumping number.
{∧/1=|2-/⍎¨⍕⍺} The dfn that checks for jumping numbers.
⍎¨⍕⍺ We take the base-10 digits of our left argument
by evaluating each character of the string representation of ⍺.
|2-/ Then we take the absolute value of the pairwise differences of the digits
∧/1= and check if all of the differences are equal to 1.
$endgroup$
APL (Dyalog Unicode), 36 bytesSBCS
1-indexed. Thanks to dzaima for their help with golfing this.
Edit: -15 bytes from ngn.
1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
Try it online!
Explanation
We have f⍣g⍣h, where, as ⍣ is an operator, APL translates this to (f⍣g)⍣h. (In contrast with functions where 2×3+1 is translated 2×(3+1))
1+⍣{...}⍣⎕⊢0 This is equivalent to
"do {check} we find the n-th integer that fulfils {check}"
1+⍣{...} ⊢0 Start with 0 and keep adding 1s until the dfn
(our jumping number check in {}) returns true.
⍣⎕ We take input n (⎕) and repeat (⍣) the above n times
to get the n-th jumping number.
{∧/1=|2-/⍎¨⍕⍺} The dfn that checks for jumping numbers.
⍎¨⍕⍺ We take the base-10 digits of our left argument
by evaluating each character of the string representation of ⍺.
|2-/ Then we take the absolute value of the pairwise differences of the digits
∧/1= and check if all of the differences are equal to 1.
edited Mar 6 at 19:29
answered Mar 2 at 16:38
Sherlock9Sherlock9
8,03411860
8,03411860
$begingroup$
10⊥⍣¯1⊢⍺->⍎¨⍕⍺
$endgroup$
– ngn
Mar 6 at 10:52
$begingroup$
it's much shorter with⍣instead of recursion:{1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⍵⊢0}or1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
$endgroup$
– ngn
Mar 6 at 11:05
$begingroup$
"⍣ is an operand" - it's an "operator" (i this mistake in chat and corrected it, but it seems you picked up the initial version. sorry)
$endgroup$
– ngn
Mar 6 at 18:53
add a comment |
$begingroup$
10⊥⍣¯1⊢⍺->⍎¨⍕⍺
$endgroup$
– ngn
Mar 6 at 10:52
$begingroup$
it's much shorter with⍣instead of recursion:{1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⍵⊢0}or1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0
$endgroup$
– ngn
Mar 6 at 11:05
$begingroup$
"⍣ is an operand" - it's an "operator" (i this mistake in chat and corrected it, but it seems you picked up the initial version. sorry)
$endgroup$
– ngn
Mar 6 at 18:53
$begingroup$
10⊥⍣¯1⊢⍺ -> ⍎¨⍕⍺$endgroup$
– ngn
Mar 6 at 10:52
$begingroup$
10⊥⍣¯1⊢⍺ -> ⍎¨⍕⍺$endgroup$
– ngn
Mar 6 at 10:52
$begingroup$
it's much shorter with
⍣ instead of recursion: {1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⍵⊢0} or 1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0$endgroup$
– ngn
Mar 6 at 11:05
$begingroup$
it's much shorter with
⍣ instead of recursion: {1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⍵⊢0} or 1+⍣{∧/1=|2-/⍎¨⍕⍺}⍣⎕⊢0$endgroup$
– ngn
Mar 6 at 11:05
$begingroup$
"⍣ is an operand" - it's an "operator" (i this mistake in chat and corrected it, but it seems you picked up the initial version. sorry)
$endgroup$
– ngn
Mar 6 at 18:53
$begingroup$
"⍣ is an operand" - it's an "operator" (i this mistake in chat and corrected it, but it seems you picked up the initial version. sorry)
$endgroup$
– ngn
Mar 6 at 18:53
add a comment |
$begingroup$
C (gcc), 90 bytes
f(n,K,b,k){for(K=0;n;b&&printf("%d,",K,n--))for(b=k=++K;k/10;)b*=abs(k%10-(k/=10)%10)==1;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 90 bytes
f(n,K,b,k){for(K=0;n;b&&printf("%d,",K,n--))for(b=k=++K;k/10;)b*=abs(k%10-(k/=10)%10)==1;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 90 bytes
f(n,K,b,k){for(K=0;n;b&&printf("%d,",K,n--))for(b=k=++K;k/10;)b*=abs(k%10-(k/=10)%10)==1;}
Try it online!
$endgroup$
C (gcc), 90 bytes
f(n,K,b,k){for(K=0;n;b&&printf("%d,",K,n--))for(b=k=++K;k/10;)b*=abs(k%10-(k/=10)%10)==1;}
Try it online!
answered Mar 1 at 17:45
Jonathan FrechJonathan Frech
6,37311040
6,37311040
add a comment |
add a comment |
$begingroup$
Japt, 14 bytes
Outputs the first nth term, 1-indexed.
_ì äa dÉ ªU´}f
Try it
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$endgroup$
$begingroup$
Haha, maybe go learn a new golfing language to cure your withdrawal. :P
$endgroup$
– Quintec
Mar 1 at 20:09
add a comment |
$begingroup$
Japt, 14 bytes
Outputs the first nth term, 1-indexed.
_ì äa dÉ ªU´}f
Try it
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$endgroup$
$begingroup$
Haha, maybe go learn a new golfing language to cure your withdrawal. :P
$endgroup$
– Quintec
Mar 1 at 20:09
add a comment |
$begingroup$
Japt, 14 bytes
Outputs the first nth term, 1-indexed.
_ì äa dÉ ªU´}f
Try it
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$endgroup$
Japt, 14 bytes
Outputs the first nth term, 1-indexed.
_ì äa dÉ ªU´}f
Try it
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
edited Mar 1 at 19:46
answered Mar 1 at 18:00
ShaggyShaggy
19.4k21667
19.4k21667
$begingroup$
Haha, maybe go learn a new golfing language to cure your withdrawal. :P
$endgroup$
– Quintec
Mar 1 at 20:09
add a comment |
$begingroup$
Haha, maybe go learn a new golfing language to cure your withdrawal. :P
$endgroup$
– Quintec
Mar 1 at 20:09
$begingroup$
Haha, maybe go learn a new golfing language to cure your withdrawal. :P
$endgroup$
– Quintec
Mar 1 at 20:09
$begingroup$
Haha, maybe go learn a new golfing language to cure your withdrawal. :P
$endgroup$
– Quintec
Mar 1 at 20:09
add a comment |
$begingroup$
Python 2, 88 87 bytes
f=lambda n,i=2:n and f(n-g(i),i+1)or~-i
g=lambda i:i<10or abs(i/10%10-i%10)==1==g(i/10)
Try it online!
Returns the 0-indexed jumping number (i.e., f(0) => 1, etc).
$endgroup$
$begingroup$
@lirtosiast : That's OK, please donate your answer to your favorite charity :). It's sufficiently different to merit a separate response (as well as being cross-language appropriate).
$endgroup$
– Chas Brown
Mar 2 at 2:57
add a comment |
$begingroup$
Python 2, 88 87 bytes
f=lambda n,i=2:n and f(n-g(i),i+1)or~-i
g=lambda i:i<10or abs(i/10%10-i%10)==1==g(i/10)
Try it online!
Returns the 0-indexed jumping number (i.e., f(0) => 1, etc).
$endgroup$
$begingroup$
@lirtosiast : That's OK, please donate your answer to your favorite charity :). It's sufficiently different to merit a separate response (as well as being cross-language appropriate).
$endgroup$
– Chas Brown
Mar 2 at 2:57
add a comment |
$begingroup$
Python 2, 88 87 bytes
f=lambda n,i=2:n and f(n-g(i),i+1)or~-i
g=lambda i:i<10or abs(i/10%10-i%10)==1==g(i/10)
Try it online!
Returns the 0-indexed jumping number (i.e., f(0) => 1, etc).
$endgroup$
Python 2, 88 87 bytes
f=lambda n,i=2:n and f(n-g(i),i+1)or~-i
g=lambda i:i<10or abs(i/10%10-i%10)==1==g(i/10)
Try it online!
Returns the 0-indexed jumping number (i.e., f(0) => 1, etc).
edited Mar 1 at 22:03
answered Mar 1 at 21:21
Chas BrownChas Brown
4,9941523
4,9941523
$begingroup$
@lirtosiast : That's OK, please donate your answer to your favorite charity :). It's sufficiently different to merit a separate response (as well as being cross-language appropriate).
$endgroup$
– Chas Brown
Mar 2 at 2:57
add a comment |
$begingroup$
@lirtosiast : That's OK, please donate your answer to your favorite charity :). It's sufficiently different to merit a separate response (as well as being cross-language appropriate).
$endgroup$
– Chas Brown
Mar 2 at 2:57
$begingroup$
@lirtosiast : That's OK, please donate your answer to your favorite charity :). It's sufficiently different to merit a separate response (as well as being cross-language appropriate).
$endgroup$
– Chas Brown
Mar 2 at 2:57
$begingroup$
@lirtosiast : That's OK, please donate your answer to your favorite charity :). It's sufficiently different to merit a separate response (as well as being cross-language appropriate).
$endgroup$
– Chas Brown
Mar 2 at 2:57
add a comment |
$begingroup$
Haskell, 69 bytes
- Thanks to Joseph Sible for enforcing the challenge rules and saving three bytes.
- Saved two bytes thanks to nimi.
(filter(all((==1).abs).(zipWith(-)<*>tail).map fromEnum.show)[1..]!!)
Try it online!
$endgroup$
1
$begingroup$
This appears to answer the question "is this a jumping number?" for a given input number, which isn't what the challenge asked for.
$endgroup$
– Joseph Sible
Mar 1 at 18:57
$begingroup$
@JosephSible You are correct. Thank you for noting.
$endgroup$
– Jonathan Frech
Mar 1 at 23:34
$begingroup$
Also, now that that's fixed, you can makeg3 bytes shorter by rewriting it to be pointfree, then using<*>:g=all((==1).abs).(zipWith(-)<*>tail).map(read.pure).show
$endgroup$
– Joseph Sible
Mar 2 at 4:02
$begingroup$
@JosephSible Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 4:19
$begingroup$
@nimi Done. Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 7:57
add a comment |
$begingroup$
Haskell, 69 bytes
- Thanks to Joseph Sible for enforcing the challenge rules and saving three bytes.
- Saved two bytes thanks to nimi.
(filter(all((==1).abs).(zipWith(-)<*>tail).map fromEnum.show)[1..]!!)
Try it online!
$endgroup$
1
$begingroup$
This appears to answer the question "is this a jumping number?" for a given input number, which isn't what the challenge asked for.
$endgroup$
– Joseph Sible
Mar 1 at 18:57
$begingroup$
@JosephSible You are correct. Thank you for noting.
$endgroup$
– Jonathan Frech
Mar 1 at 23:34
$begingroup$
Also, now that that's fixed, you can makeg3 bytes shorter by rewriting it to be pointfree, then using<*>:g=all((==1).abs).(zipWith(-)<*>tail).map(read.pure).show
$endgroup$
– Joseph Sible
Mar 2 at 4:02
$begingroup$
@JosephSible Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 4:19
$begingroup$
@nimi Done. Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 7:57
add a comment |
$begingroup$
Haskell, 69 bytes
- Thanks to Joseph Sible for enforcing the challenge rules and saving three bytes.
- Saved two bytes thanks to nimi.
(filter(all((==1).abs).(zipWith(-)<*>tail).map fromEnum.show)[1..]!!)
Try it online!
$endgroup$
Haskell, 69 bytes
- Thanks to Joseph Sible for enforcing the challenge rules and saving three bytes.
- Saved two bytes thanks to nimi.
(filter(all((==1).abs).(zipWith(-)<*>tail).map fromEnum.show)[1..]!!)
Try it online!
edited Mar 2 at 7:57
answered Mar 1 at 18:03
Jonathan FrechJonathan Frech
6,37311040
6,37311040
1
$begingroup$
This appears to answer the question "is this a jumping number?" for a given input number, which isn't what the challenge asked for.
$endgroup$
– Joseph Sible
Mar 1 at 18:57
$begingroup$
@JosephSible You are correct. Thank you for noting.
$endgroup$
– Jonathan Frech
Mar 1 at 23:34
$begingroup$
Also, now that that's fixed, you can makeg3 bytes shorter by rewriting it to be pointfree, then using<*>:g=all((==1).abs).(zipWith(-)<*>tail).map(read.pure).show
$endgroup$
– Joseph Sible
Mar 2 at 4:02
$begingroup$
@JosephSible Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 4:19
$begingroup$
@nimi Done. Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 7:57
add a comment |
1
$begingroup$
This appears to answer the question "is this a jumping number?" for a given input number, which isn't what the challenge asked for.
$endgroup$
– Joseph Sible
Mar 1 at 18:57
$begingroup$
@JosephSible You are correct. Thank you for noting.
$endgroup$
– Jonathan Frech
Mar 1 at 23:34
$begingroup$
Also, now that that's fixed, you can makeg3 bytes shorter by rewriting it to be pointfree, then using<*>:g=all((==1).abs).(zipWith(-)<*>tail).map(read.pure).show
$endgroup$
– Joseph Sible
Mar 2 at 4:02
$begingroup$
@JosephSible Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 4:19
$begingroup$
@nimi Done. Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 7:57
1
1
$begingroup$
This appears to answer the question "is this a jumping number?" for a given input number, which isn't what the challenge asked for.
$endgroup$
– Joseph Sible
Mar 1 at 18:57
$begingroup$
This appears to answer the question "is this a jumping number?" for a given input number, which isn't what the challenge asked for.
$endgroup$
– Joseph Sible
Mar 1 at 18:57
$begingroup$
@JosephSible You are correct. Thank you for noting.
$endgroup$
– Jonathan Frech
Mar 1 at 23:34
$begingroup$
@JosephSible You are correct. Thank you for noting.
$endgroup$
– Jonathan Frech
Mar 1 at 23:34
$begingroup$
Also, now that that's fixed, you can make
g 3 bytes shorter by rewriting it to be pointfree, then using <*>: g=all((==1).abs).(zipWith(-)<*>tail).map(read.pure).show$endgroup$
– Joseph Sible
Mar 2 at 4:02
$begingroup$
Also, now that that's fixed, you can make
g 3 bytes shorter by rewriting it to be pointfree, then using <*>: g=all((==1).abs).(zipWith(-)<*>tail).map(read.pure).show$endgroup$
– Joseph Sible
Mar 2 at 4:02
$begingroup$
@JosephSible Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 4:19
$begingroup$
@JosephSible Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 4:19
$begingroup$
@nimi Done. Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 7:57
$begingroup$
@nimi Done. Thank you.
$endgroup$
– Jonathan Frech
Mar 2 at 7:57
add a comment |
$begingroup$
JavaScript (ES7), 60 bytes
Returns the $n$th term of the sequence (1-indexed).
f=(n,k)=>[...k+''].some(p=x=>(p-(p=x))**2-1)||n--?f(n,-~k):k
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 60 bytes
Returns the $n$th term of the sequence (1-indexed).
f=(n,k)=>[...k+''].some(p=x=>(p-(p=x))**2-1)||n--?f(n,-~k):k
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 60 bytes
Returns the $n$th term of the sequence (1-indexed).
f=(n,k)=>[...k+''].some(p=x=>(p-(p=x))**2-1)||n--?f(n,-~k):k
Try it online!
$endgroup$
JavaScript (ES7), 60 bytes
Returns the $n$th term of the sequence (1-indexed).
f=(n,k)=>[...k+''].some(p=x=>(p-(p=x))**2-1)||n--?f(n,-~k):k
Try it online!
answered Mar 1 at 18:04
ArnauldArnauld
78.1k795326
78.1k795326
add a comment |
add a comment |
$begingroup$
Jelly, 9 bytes
-1 by Jonathan Allan
1DạƝ=1ẠƲ#
Try it online!
1-indexed.
$endgroup$
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
Mar 1 at 18:15
add a comment |
$begingroup$
Jelly, 9 bytes
-1 by Jonathan Allan
1DạƝ=1ẠƲ#
Try it online!
1-indexed.
$endgroup$
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
Mar 1 at 18:15
add a comment |
$begingroup$
Jelly, 9 bytes
-1 by Jonathan Allan
1DạƝ=1ẠƲ#
Try it online!
1-indexed.
$endgroup$
Jelly, 9 bytes
-1 by Jonathan Allan
1DạƝ=1ẠƲ#
Try it online!
1-indexed.
edited Mar 1 at 19:51
answered Mar 1 at 18:04
lirtosiastlirtosiast
18.2k438109
18.2k438109
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
Mar 1 at 18:15
add a comment |
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
Mar 1 at 18:15
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
Mar 1 at 18:15
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
Mar 1 at 18:15
add a comment |
$begingroup$
Swift, 228 bytes
func j(n:Int){
var r:[Int]=
for x in 0...n{
if x<=10{r.append(x)}else{
let t=String(x).compactMap{Int(String($0))}
var b=true
for i in 1...t.count-1{if abs(t[i-1]-t[i]) != 1{b=false}}
if b{r.append(x)}
}
}
print(r)
}
j(n:1000)
Try it online!
$endgroup$
add a comment |
$begingroup$
Swift, 228 bytes
func j(n:Int){
var r:[Int]=
for x in 0...n{
if x<=10{r.append(x)}else{
let t=String(x).compactMap{Int(String($0))}
var b=true
for i in 1...t.count-1{if abs(t[i-1]-t[i]) != 1{b=false}}
if b{r.append(x)}
}
}
print(r)
}
j(n:1000)
Try it online!
$endgroup$
add a comment |
$begingroup$
Swift, 228 bytes
func j(n:Int){
var r:[Int]=
for x in 0...n{
if x<=10{r.append(x)}else{
let t=String(x).compactMap{Int(String($0))}
var b=true
for i in 1...t.count-1{if abs(t[i-1]-t[i]) != 1{b=false}}
if b{r.append(x)}
}
}
print(r)
}
j(n:1000)
Try it online!
$endgroup$
Swift, 228 bytes
func j(n:Int){
var r:[Int]=
for x in 0...n{
if x<=10{r.append(x)}else{
let t=String(x).compactMap{Int(String($0))}
var b=true
for i in 1...t.count-1{if abs(t[i-1]-t[i]) != 1{b=false}}
if b{r.append(x)}
}
}
print(r)
}
j(n:1000)
Try it online!
edited Mar 1 at 19:07
Shaggy
19.4k21667
19.4k21667
answered Mar 1 at 18:55
onnowebonnoweb
1312
1312
add a comment |
add a comment |
$begingroup$
Python 3, 122 121 bytes
g=lambda s:len(s)==1or 1==abs(ord(s[0])-ord(s[1]))and g(s[1:])
def f(n,i=1):
while n:
if g(str(i)):n-=1;yield i
i+=1
Try it online!
-1 byte by changing f from printing, to a generator function.
g is a recursive helper function which determines if a string s is a "jumping string" (this works since the character codes for 0 to 9 are in order and contiguous).
f is a generator function that takes in n and yields the first n jumping numbers.
$endgroup$
add a comment |
$begingroup$
Python 3, 122 121 bytes
g=lambda s:len(s)==1or 1==abs(ord(s[0])-ord(s[1]))and g(s[1:])
def f(n,i=1):
while n:
if g(str(i)):n-=1;yield i
i+=1
Try it online!
-1 byte by changing f from printing, to a generator function.
g is a recursive helper function which determines if a string s is a "jumping string" (this works since the character codes for 0 to 9 are in order and contiguous).
f is a generator function that takes in n and yields the first n jumping numbers.
$endgroup$
add a comment |
$begingroup$
Python 3, 122 121 bytes
g=lambda s:len(s)==1or 1==abs(ord(s[0])-ord(s[1]))and g(s[1:])
def f(n,i=1):
while n:
if g(str(i)):n-=1;yield i
i+=1
Try it online!
-1 byte by changing f from printing, to a generator function.
g is a recursive helper function which determines if a string s is a "jumping string" (this works since the character codes for 0 to 9 are in order and contiguous).
f is a generator function that takes in n and yields the first n jumping numbers.
$endgroup$
Python 3, 122 121 bytes
g=lambda s:len(s)==1or 1==abs(ord(s[0])-ord(s[1]))and g(s[1:])
def f(n,i=1):
while n:
if g(str(i)):n-=1;yield i
i+=1
Try it online!
-1 byte by changing f from printing, to a generator function.
g is a recursive helper function which determines if a string s is a "jumping string" (this works since the character codes for 0 to 9 are in order and contiguous).
f is a generator function that takes in n and yields the first n jumping numbers.
answered Mar 1 at 20:11
pizzapants184pizzapants184
2,724716
2,724716
add a comment |
add a comment |
$begingroup$
R, 85 bytes
i=scan();j=0;while(i)if((j=j+1)<10|all(abs(diff(j%/%10^(0:log10(j))%%10))==1))i=i-1;j
Try it online!
Suspect this can be golfed more. Reads the number using scan() and outputs the appropriate jumping number.
$endgroup$
add a comment |
$begingroup$
R, 85 bytes
i=scan();j=0;while(i)if((j=j+1)<10|all(abs(diff(j%/%10^(0:log10(j))%%10))==1))i=i-1;j
Try it online!
Suspect this can be golfed more. Reads the number using scan() and outputs the appropriate jumping number.
$endgroup$
add a comment |
$begingroup$
R, 85 bytes
i=scan();j=0;while(i)if((j=j+1)<10|all(abs(diff(j%/%10^(0:log10(j))%%10))==1))i=i-1;j
Try it online!
Suspect this can be golfed more. Reads the number using scan() and outputs the appropriate jumping number.
$endgroup$
R, 85 bytes
i=scan();j=0;while(i)if((j=j+1)<10|all(abs(diff(j%/%10^(0:log10(j))%%10))==1))i=i-1;j
Try it online!
Suspect this can be golfed more. Reads the number using scan() and outputs the appropriate jumping number.
answered Mar 1 at 20:19
Nick KennedyNick Kennedy
56127
56127
add a comment |
add a comment |
$begingroup$
Perl 5, 56 bytes
map{1while++$n=~s|.(?=(.))|abs$&-$1!=1|ger>9}1..<>;say$n
Try it online!
1-indexed, outputs the nth jumping number
$endgroup$
add a comment |
$begingroup$
Perl 5, 56 bytes
map{1while++$n=~s|.(?=(.))|abs$&-$1!=1|ger>9}1..<>;say$n
Try it online!
1-indexed, outputs the nth jumping number
$endgroup$
add a comment |
$begingroup$
Perl 5, 56 bytes
map{1while++$n=~s|.(?=(.))|abs$&-$1!=1|ger>9}1..<>;say$n
Try it online!
1-indexed, outputs the nth jumping number
$endgroup$
Perl 5, 56 bytes
map{1while++$n=~s|.(?=(.))|abs$&-$1!=1|ger>9}1..<>;say$n
Try it online!
1-indexed, outputs the nth jumping number
answered Mar 1 at 23:43
XcaliXcali
5,425520
5,425520
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 85 bytes
If[#<10,#,t=n=1;While[t<=#,{-1,1}~SubsetQ~Differences@IntegerDigits@n++~If~t++];n-1]&
Try it online!
returns the n-th number
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 85 bytes
If[#<10,#,t=n=1;While[t<=#,{-1,1}~SubsetQ~Differences@IntegerDigits@n++~If~t++];n-1]&
Try it online!
returns the n-th number
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 85 bytes
If[#<10,#,t=n=1;While[t<=#,{-1,1}~SubsetQ~Differences@IntegerDigits@n++~If~t++];n-1]&
Try it online!
returns the n-th number
$endgroup$
Wolfram Language (Mathematica), 85 bytes
If[#<10,#,t=n=1;While[t<=#,{-1,1}~SubsetQ~Differences@IntegerDigits@n++~If~t++];n-1]&
Try it online!
returns the n-th number
edited Mar 2 at 1:23
answered Mar 2 at 1:17
J42161217J42161217
13.2k21150
13.2k21150
add a comment |
add a comment |
$begingroup$
Factor, 129 bytes
: f ( x -- ) 1 [ [ dup 10 >base >array differences [ abs 1 = ] all? ] [ 1 + ] until
dup . 1 + [ 1 - ] dip over 0 > ] loop 2drop ;
Try it online!
Outputs the first n jumping numbers
$endgroup$
add a comment |
$begingroup$
Factor, 129 bytes
: f ( x -- ) 1 [ [ dup 10 >base >array differences [ abs 1 = ] all? ] [ 1 + ] until
dup . 1 + [ 1 - ] dip over 0 > ] loop 2drop ;
Try it online!
Outputs the first n jumping numbers
$endgroup$
add a comment |
$begingroup$
Factor, 129 bytes
: f ( x -- ) 1 [ [ dup 10 >base >array differences [ abs 1 = ] all? ] [ 1 + ] until
dup . 1 + [ 1 - ] dip over 0 > ] loop 2drop ;
Try it online!
Outputs the first n jumping numbers
$endgroup$
Factor, 129 bytes
: f ( x -- ) 1 [ [ dup 10 >base >array differences [ abs 1 = ] all? ] [ 1 + ] until
dup . 1 + [ 1 - ] dip over 0 > ] loop 2drop ;
Try it online!
Outputs the first n jumping numbers
answered Mar 2 at 10:47
Galen IvanovGalen Ivanov
7,06211034
7,06211034
add a comment |
add a comment |
$begingroup$
Catholicon, 5 bytes
ρHṘḃǰ
Try it online!
$endgroup$
add a comment |
$begingroup$
Catholicon, 5 bytes
ρHṘḃǰ
Try it online!
$endgroup$
add a comment |
$begingroup$
Catholicon, 5 bytes
ρHṘḃǰ
Try it online!
$endgroup$
Catholicon, 5 bytes
ρHṘḃǰ
Try it online!
answered Mar 3 at 0:00
OkxOkx
12.9k128102
12.9k128102
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%2f180693%2fjumping-numbers%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
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
Mar 1 at 17:19
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the input
nthen it is up to you.$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 17:20
$begingroup$
I'm guessing "Any valid I/O format is allowed" includes outputting the numbers as lists of decimal digits, but just wanted to confirm - ?
$endgroup$
– Jonathan Allan
Mar 1 at 18:04
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
Mar 1 at 18:27