Jumping NumbersJumping and RunningEnumerate all palindromic numbers (in decimal) between 0 and nConvert image...
Using only 1s, make 29 with the minimum number of digits
Why did other German political parties disband so fast when Hitler was appointed chancellor?
Can a hotel cancel a confirmed reservation?
What creature do these Alchemical Humonculus actions target?
Broken patches on a road
Lick explanation
What is the in-universe cost of a TIE fighter?
Why does lambda auto& parameter choose const overload?
Magento 2 : Call Helper Without Using __construct in Own Module
Quenching swords in dragon blood; why?
What is a jet (unit) shown in Windows 10 calculator?
What's a good word to describe a public place that looks like it wouldn't be rough?
Typing Amharic inside a math equation?
How to deal with an incendiary email that was recalled
Isn't using the Extrusion Multiplier like cheating?
How to tag distinct options/entities without giving any an implicit priority or suggested order?
How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?
Why is working on the same position for more than 15 years not a red flag?
Is a debit card dangerous in my situation?
Can I write a book of my D&D game?
Do authors have to be politically correct in article-writing?
How do you funnel food off a cutting board?
What is the purpose of easy combat scenarios that don't need resource expenditure?
Why exactly do action photographers need high fps burst cameras?
Jumping Numbers
Jumping and RunningEnumerate all palindromic numbers (in decimal) between 0 and nConvert image pixels to quadruplesAsciimation Jumping JacksThe jumping digits to letters transformationLily pad jumpingBIU numbers (or Sumdivized numbers)cardinal numbers into ordinal numbersThe Jumping Up SequencePointer jumping
$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
n
output the firstn
jumping numbers. - Given an input
n
output then
th 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
$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
n
output the firstn
jumping numbers. - Given an input
n
output then
th 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
$endgroup$
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
2 hours ago
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the inputn
then it is up to you.
$endgroup$
– Luis felipe De jesus Munoz
2 hours ago
$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
1 hour ago
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
1 hour ago
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
n
output the firstn
jumping numbers. - Given an input
n
output then
th 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
$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
n
output the firstn
jumping numbers. - Given an input
n
output then
th 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
code-golf
edited 2 hours ago
Luis felipe De jesus Munoz
asked 2 hours ago
Luis felipe De jesus MunozLuis felipe De jesus Munoz
5,32221669
5,32221669
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
2 hours ago
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the inputn
then it is up to you.
$endgroup$
– Luis felipe De jesus Munoz
2 hours ago
$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
1 hour ago
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
1 hour ago
add a comment |
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
2 hours ago
1
$begingroup$
@TaylorScott The sequence consists in only positive numbers. If you mean the inputn
then it is up to you.
$endgroup$
– Luis felipe De jesus Munoz
2 hours ago
$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
1 hour ago
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
1 hour ago
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
2 hours ago
$begingroup$
Is this 0 or 1 Indexed?
$endgroup$
– Taylor Scott
2 hours ago
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
2 hours ago
$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
2 hours ago
$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
1 hour ago
$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
1 hour ago
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
1 hour ago
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
1 hour ago
add a comment |
7 Answers
7
active
oldest
votes
$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$
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$
Haskell, 61 bytes
f n|l<-map fromEnum.show$n=all((==1).abs)$zipWith(-)l(tail l)
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
32 mins ago
add a comment |
$begingroup$
Jelly, 10 bytes
1DạƝ=1ẠƲ³#
Try it online!
1-indexed.
$endgroup$
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
1 hour ago
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$
Japt, 18 bytes
Outputs the first n
terms using 1-based indexing.
@_ì_äa âÃÉ}fXÄ}h9õ
Try it
@_ì_äa âÃÉ}fXÄ}h9õ :Implicit input of integer U
9õ :Range [1,9]
@ }h :Run the following function until that reaches length U,
:passing the last element as X each time,
:and pushing the output each time
XÄ : Add 1 to X
_ }f : Get the first integer >= to that that returns falsey (0)
ì : Split to digit array
_ : Run through the following function and rejoin to integer
äa : Consecutive absolute differences
â : Deduplicate
à : End function
É : Subtract 1
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$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 |
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
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
$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 1 hour ago
Jonathan FrechJonathan Frech
6,32311040
6,32311040
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 16 mins ago
answered 1 hour ago
Jonathan AllanJonathan Allan
52.3k535170
52.3k535170
add a comment |
add a comment |
$begingroup$
Haskell, 61 bytes
f n|l<-map fromEnum.show$n=all((==1).abs)$zipWith(-)l(tail l)
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
32 mins ago
add a comment |
$begingroup$
Haskell, 61 bytes
f n|l<-map fromEnum.show$n=all((==1).abs)$zipWith(-)l(tail l)
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
32 mins ago
add a comment |
$begingroup$
Haskell, 61 bytes
f n|l<-map fromEnum.show$n=all((==1).abs)$zipWith(-)l(tail l)
Try it online!
$endgroup$
Haskell, 61 bytes
f n|l<-map fromEnum.show$n=all((==1).abs)$zipWith(-)l(tail l)
Try it online!
answered 1 hour ago
Jonathan FrechJonathan Frech
6,32311040
6,32311040
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
32 mins ago
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
32 mins ago
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
32 mins ago
$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
32 mins ago
add a comment |
$begingroup$
Jelly, 10 bytes
1DạƝ=1ẠƲ³#
Try it online!
1-indexed.
$endgroup$
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
1 hour ago
add a comment |
$begingroup$
Jelly, 10 bytes
1DạƝ=1ẠƲ³#
Try it online!
1-indexed.
$endgroup$
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
1 hour ago
add a comment |
$begingroup$
Jelly, 10 bytes
1DạƝ=1ẠƲ³#
Try it online!
1-indexed.
$endgroup$
Jelly, 10 bytes
1DạƝ=1ẠƲ³#
Try it online!
1-indexed.
answered 1 hour ago
lirtosiastlirtosiast
18k437109
18k437109
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
1 hour ago
add a comment |
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
1 hour ago
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
1 hour ago
$begingroup$
9 bytes by reading STDIN
$endgroup$
– Jonathan Allan
1 hour ago
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 1 hour ago
ArnauldArnauld
77.4k694324
77.4k694324
add a comment |
add a comment |
$begingroup$
Japt, 18 bytes
Outputs the first n
terms using 1-based indexing.
@_ì_äa âÃÉ}fXÄ}h9õ
Try it
@_ì_äa âÃÉ}fXÄ}h9õ :Implicit input of integer U
9õ :Range [1,9]
@ }h :Run the following function until that reaches length U,
:passing the last element as X each time,
:and pushing the output each time
XÄ : Add 1 to X
_ }f : Get the first integer >= to that that returns falsey (0)
ì : Split to digit array
_ : Run through the following function and rejoin to integer
äa : Consecutive absolute differences
â : Deduplicate
à : End function
É : Subtract 1
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$endgroup$
add a comment |
$begingroup$
Japt, 18 bytes
Outputs the first n
terms using 1-based indexing.
@_ì_äa âÃÉ}fXÄ}h9õ
Try it
@_ì_äa âÃÉ}fXÄ}h9õ :Implicit input of integer U
9õ :Range [1,9]
@ }h :Run the following function until that reaches length U,
:passing the last element as X each time,
:and pushing the output each time
XÄ : Add 1 to X
_ }f : Get the first integer >= to that that returns falsey (0)
ì : Split to digit array
_ : Run through the following function and rejoin to integer
äa : Consecutive absolute differences
â : Deduplicate
à : End function
É : Subtract 1
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$endgroup$
add a comment |
$begingroup$
Japt, 18 bytes
Outputs the first n
terms using 1-based indexing.
@_ì_äa âÃÉ}fXÄ}h9õ
Try it
@_ì_äa âÃÉ}fXÄ}h9õ :Implicit input of integer U
9õ :Range [1,9]
@ }h :Run the following function until that reaches length U,
:passing the last element as X each time,
:and pushing the output each time
XÄ : Add 1 to X
_ }f : Get the first integer >= to that that returns falsey (0)
ì : Split to digit array
_ : Run through the following function and rejoin to integer
äa : Consecutive absolute differences
â : Deduplicate
à : End function
É : Subtract 1
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
$endgroup$
Japt, 18 bytes
Outputs the first n
terms using 1-based indexing.
@_ì_äa âÃÉ}fXÄ}h9õ
Try it
@_ì_äa âÃÉ}fXÄ}h9õ :Implicit input of integer U
9õ :Range [1,9]
@ }h :Run the following function until that reaches length U,
:passing the last element as X each time,
:and pushing the output each time
XÄ : Add 1 to X
_ }f : Get the first integer >= to that that returns falsey (0)
ì : Split to digit array
_ : Run through the following function and rejoin to integer
äa : Consecutive absolute differences
â : Deduplicate
à : End function
É : Subtract 1
(I know, I know, I'm supposed to be taking a break but I'm in golf withdrawal!)
edited 1 hour ago
answered 1 hour ago
ShaggyShaggy
19.5k21667
19.5k21667
add a comment |
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 23 mins ago
Shaggy
19.5k21667
19.5k21667
answered 34 mins ago
onnowebonnoweb
1212
1212
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
2 hours ago
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
2 hours ago
$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
1 hour ago
$begingroup$
Yes @JonathanAllan
$endgroup$
– Luis felipe De jesus Munoz
1 hour ago