The Nth Gryphon Number Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) The PPCG Site design is on its way - help us make it awesome! Sandbox for Proposed ChallengesReturn the nth digit of the sequence of aliquot seriesOutput the nth rational number according to the Stern-Brocot sequenceNumbers divisible by the sum and product of their digitsDisplay OEIS sequencesLinear interpolation of the Fibonacci sequenceSwap the SequenceSeeking Secret Swapping SequencesCan even numbers become prime?Back to the Basics of MathX Steps Forward, 1 Step Back
One-one communication
What is the meaning of 'breadth' in breadth first search?
AppleTVs create a chatty alternate WiFi network
Is there hard evidence that the grant peer review system performs significantly better than random?
How would a mousetrap for use in space work?
How fail-safe is nr as stop bytes?
Is there any word for a place full of confusion?
What would you call this weird metallic apparatus that allows you to lift people?
Why is there Net Work Done on a Pressure/Volume Cycle?
Can you explain what "processes and tools" means in the first Agile principle?
Project Euler #1 in C++
Importance of からだ in this sentence
How to play a character with a disability or mental disorder without being offensive?
What do you call the main part of a joke?
A letter with no particular backstory
"Lost his faith in humanity in the trenches of Verdun" — last line of an SF story
Do wooden building fires get hotter than 600°C?
Why weren't discrete x86 CPUs ever used in game hardware?
Is it possible for SQL statements to execute concurrently within a single session in SQL Server?
Why limits give us the exact value of the slope of the tangent line?
How to run automated tests after each commit?
Electrolysis of water: Which equations to use? (IB Chem)
Belief In God or Knowledge Of God. Which is better?
Who can remove European Commissioners?
The Nth Gryphon Number
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
The PPCG Site design is on its way - help us make it awesome!
Sandbox for Proposed ChallengesReturn the nth digit of the sequence of aliquot seriesOutput the nth rational number according to the Stern-Brocot sequenceNumbers divisible by the sum and product of their digitsDisplay OEIS sequencesLinear interpolation of the Fibonacci sequenceSwap the SequenceSeeking Secret Swapping SequencesCan even numbers become prime?Back to the Basics of MathX Steps Forward, 1 Step Back
$begingroup$
I came up with a series of numbers the other day and decided to check what the OEIS number for it was. Much to my surprise, the sequence did not appear to be in the OEIS database, so I decided to name the sequence after myself (note that someone else who's a lot smarter than me has probably already come up with this, and if someone finds the actual name of this sequence, please comment and I'll change the question title). As I couldn't find the sequence anywhere, I decided to name it after myself, hence "Gryphon Numbers".
A Gryphon number is a number of the form $a+a^2+...+a^x$, where both $a$ and $x$ are integers greater than or equal to two, and the Gryphon sequence is the set of all Gryphon numbers in ascending order. If there are multiple ways of forming a Gryphon number (the first example is $30$, which is both $2+2^2+2^3+2^4$ and $5+5^2$) the number is only counted once in the sequence. The first few Gryphon numbers are: $6, 12, 14, 20, 30, 39, 42, 56, 62, 72$.
Your Task:
Write a program or function that receives an integer $n$ as input and outputs the $n$th Gryphon number.
Input:
An integer between 0 and 10000 (inclusive). You may treat the sequence as either 0-indexed or 1-indexed, whichever you prefer. Please state which indexing system you use in your answer to avoid confusion.
Output:
The Gryphon number corresponding to the input.
Test Cases:
Please note that this assumes the sequence is 0-indexed. If your program assumes a 1-indexed sequence, don't forget to increment all the input numbers.
Input: Output:
0 ---> 6
3 ---> 20
4 ---> 30
10 ---> 84
Scoring:
This is code-golf, so the lowest score in bytes wins.
code-golf sequence
$endgroup$
add a comment |
$begingroup$
I came up with a series of numbers the other day and decided to check what the OEIS number for it was. Much to my surprise, the sequence did not appear to be in the OEIS database, so I decided to name the sequence after myself (note that someone else who's a lot smarter than me has probably already come up with this, and if someone finds the actual name of this sequence, please comment and I'll change the question title). As I couldn't find the sequence anywhere, I decided to name it after myself, hence "Gryphon Numbers".
A Gryphon number is a number of the form $a+a^2+...+a^x$, where both $a$ and $x$ are integers greater than or equal to two, and the Gryphon sequence is the set of all Gryphon numbers in ascending order. If there are multiple ways of forming a Gryphon number (the first example is $30$, which is both $2+2^2+2^3+2^4$ and $5+5^2$) the number is only counted once in the sequence. The first few Gryphon numbers are: $6, 12, 14, 20, 30, 39, 42, 56, 62, 72$.
Your Task:
Write a program or function that receives an integer $n$ as input and outputs the $n$th Gryphon number.
Input:
An integer between 0 and 10000 (inclusive). You may treat the sequence as either 0-indexed or 1-indexed, whichever you prefer. Please state which indexing system you use in your answer to avoid confusion.
Output:
The Gryphon number corresponding to the input.
Test Cases:
Please note that this assumes the sequence is 0-indexed. If your program assumes a 1-indexed sequence, don't forget to increment all the input numbers.
Input: Output:
0 ---> 6
3 ---> 20
4 ---> 30
10 ---> 84
Scoring:
This is code-golf, so the lowest score in bytes wins.
code-golf sequence
$endgroup$
3
$begingroup$
How about bigger test cases like 2000 or 10000?
$endgroup$
– J42161217
1 hour ago
add a comment |
$begingroup$
I came up with a series of numbers the other day and decided to check what the OEIS number for it was. Much to my surprise, the sequence did not appear to be in the OEIS database, so I decided to name the sequence after myself (note that someone else who's a lot smarter than me has probably already come up with this, and if someone finds the actual name of this sequence, please comment and I'll change the question title). As I couldn't find the sequence anywhere, I decided to name it after myself, hence "Gryphon Numbers".
A Gryphon number is a number of the form $a+a^2+...+a^x$, where both $a$ and $x$ are integers greater than or equal to two, and the Gryphon sequence is the set of all Gryphon numbers in ascending order. If there are multiple ways of forming a Gryphon number (the first example is $30$, which is both $2+2^2+2^3+2^4$ and $5+5^2$) the number is only counted once in the sequence. The first few Gryphon numbers are: $6, 12, 14, 20, 30, 39, 42, 56, 62, 72$.
Your Task:
Write a program or function that receives an integer $n$ as input and outputs the $n$th Gryphon number.
Input:
An integer between 0 and 10000 (inclusive). You may treat the sequence as either 0-indexed or 1-indexed, whichever you prefer. Please state which indexing system you use in your answer to avoid confusion.
Output:
The Gryphon number corresponding to the input.
Test Cases:
Please note that this assumes the sequence is 0-indexed. If your program assumes a 1-indexed sequence, don't forget to increment all the input numbers.
Input: Output:
0 ---> 6
3 ---> 20
4 ---> 30
10 ---> 84
Scoring:
This is code-golf, so the lowest score in bytes wins.
code-golf sequence
$endgroup$
I came up with a series of numbers the other day and decided to check what the OEIS number for it was. Much to my surprise, the sequence did not appear to be in the OEIS database, so I decided to name the sequence after myself (note that someone else who's a lot smarter than me has probably already come up with this, and if someone finds the actual name of this sequence, please comment and I'll change the question title). As I couldn't find the sequence anywhere, I decided to name it after myself, hence "Gryphon Numbers".
A Gryphon number is a number of the form $a+a^2+...+a^x$, where both $a$ and $x$ are integers greater than or equal to two, and the Gryphon sequence is the set of all Gryphon numbers in ascending order. If there are multiple ways of forming a Gryphon number (the first example is $30$, which is both $2+2^2+2^3+2^4$ and $5+5^2$) the number is only counted once in the sequence. The first few Gryphon numbers are: $6, 12, 14, 20, 30, 39, 42, 56, 62, 72$.
Your Task:
Write a program or function that receives an integer $n$ as input and outputs the $n$th Gryphon number.
Input:
An integer between 0 and 10000 (inclusive). You may treat the sequence as either 0-indexed or 1-indexed, whichever you prefer. Please state which indexing system you use in your answer to avoid confusion.
Output:
The Gryphon number corresponding to the input.
Test Cases:
Please note that this assumes the sequence is 0-indexed. If your program assumes a 1-indexed sequence, don't forget to increment all the input numbers.
Input: Output:
0 ---> 6
3 ---> 20
4 ---> 30
10 ---> 84
Scoring:
This is code-golf, so the lowest score in bytes wins.
code-golf sequence
code-golf sequence
edited 1 hour ago
Giuseppe
17.9k31155
17.9k31155
asked 1 hour ago
GryphonGryphon
3,57912165
3,57912165
3
$begingroup$
How about bigger test cases like 2000 or 10000?
$endgroup$
– J42161217
1 hour ago
add a comment |
3
$begingroup$
How about bigger test cases like 2000 or 10000?
$endgroup$
– J42161217
1 hour ago
3
3
$begingroup$
How about bigger test cases like 2000 or 10000?
$endgroup$
– J42161217
1 hour ago
$begingroup$
How about bigger test cases like 2000 or 10000?
$endgroup$
– J42161217
1 hour ago
add a comment |
5 Answers
5
active
oldest
votes
$begingroup$
MATL, 16 13 bytes
:Qtt!^Ys+uSG)
1-based.
Try it online!
Explanation
Consider input n = 3
as an example.
: % Implicit input: n. Range
% STACK: [1 2 3]
Q % Add 1, element-wise
% STACK: [2 3 4]
tt % Duplicate twice, transpose
% STACK: [2 3 4], [2 3 4], [2;
3;
4]
^ % Power, element-wise with broadcast
% STACK: [2 3 4], [ 4 9 16;
8 27 64;
16 81 256]
Ys % Cumulative sum of each column
% STACK: [2 3 4], [ 4 9 16;
12 36 80;
28 117 336]
+ % Add, element-wise with broadcast (*)
% STACK: [ 6 12 20;
14 39 84
30 120 340]
u % Unique elements. Gives a column vector
% STACK: [ 6;
14;
30;
12;
···
340]
S % Sort
% STACK: [ 6;
12
14;
20;
···
340]
G) % Push input again, index. This gets the n-th element. Implicit display
% STACK: 14
The matrix obtained in step (*) contains possibly repeated Gryphon numbers. In particular, it contains n
distinct Gryphon numbers in its first row. These are not necessarily the n
smallest Gryphon numbers. However, the lower-left entry 2+2^+···+2^n
exceeds the upper-right entry n+n^2
, and thus all the numbers in the last row exceed those in the first row. This implies that extending the matrix rightward or downward would not contribute any Gryphon number lower than the lowest n
numbers in the matrix. Therefore, the matrix is guaranteed to contain the n
smallest Gryphon numbers. Consequently, its n
-th lowest unique element is the solution.
$endgroup$
1
$begingroup$
What the hell, this is amazing!
$endgroup$
– IQuick 143
59 mins ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 59 bytes
Union[Join@@Table[Sum[n^k,k,j],j,2,30,n,2,7!2]][[#]]&
Try it online!
1-indexed
$endgroup$
add a comment |
$begingroup$
Jelly, 9 bytes
bṖ’ḅi-µ#Ṫ
A full program which reads a (1-indexed) integer from STDIN and prints the result.
Try it online!
How?
A Gryphon number is a number which is expressible in a base less than itself such that all the digits are ones except the least significant, which is a zero. For example:
$30=1times 2^4+1times 2^3+1times2^2+1times2^1+0times2^0$
$84=1times 4^3+1times 4^2+1times 4^1+0times 4^0$
This program takes n
, then starts at v=0
and tests for this property and increments v
until it finds n
such numbers, then outputs the final one:
bṖ’ḅi-µ#Ṫ - Main Link: no arguments
# - set v=0 then count up collecting n=STDIN matches of:
µ - the monadic link -- i.e. f(v): e.g. v=6
Ṗ - pop (implicit range of v) [1,2,3,4,5]
b - to base (vectorises) [[1,1,1,1,1,1],[1,1,0],[2,0],[1,2],[1,1]]
’ - decrement (vectorises) [[0,0,0,0,0,0],[0,0,-1],[1,-1],[0,1],[0,0]]
ḅ - from base (v) (vectorises) [0,-1,5,1,0]
- - literal -1 -1
i - first index of (zero if not found) 2
- } e.g. n=11 -> [6,12,14,20,30,39,42,56,62,72,84]
Ṫ - tail -> 84
- implicit print
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 89 bytes
1-indexed.
n=>eval('for(a=[i=1e4];--i>1;)for(s=1e8+i,x=1;a[s+=i**++x]=x<26;);Object.keys(a)[n]-1e8')
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 65 bytes
n=scan();unique(sort(apply(outer(2:n,1:n,"^"),1,cumsum)[-1,]))[n]
Try it online!
1-indexed.
Generates a matrix of all values of the form $a^i$, takes the cumulative sum, removes the entries corresponding to $x=1$ (first row), then takes the unique sorted values.
Note that sort(unique(...))
would not work, as unique
would give unique rows of the matrix, and not unique entries. Using unique(sort(...))
works because sort
converts to vector.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/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%2f183491%2fthe-nth-gryphon-number%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
MATL, 16 13 bytes
:Qtt!^Ys+uSG)
1-based.
Try it online!
Explanation
Consider input n = 3
as an example.
: % Implicit input: n. Range
% STACK: [1 2 3]
Q % Add 1, element-wise
% STACK: [2 3 4]
tt % Duplicate twice, transpose
% STACK: [2 3 4], [2 3 4], [2;
3;
4]
^ % Power, element-wise with broadcast
% STACK: [2 3 4], [ 4 9 16;
8 27 64;
16 81 256]
Ys % Cumulative sum of each column
% STACK: [2 3 4], [ 4 9 16;
12 36 80;
28 117 336]
+ % Add, element-wise with broadcast (*)
% STACK: [ 6 12 20;
14 39 84
30 120 340]
u % Unique elements. Gives a column vector
% STACK: [ 6;
14;
30;
12;
···
340]
S % Sort
% STACK: [ 6;
12
14;
20;
···
340]
G) % Push input again, index. This gets the n-th element. Implicit display
% STACK: 14
The matrix obtained in step (*) contains possibly repeated Gryphon numbers. In particular, it contains n
distinct Gryphon numbers in its first row. These are not necessarily the n
smallest Gryphon numbers. However, the lower-left entry 2+2^+···+2^n
exceeds the upper-right entry n+n^2
, and thus all the numbers in the last row exceed those in the first row. This implies that extending the matrix rightward or downward would not contribute any Gryphon number lower than the lowest n
numbers in the matrix. Therefore, the matrix is guaranteed to contain the n
smallest Gryphon numbers. Consequently, its n
-th lowest unique element is the solution.
$endgroup$
1
$begingroup$
What the hell, this is amazing!
$endgroup$
– IQuick 143
59 mins ago
add a comment |
$begingroup$
MATL, 16 13 bytes
:Qtt!^Ys+uSG)
1-based.
Try it online!
Explanation
Consider input n = 3
as an example.
: % Implicit input: n. Range
% STACK: [1 2 3]
Q % Add 1, element-wise
% STACK: [2 3 4]
tt % Duplicate twice, transpose
% STACK: [2 3 4], [2 3 4], [2;
3;
4]
^ % Power, element-wise with broadcast
% STACK: [2 3 4], [ 4 9 16;
8 27 64;
16 81 256]
Ys % Cumulative sum of each column
% STACK: [2 3 4], [ 4 9 16;
12 36 80;
28 117 336]
+ % Add, element-wise with broadcast (*)
% STACK: [ 6 12 20;
14 39 84
30 120 340]
u % Unique elements. Gives a column vector
% STACK: [ 6;
14;
30;
12;
···
340]
S % Sort
% STACK: [ 6;
12
14;
20;
···
340]
G) % Push input again, index. This gets the n-th element. Implicit display
% STACK: 14
The matrix obtained in step (*) contains possibly repeated Gryphon numbers. In particular, it contains n
distinct Gryphon numbers in its first row. These are not necessarily the n
smallest Gryphon numbers. However, the lower-left entry 2+2^+···+2^n
exceeds the upper-right entry n+n^2
, and thus all the numbers in the last row exceed those in the first row. This implies that extending the matrix rightward or downward would not contribute any Gryphon number lower than the lowest n
numbers in the matrix. Therefore, the matrix is guaranteed to contain the n
smallest Gryphon numbers. Consequently, its n
-th lowest unique element is the solution.
$endgroup$
1
$begingroup$
What the hell, this is amazing!
$endgroup$
– IQuick 143
59 mins ago
add a comment |
$begingroup$
MATL, 16 13 bytes
:Qtt!^Ys+uSG)
1-based.
Try it online!
Explanation
Consider input n = 3
as an example.
: % Implicit input: n. Range
% STACK: [1 2 3]
Q % Add 1, element-wise
% STACK: [2 3 4]
tt % Duplicate twice, transpose
% STACK: [2 3 4], [2 3 4], [2;
3;
4]
^ % Power, element-wise with broadcast
% STACK: [2 3 4], [ 4 9 16;
8 27 64;
16 81 256]
Ys % Cumulative sum of each column
% STACK: [2 3 4], [ 4 9 16;
12 36 80;
28 117 336]
+ % Add, element-wise with broadcast (*)
% STACK: [ 6 12 20;
14 39 84
30 120 340]
u % Unique elements. Gives a column vector
% STACK: [ 6;
14;
30;
12;
···
340]
S % Sort
% STACK: [ 6;
12
14;
20;
···
340]
G) % Push input again, index. This gets the n-th element. Implicit display
% STACK: 14
The matrix obtained in step (*) contains possibly repeated Gryphon numbers. In particular, it contains n
distinct Gryphon numbers in its first row. These are not necessarily the n
smallest Gryphon numbers. However, the lower-left entry 2+2^+···+2^n
exceeds the upper-right entry n+n^2
, and thus all the numbers in the last row exceed those in the first row. This implies that extending the matrix rightward or downward would not contribute any Gryphon number lower than the lowest n
numbers in the matrix. Therefore, the matrix is guaranteed to contain the n
smallest Gryphon numbers. Consequently, its n
-th lowest unique element is the solution.
$endgroup$
MATL, 16 13 bytes
:Qtt!^Ys+uSG)
1-based.
Try it online!
Explanation
Consider input n = 3
as an example.
: % Implicit input: n. Range
% STACK: [1 2 3]
Q % Add 1, element-wise
% STACK: [2 3 4]
tt % Duplicate twice, transpose
% STACK: [2 3 4], [2 3 4], [2;
3;
4]
^ % Power, element-wise with broadcast
% STACK: [2 3 4], [ 4 9 16;
8 27 64;
16 81 256]
Ys % Cumulative sum of each column
% STACK: [2 3 4], [ 4 9 16;
12 36 80;
28 117 336]
+ % Add, element-wise with broadcast (*)
% STACK: [ 6 12 20;
14 39 84
30 120 340]
u % Unique elements. Gives a column vector
% STACK: [ 6;
14;
30;
12;
···
340]
S % Sort
% STACK: [ 6;
12
14;
20;
···
340]
G) % Push input again, index. This gets the n-th element. Implicit display
% STACK: 14
The matrix obtained in step (*) contains possibly repeated Gryphon numbers. In particular, it contains n
distinct Gryphon numbers in its first row. These are not necessarily the n
smallest Gryphon numbers. However, the lower-left entry 2+2^+···+2^n
exceeds the upper-right entry n+n^2
, and thus all the numbers in the last row exceed those in the first row. This implies that extending the matrix rightward or downward would not contribute any Gryphon number lower than the lowest n
numbers in the matrix. Therefore, the matrix is guaranteed to contain the n
smallest Gryphon numbers. Consequently, its n
-th lowest unique element is the solution.
edited 19 mins ago
answered 1 hour ago
Luis MendoLuis Mendo
75.4k889293
75.4k889293
1
$begingroup$
What the hell, this is amazing!
$endgroup$
– IQuick 143
59 mins ago
add a comment |
1
$begingroup$
What the hell, this is amazing!
$endgroup$
– IQuick 143
59 mins ago
1
1
$begingroup$
What the hell, this is amazing!
$endgroup$
– IQuick 143
59 mins ago
$begingroup$
What the hell, this is amazing!
$endgroup$
– IQuick 143
59 mins ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 59 bytes
Union[Join@@Table[Sum[n^k,k,j],j,2,30,n,2,7!2]][[#]]&
Try it online!
1-indexed
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 59 bytes
Union[Join@@Table[Sum[n^k,k,j],j,2,30,n,2,7!2]][[#]]&
Try it online!
1-indexed
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 59 bytes
Union[Join@@Table[Sum[n^k,k,j],j,2,30,n,2,7!2]][[#]]&
Try it online!
1-indexed
$endgroup$
Wolfram Language (Mathematica), 59 bytes
Union[Join@@Table[Sum[n^k,k,j],j,2,30,n,2,7!2]][[#]]&
Try it online!
1-indexed
answered 1 hour ago
J42161217J42161217
14.2k21353
14.2k21353
add a comment |
add a comment |
$begingroup$
Jelly, 9 bytes
bṖ’ḅi-µ#Ṫ
A full program which reads a (1-indexed) integer from STDIN and prints the result.
Try it online!
How?
A Gryphon number is a number which is expressible in a base less than itself such that all the digits are ones except the least significant, which is a zero. For example:
$30=1times 2^4+1times 2^3+1times2^2+1times2^1+0times2^0$
$84=1times 4^3+1times 4^2+1times 4^1+0times 4^0$
This program takes n
, then starts at v=0
and tests for this property and increments v
until it finds n
such numbers, then outputs the final one:
bṖ’ḅi-µ#Ṫ - Main Link: no arguments
# - set v=0 then count up collecting n=STDIN matches of:
µ - the monadic link -- i.e. f(v): e.g. v=6
Ṗ - pop (implicit range of v) [1,2,3,4,5]
b - to base (vectorises) [[1,1,1,1,1,1],[1,1,0],[2,0],[1,2],[1,1]]
’ - decrement (vectorises) [[0,0,0,0,0,0],[0,0,-1],[1,-1],[0,1],[0,0]]
ḅ - from base (v) (vectorises) [0,-1,5,1,0]
- - literal -1 -1
i - first index of (zero if not found) 2
- } e.g. n=11 -> [6,12,14,20,30,39,42,56,62,72,84]
Ṫ - tail -> 84
- implicit print
$endgroup$
add a comment |
$begingroup$
Jelly, 9 bytes
bṖ’ḅi-µ#Ṫ
A full program which reads a (1-indexed) integer from STDIN and prints the result.
Try it online!
How?
A Gryphon number is a number which is expressible in a base less than itself such that all the digits are ones except the least significant, which is a zero. For example:
$30=1times 2^4+1times 2^3+1times2^2+1times2^1+0times2^0$
$84=1times 4^3+1times 4^2+1times 4^1+0times 4^0$
This program takes n
, then starts at v=0
and tests for this property and increments v
until it finds n
such numbers, then outputs the final one:
bṖ’ḅi-µ#Ṫ - Main Link: no arguments
# - set v=0 then count up collecting n=STDIN matches of:
µ - the monadic link -- i.e. f(v): e.g. v=6
Ṗ - pop (implicit range of v) [1,2,3,4,5]
b - to base (vectorises) [[1,1,1,1,1,1],[1,1,0],[2,0],[1,2],[1,1]]
’ - decrement (vectorises) [[0,0,0,0,0,0],[0,0,-1],[1,-1],[0,1],[0,0]]
ḅ - from base (v) (vectorises) [0,-1,5,1,0]
- - literal -1 -1
i - first index of (zero if not found) 2
- } e.g. n=11 -> [6,12,14,20,30,39,42,56,62,72,84]
Ṫ - tail -> 84
- implicit print
$endgroup$
add a comment |
$begingroup$
Jelly, 9 bytes
bṖ’ḅi-µ#Ṫ
A full program which reads a (1-indexed) integer from STDIN and prints the result.
Try it online!
How?
A Gryphon number is a number which is expressible in a base less than itself such that all the digits are ones except the least significant, which is a zero. For example:
$30=1times 2^4+1times 2^3+1times2^2+1times2^1+0times2^0$
$84=1times 4^3+1times 4^2+1times 4^1+0times 4^0$
This program takes n
, then starts at v=0
and tests for this property and increments v
until it finds n
such numbers, then outputs the final one:
bṖ’ḅi-µ#Ṫ - Main Link: no arguments
# - set v=0 then count up collecting n=STDIN matches of:
µ - the monadic link -- i.e. f(v): e.g. v=6
Ṗ - pop (implicit range of v) [1,2,3,4,5]
b - to base (vectorises) [[1,1,1,1,1,1],[1,1,0],[2,0],[1,2],[1,1]]
’ - decrement (vectorises) [[0,0,0,0,0,0],[0,0,-1],[1,-1],[0,1],[0,0]]
ḅ - from base (v) (vectorises) [0,-1,5,1,0]
- - literal -1 -1
i - first index of (zero if not found) 2
- } e.g. n=11 -> [6,12,14,20,30,39,42,56,62,72,84]
Ṫ - tail -> 84
- implicit print
$endgroup$
Jelly, 9 bytes
bṖ’ḅi-µ#Ṫ
A full program which reads a (1-indexed) integer from STDIN and prints the result.
Try it online!
How?
A Gryphon number is a number which is expressible in a base less than itself such that all the digits are ones except the least significant, which is a zero. For example:
$30=1times 2^4+1times 2^3+1times2^2+1times2^1+0times2^0$
$84=1times 4^3+1times 4^2+1times 4^1+0times 4^0$
This program takes n
, then starts at v=0
and tests for this property and increments v
until it finds n
such numbers, then outputs the final one:
bṖ’ḅi-µ#Ṫ - Main Link: no arguments
# - set v=0 then count up collecting n=STDIN matches of:
µ - the monadic link -- i.e. f(v): e.g. v=6
Ṗ - pop (implicit range of v) [1,2,3,4,5]
b - to base (vectorises) [[1,1,1,1,1,1],[1,1,0],[2,0],[1,2],[1,1]]
’ - decrement (vectorises) [[0,0,0,0,0,0],[0,0,-1],[1,-1],[0,1],[0,0]]
ḅ - from base (v) (vectorises) [0,-1,5,1,0]
- - literal -1 -1
i - first index of (zero if not found) 2
- } e.g. n=11 -> [6,12,14,20,30,39,42,56,62,72,84]
Ṫ - tail -> 84
- implicit print
edited 6 mins ago
answered 27 mins ago
Jonathan AllanJonathan Allan
54.5k537174
54.5k537174
add a comment |
add a comment |
$begingroup$
JavaScript (ES7), 89 bytes
1-indexed.
n=>eval('for(a=[i=1e4];--i>1;)for(s=1e8+i,x=1;a[s+=i**++x]=x<26;);Object.keys(a)[n]-1e8')
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 89 bytes
1-indexed.
n=>eval('for(a=[i=1e4];--i>1;)for(s=1e8+i,x=1;a[s+=i**++x]=x<26;);Object.keys(a)[n]-1e8')
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 89 bytes
1-indexed.
n=>eval('for(a=[i=1e4];--i>1;)for(s=1e8+i,x=1;a[s+=i**++x]=x<26;);Object.keys(a)[n]-1e8')
Try it online!
$endgroup$
JavaScript (ES7), 89 bytes
1-indexed.
n=>eval('for(a=[i=1e4];--i>1;)for(s=1e8+i,x=1;a[s+=i**++x]=x<26;);Object.keys(a)[n]-1e8')
Try it online!
answered 15 mins ago
ArnauldArnauld
81.6k797336
81.6k797336
add a comment |
add a comment |
$begingroup$
R, 65 bytes
n=scan();unique(sort(apply(outer(2:n,1:n,"^"),1,cumsum)[-1,]))[n]
Try it online!
1-indexed.
Generates a matrix of all values of the form $a^i$, takes the cumulative sum, removes the entries corresponding to $x=1$ (first row), then takes the unique sorted values.
Note that sort(unique(...))
would not work, as unique
would give unique rows of the matrix, and not unique entries. Using unique(sort(...))
works because sort
converts to vector.
$endgroup$
add a comment |
$begingroup$
R, 65 bytes
n=scan();unique(sort(apply(outer(2:n,1:n,"^"),1,cumsum)[-1,]))[n]
Try it online!
1-indexed.
Generates a matrix of all values of the form $a^i$, takes the cumulative sum, removes the entries corresponding to $x=1$ (first row), then takes the unique sorted values.
Note that sort(unique(...))
would not work, as unique
would give unique rows of the matrix, and not unique entries. Using unique(sort(...))
works because sort
converts to vector.
$endgroup$
add a comment |
$begingroup$
R, 65 bytes
n=scan();unique(sort(apply(outer(2:n,1:n,"^"),1,cumsum)[-1,]))[n]
Try it online!
1-indexed.
Generates a matrix of all values of the form $a^i$, takes the cumulative sum, removes the entries corresponding to $x=1$ (first row), then takes the unique sorted values.
Note that sort(unique(...))
would not work, as unique
would give unique rows of the matrix, and not unique entries. Using unique(sort(...))
works because sort
converts to vector.
$endgroup$
R, 65 bytes
n=scan();unique(sort(apply(outer(2:n,1:n,"^"),1,cumsum)[-1,]))[n]
Try it online!
1-indexed.
Generates a matrix of all values of the form $a^i$, takes the cumulative sum, removes the entries corresponding to $x=1$ (first row), then takes the unique sorted values.
Note that sort(unique(...))
would not work, as unique
would give unique rows of the matrix, and not unique entries. Using unique(sort(...))
works because sort
converts to vector.
answered 26 secs ago
Robin RyderRobin Ryder
84112
84112
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%2f183491%2fthe-nth-gryphon-number%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
3
$begingroup$
How about bigger test cases like 2000 or 10000?
$endgroup$
– J42161217
1 hour ago