A Note on N!Pseudo-cyclic Number EvaluatorFind the remaining side of the tangential...
Examples of subgroups where it's nontrivial to show closure under multiplication?
Why other Westeros houses don't use wildfire?
US visa is under administrative processing, I need the passport back ASAP
How can I place the product on a social media post better?
With a Canadian student visa, can I spend a night at Vancouver before continuing to Toronto?
How to verbalise code in Mathematica?
How to reduce LED flash rate (frequency)
What happened to Captain America in Endgame?
How can I practically buy stocks?
What's the polite way to say "I need to urinate"?
How could Tony Stark make this in Endgame?
How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?
Do I have to worry about players making “bad” choices on level up?
Can SQL Server create collisions in system generated constraint names?
Don’t seats that recline flat defeat the purpose of having seatbelts?
Exchange,swap or switch
Binary Numbers Magic Trick
Why do Computer Science majors learn Calculus?
what is the sudo password for a --disabled-password user
Does holding a wand and speaking its command word count as V/S/M spell components?
how to find the equation of a circle given points of the circle
Fizzy, soft, pop and still drinks
Was there a Viking Exchange as well as a Columbian one?
How to solve constants out of the internal energy equation?
A Note on N!
Pseudo-cyclic Number EvaluatorFind the remaining side of the tangential quadrilateralSelf Referential PolynomialsInverse Pi functionClosest Woodall PrimeFactorials and never ending cycles!Do two numbers contain unique factorials?Additional facts!prepend,append-SequenceExact Partial Sum of Harmonic Series
$begingroup$
J. E. Maxfield proved following theorem (see DOI: 10.2307/2688966):
If $A$ is any positive integer having $m$ digits, there exists a positive integer $N$ such that the first $m$ digits of $N!$ constitute the integer $A$.
Challenge
Your challenge is given some $A geqslant 1$ find a corresponding $N geqslant 1$.
Details
$N!$ represents the factorial $N! = 1cdot 2 cdot 3cdot ldots cdot N$ of $N$.- The digits of $A$ in our case are understood to be in base $10$.
- Your submission should work for arbitrary $Ageqslant 1$ given enough time and memory. Just using e.g. 32-bit types to represent integers is not sufficient.
- You don't necessarily need to output the least possible $N$.
Examples
A N
1 1
2 2
3 9
4 8
5 7
6 3
7 6
9 96
12 5
16 89
17 69
18 76
19 63
24 4
72 6
841 12745
206591378 314
The least possible $N$ for each $A$ can be found in https://oeis.org/A076219
code-golf math number integer factorial
$endgroup$
|
show 14 more comments
$begingroup$
J. E. Maxfield proved following theorem (see DOI: 10.2307/2688966):
If $A$ is any positive integer having $m$ digits, there exists a positive integer $N$ such that the first $m$ digits of $N!$ constitute the integer $A$.
Challenge
Your challenge is given some $A geqslant 1$ find a corresponding $N geqslant 1$.
Details
$N!$ represents the factorial $N! = 1cdot 2 cdot 3cdot ldots cdot N$ of $N$.- The digits of $A$ in our case are understood to be in base $10$.
- Your submission should work for arbitrary $Ageqslant 1$ given enough time and memory. Just using e.g. 32-bit types to represent integers is not sufficient.
- You don't necessarily need to output the least possible $N$.
Examples
A N
1 1
2 2
3 9
4 8
5 7
6 3
7 6
9 96
12 5
16 89
17 69
18 76
19 63
24 4
72 6
841 12745
206591378 314
The least possible $N$ for each $A$ can be found in https://oeis.org/A076219
code-golf math number integer factorial
$endgroup$
22
$begingroup$
I... why did he prove that theorem? Did he just wake up one day and say "I shall solve this!" or did it serve a purpose?
$endgroup$
– Magic Octopus Urn
2 days ago
5
$begingroup$
Can we return0
for input1
? Lynn's answer currently does.
$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko My question is whether we're actually required to output a positive integer or not, though, that quote itself isn't really enough to specify that, and nowhere does it say that the test cases include the least possible output for each input.
$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko Yes, "positive" excludes 0, but, again, nowhere in the challenge does it say that the output must be positive. Well, technically, it does restrict the output, but you really need to see into the details to figure that out (the challenge text also uses the "N" variable), so it's not at all clear if OP actually intended to restrict the output to the positive integers or if we can output0
for input1
as well.
$endgroup$
– Erik the Outgolfer
2 days ago
6
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
yesterday
|
show 14 more comments
$begingroup$
J. E. Maxfield proved following theorem (see DOI: 10.2307/2688966):
If $A$ is any positive integer having $m$ digits, there exists a positive integer $N$ such that the first $m$ digits of $N!$ constitute the integer $A$.
Challenge
Your challenge is given some $A geqslant 1$ find a corresponding $N geqslant 1$.
Details
$N!$ represents the factorial $N! = 1cdot 2 cdot 3cdot ldots cdot N$ of $N$.- The digits of $A$ in our case are understood to be in base $10$.
- Your submission should work for arbitrary $Ageqslant 1$ given enough time and memory. Just using e.g. 32-bit types to represent integers is not sufficient.
- You don't necessarily need to output the least possible $N$.
Examples
A N
1 1
2 2
3 9
4 8
5 7
6 3
7 6
9 96
12 5
16 89
17 69
18 76
19 63
24 4
72 6
841 12745
206591378 314
The least possible $N$ for each $A$ can be found in https://oeis.org/A076219
code-golf math number integer factorial
$endgroup$
J. E. Maxfield proved following theorem (see DOI: 10.2307/2688966):
If $A$ is any positive integer having $m$ digits, there exists a positive integer $N$ such that the first $m$ digits of $N!$ constitute the integer $A$.
Challenge
Your challenge is given some $A geqslant 1$ find a corresponding $N geqslant 1$.
Details
$N!$ represents the factorial $N! = 1cdot 2 cdot 3cdot ldots cdot N$ of $N$.- The digits of $A$ in our case are understood to be in base $10$.
- Your submission should work for arbitrary $Ageqslant 1$ given enough time and memory. Just using e.g. 32-bit types to represent integers is not sufficient.
- You don't necessarily need to output the least possible $N$.
Examples
A N
1 1
2 2
3 9
4 8
5 7
6 3
7 6
9 96
12 5
16 89
17 69
18 76
19 63
24 4
72 6
841 12745
206591378 314
The least possible $N$ for each $A$ can be found in https://oeis.org/A076219
code-golf math number integer factorial
code-golf math number integer factorial
edited yesterday
flawr
asked 2 days ago
flawrflawr
27.6k669195
27.6k669195
22
$begingroup$
I... why did he prove that theorem? Did he just wake up one day and say "I shall solve this!" or did it serve a purpose?
$endgroup$
– Magic Octopus Urn
2 days ago
5
$begingroup$
Can we return0
for input1
? Lynn's answer currently does.
$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko My question is whether we're actually required to output a positive integer or not, though, that quote itself isn't really enough to specify that, and nowhere does it say that the test cases include the least possible output for each input.
$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko Yes, "positive" excludes 0, but, again, nowhere in the challenge does it say that the output must be positive. Well, technically, it does restrict the output, but you really need to see into the details to figure that out (the challenge text also uses the "N" variable), so it's not at all clear if OP actually intended to restrict the output to the positive integers or if we can output0
for input1
as well.
$endgroup$
– Erik the Outgolfer
2 days ago
6
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
yesterday
|
show 14 more comments
22
$begingroup$
I... why did he prove that theorem? Did he just wake up one day and say "I shall solve this!" or did it serve a purpose?
$endgroup$
– Magic Octopus Urn
2 days ago
5
$begingroup$
Can we return0
for input1
? Lynn's answer currently does.
$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko My question is whether we're actually required to output a positive integer or not, though, that quote itself isn't really enough to specify that, and nowhere does it say that the test cases include the least possible output for each input.
$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko Yes, "positive" excludes 0, but, again, nowhere in the challenge does it say that the output must be positive. Well, technically, it does restrict the output, but you really need to see into the details to figure that out (the challenge text also uses the "N" variable), so it's not at all clear if OP actually intended to restrict the output to the positive integers or if we can output0
for input1
as well.
$endgroup$
– Erik the Outgolfer
2 days ago
6
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
yesterday
22
22
$begingroup$
I... why did he prove that theorem? Did he just wake up one day and say "I shall solve this!" or did it serve a purpose?
$endgroup$
– Magic Octopus Urn
2 days ago
$begingroup$
I... why did he prove that theorem? Did he just wake up one day and say "I shall solve this!" or did it serve a purpose?
$endgroup$
– Magic Octopus Urn
2 days ago
5
5
$begingroup$
Can we return
0
for input 1
? Lynn's answer currently does.$endgroup$
– Erik the Outgolfer
2 days ago
$begingroup$
Can we return
0
for input 1
? Lynn's answer currently does.$endgroup$
– Erik the Outgolfer
2 days ago
5
5
$begingroup$
@SolomonUcko My question is whether we're actually required to output a positive integer or not, though, that quote itself isn't really enough to specify that, and nowhere does it say that the test cases include the least possible output for each input.
$endgroup$
– Erik the Outgolfer
2 days ago
$begingroup$
@SolomonUcko My question is whether we're actually required to output a positive integer or not, though, that quote itself isn't really enough to specify that, and nowhere does it say that the test cases include the least possible output for each input.
$endgroup$
– Erik the Outgolfer
2 days ago
5
5
$begingroup$
@SolomonUcko Yes, "positive" excludes 0, but, again, nowhere in the challenge does it say that the output must be positive. Well, technically, it does restrict the output, but you really need to see into the details to figure that out (the challenge text also uses the "N" variable), so it's not at all clear if OP actually intended to restrict the output to the positive integers or if we can output
0
for input 1
as well.$endgroup$
– Erik the Outgolfer
2 days ago
$begingroup$
@SolomonUcko Yes, "positive" excludes 0, but, again, nowhere in the challenge does it say that the output must be positive. Well, technically, it does restrict the output, but you really need to see into the details to figure that out (the challenge text also uses the "N" variable), so it's not at all clear if OP actually intended to restrict the output to the positive integers or if we can output
0
for input 1
as well.$endgroup$
– Erik the Outgolfer
2 days ago
6
6
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
yesterday
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
yesterday
|
show 14 more comments
20 Answers
20
active
oldest
votes
$begingroup$
Python 2, 50 bytes
f=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
Try it online!
This is a variation of the 47-byte solution explained below, adjusted to return 1
for input '1'
. (Namely, we add 1
to the full expression rather than the recursive call, and start counting from n==2
to remove one layer of depth, balancing the result out for all non-'1'
inputs.)
Python 2, 45 bytes (maps 1 to True
)
f=lambda a,n=2,p=1:`-a`in`-p`or-~f(a,n+1,p*n)
This is another variation, by @Jo King and @xnor, which takes input as a number and returns True
for input 1
. Some people think this is fair game, but I personally find it a little weird.
But it costs only 3 bytes to wrap the icky Boolean result in +()
, giving us a shorter "nice" solution:
Python 2, 48 bytes
f=lambda a,n=2,p=1:+(`-a`in`-p`)or-~f(a,n+1,p*n)
This is my previous solution, which returns
0
for input'1'
. It would have been valid if the question concerned a non-negativeN
.
Python 2, 47 bytes (invalid)
f=lambda a,n=1,p=1:`p`.find(a)and-~f(a,n+1,p*n)
Try it online!
Takes a string as input, like
f('18')
.
The trick here is that
x.find(y) == 0
precisely whenx.startswith(y)
.
The
and
-expression will short circuit at`p`.find(a)
with result0
as soon as`p`
starts witha
; otherwise, it will evaluate to-~f(a,n+1,p*n)
, id est1 + f(a,n+1,p*n)
.
The end result is
1 + (1 + (1 + (... + 0)))
,n
layers deep, son
.
$endgroup$
2
$begingroup$
@EriktheOutgolfer hmm, I can think off=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
, a +3 byte fix.
$endgroup$
– Lynn
2 days ago
$begingroup$
Nice solution by the way. I was working on the same method but calculating the factorial on each iteration; implementing your approach saved me a few bytes so+1
anyway.
$endgroup$
– Shaggy
2 days ago
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
18 hours ago
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
8 hours ago
add a comment |
$begingroup$
Brachylog, 3 5 bytes
ℕ₁ḟa₀
Try it online!
Takes input through its output variable, and outputs through its input variable. (The other way around, it just finds arbitrary prefixes of the input's factorial, which isn't quite as interesting.) Times out on the second-to-last test case on TIO, but does fine on the last one. I've been running it on 841 on my laptop for several minutes at the time of writing this, and it hasn't actually spit out an answer yet, but I have faith in it.
The (implicit) output variable
a₀ is a prefix of
ḟ the factorial of
the (implicit) input variable
ℕ₁ which is a positive integer.
Since the only input ḟa₀
doesn't work for is 1, and 1 is a positive prefix of 1! = 1, 1|ḟa₀
works just as well.
Also, as of this edit, 841 has been running for nearly three hours and it still hasn't produced an output. I guess computing the factorial of every integer from 1 to 12745 isn't exactly fast.
$endgroup$
2
$begingroup$
The implementation of the factorial predicate in Brachylog is a bit convoluted so that it can be used both ways with acceptable efficiency. One could implement a much faster algorithm to compute the factorial, but it would be extremely slow running the other way (i.e. finding the original number from the factorial).
$endgroup$
– Fatalize
yesterday
$begingroup$
Oh, cool! Looking at the source for it, I can't tell what all it's doing, but I can tell you put a lot of good thought into it.
$endgroup$
– Unrelated String
yesterday
add a comment |
$begingroup$
Jelly, 8 bytes
1!w⁼1ʋ1#
Try it online!
Takes an integer and returns a singleton.
$endgroup$
add a comment |
$begingroup$
05AB1E, 7 bytes
∞.Δ!IÅ?
Try it online or verify -almost- all test cases (841
times out, so is excluded).
Explanation:
∞.Δ # Find the first positive integer which is truthy for:
! # Get the factorial of the current integer
IÅ? # And check if it starts with the input
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
C++ (gcc), 107 95 bytes, using -lgmp
and -lgmpxx
Thanks to the people in the comments for pointing out some silly mishaps.
#import<gmpxx.h>
auto f(auto A){mpz_class n,x=1,z;for(;z!=A;)for(z=x*=++n;z>A;z/=10);return n;}
Try it online!
Computes $n!$ by multiplying $(n-1)!$ by $n$, then repeatedly divides it by $10$ until it is no longer greater than the passed integer. At this point, the loop terminates if the factorial equals the passed integer, or proceeds to the next $n$ otherwise.
$endgroup$
$begingroup$
You don't need to count flags anymore, so this is107
bytes.
$endgroup$
– AdmBorkBork
yesterday
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
yesterday
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
Pyth - 8 bytes
f!x`.!Tz
f filter. With no second arg, it searches 1.. for first truthy
! logical not, here it checks for zero
x z indexof. z is input as string
` string repr
.!T Factorial of lambda var
Try it online.
$endgroup$
add a comment |
$begingroup$
JavaScript, 47 43 bytes
Output as a BigInt.
n=>(g=x=>`${x}`.search(n)?g(x*++i):i)(i=1n)
Try It Online!
Saved a few bytes by taking Lynn's approach of "building" the factorial rather than calculating it on each iteration so please upvote her solution as well if you're upvoting this one.
$endgroup$
$begingroup$
Sadly,_Ês bU}f1
in Japt doesn't work
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
2 days ago
add a comment |
$begingroup$
C# (.NET Core), 69 + 22 = 91 bytes
a=>{var n=a/a;for(var b=n;!(b+"").StartsWith(a+"");b*=++n);return n;}
Try it online!
Uses System.Numerics.BigInteger
which requires a using
statement.
-1 byte thanks to @ExpiredData!
$endgroup$
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
yesterday
add a comment |
$begingroup$
Jelly, 16 bytes
‘ɼ!³;D®ß⁼Lḣ@¥¥/?
Try it online!
Explanation
‘ɼ | Increment the register (initially 0)
! | Factorial
³; | Prepend the input
D | Convert to decimal digits
⁼ ¥¥/? | If the input diguts are equal to...
Lḣ@ | The same number of diguts from the head of the factorial
® | Return the register
ß | Otherwise run the link again
$endgroup$
add a comment |
$begingroup$
Perl 6, 23 bytes
{+([*](1..*).../^$_/)}
Try it online!
Explanation
{ } # Anonymous code block
[*](1..*) # From the infinite list of factorials
... # Take up to the first element
/^$_/ # That starts with the input
+( ) # And return the length of the sequence
$endgroup$
add a comment |
$begingroup$
Charcoal, 16 bytes
⊞υ¹W⌕IΠυθ⊞υLυI⊟υ
Try it online! Link is to verbose version of code. Explanation:
⊞υ¹
Push 1
to the empty list so that it starts off with a defined product.
W⌕IΠυθ
Repeat while the input cannot be found at the beginning of the product of the list...
⊞υLυ
... push the length of the list to itself.
I⊟υ
Print the last value pushed to the list.
$endgroup$
add a comment |
$begingroup$
Perl 5 -Mbigint -p
, 25 bytes
1while($.*=++$)!~/^$_/}{
Try it online!
$endgroup$
add a comment |
$begingroup$
J, 28 22 bytes
-6 bytes thanks to FrownyFrog
(]+1-0{(E.&":!))^:_&1x
Try it online!
original answer J, 28 bytes
>:@]^:(-.@{.@E.&":!)^:_ x:@1
Try it online!
>:@] ... x:@1
starting with an extended precision1
, keep incrementing it while...
-.@
its not the case that...
{.@
the first elm is a starting match of...
E.&":
all the substring matches (after stringfying both arguments&":
) of searching for the original input in...
!
the factorial of the number we're incrementing
$endgroup$
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
yesterday
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
yesterday
add a comment |
$begingroup$
C (gcc) -lgmp, 161 bytes
#include"gmp.h"
f(a,n,_,b)char*a,*b;mpz_t n,_;{for(mpz_init_set_si(n,1),mpz_init_set(_,n);b=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n));}
Try it online!
$endgroup$
$begingroup$
Suggeststrstr(b=mpz_get_str(0,10,_),a)-b;mpz_mul(_,_,n))mpz_add_ui(n,n,1)
instead ofb=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n))
$endgroup$
– ceilingcat
yesterday
add a comment |
$begingroup$
Python 3, 61 bytes
lambda x,a=2,b=1:str(b).find(str(x))==0and a-1or f(x,a+1,b*a)
Try it online!
-24 bytes thanks to Jo King
-3 bytes thanks to Chas Brown
$endgroup$
$begingroup$
64 bytes
$endgroup$
– Jo King
2 days ago
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
61 bytes
$endgroup$
– Chas Brown
yesterday
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
yesterday
add a comment |
$begingroup$
Jelly, 11 bytes
‘ɼµ®!Dw³’µ¿
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 88 bytes
import StdEnv,Data.Integer,Text
$a=hd[n\n<-[a/a..]|startsWith(""<+a)(""<+prod[one..n])]
Try it online!
Defines $ :: Integer -> Integer
.
Uses Data.Integer
's arbitrary size integers for IO.
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 62 bytes
(b=1;While[⌊b!/10^((i=IntegerLength)[b!]-i@#)⌋!=#,b++];b)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 40 bytes
->n{a=b=1;a*=b+=1until"%d"%a=~/^#{n}/;b}
Try it online!
$endgroup$
add a comment |
$begingroup$
Icon, 65 63 bytes
procedure f(a);p:=1;every n:=seq()&1=find(a,p*:=n)&return n;end
Try it online!
$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%2f184776%2fa-note-on-n%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
20 Answers
20
active
oldest
votes
20 Answers
20
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 50 bytes
f=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
Try it online!
This is a variation of the 47-byte solution explained below, adjusted to return 1
for input '1'
. (Namely, we add 1
to the full expression rather than the recursive call, and start counting from n==2
to remove one layer of depth, balancing the result out for all non-'1'
inputs.)
Python 2, 45 bytes (maps 1 to True
)
f=lambda a,n=2,p=1:`-a`in`-p`or-~f(a,n+1,p*n)
This is another variation, by @Jo King and @xnor, which takes input as a number and returns True
for input 1
. Some people think this is fair game, but I personally find it a little weird.
But it costs only 3 bytes to wrap the icky Boolean result in +()
, giving us a shorter "nice" solution:
Python 2, 48 bytes
f=lambda a,n=2,p=1:+(`-a`in`-p`)or-~f(a,n+1,p*n)
This is my previous solution, which returns
0
for input'1'
. It would have been valid if the question concerned a non-negativeN
.
Python 2, 47 bytes (invalid)
f=lambda a,n=1,p=1:`p`.find(a)and-~f(a,n+1,p*n)
Try it online!
Takes a string as input, like
f('18')
.
The trick here is that
x.find(y) == 0
precisely whenx.startswith(y)
.
The
and
-expression will short circuit at`p`.find(a)
with result0
as soon as`p`
starts witha
; otherwise, it will evaluate to-~f(a,n+1,p*n)
, id est1 + f(a,n+1,p*n)
.
The end result is
1 + (1 + (1 + (... + 0)))
,n
layers deep, son
.
$endgroup$
2
$begingroup$
@EriktheOutgolfer hmm, I can think off=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
, a +3 byte fix.
$endgroup$
– Lynn
2 days ago
$begingroup$
Nice solution by the way. I was working on the same method but calculating the factorial on each iteration; implementing your approach saved me a few bytes so+1
anyway.
$endgroup$
– Shaggy
2 days ago
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
18 hours ago
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
8 hours ago
add a comment |
$begingroup$
Python 2, 50 bytes
f=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
Try it online!
This is a variation of the 47-byte solution explained below, adjusted to return 1
for input '1'
. (Namely, we add 1
to the full expression rather than the recursive call, and start counting from n==2
to remove one layer of depth, balancing the result out for all non-'1'
inputs.)
Python 2, 45 bytes (maps 1 to True
)
f=lambda a,n=2,p=1:`-a`in`-p`or-~f(a,n+1,p*n)
This is another variation, by @Jo King and @xnor, which takes input as a number and returns True
for input 1
. Some people think this is fair game, but I personally find it a little weird.
But it costs only 3 bytes to wrap the icky Boolean result in +()
, giving us a shorter "nice" solution:
Python 2, 48 bytes
f=lambda a,n=2,p=1:+(`-a`in`-p`)or-~f(a,n+1,p*n)
This is my previous solution, which returns
0
for input'1'
. It would have been valid if the question concerned a non-negativeN
.
Python 2, 47 bytes (invalid)
f=lambda a,n=1,p=1:`p`.find(a)and-~f(a,n+1,p*n)
Try it online!
Takes a string as input, like
f('18')
.
The trick here is that
x.find(y) == 0
precisely whenx.startswith(y)
.
The
and
-expression will short circuit at`p`.find(a)
with result0
as soon as`p`
starts witha
; otherwise, it will evaluate to-~f(a,n+1,p*n)
, id est1 + f(a,n+1,p*n)
.
The end result is
1 + (1 + (1 + (... + 0)))
,n
layers deep, son
.
$endgroup$
2
$begingroup$
@EriktheOutgolfer hmm, I can think off=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
, a +3 byte fix.
$endgroup$
– Lynn
2 days ago
$begingroup$
Nice solution by the way. I was working on the same method but calculating the factorial on each iteration; implementing your approach saved me a few bytes so+1
anyway.
$endgroup$
– Shaggy
2 days ago
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
18 hours ago
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
8 hours ago
add a comment |
$begingroup$
Python 2, 50 bytes
f=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
Try it online!
This is a variation of the 47-byte solution explained below, adjusted to return 1
for input '1'
. (Namely, we add 1
to the full expression rather than the recursive call, and start counting from n==2
to remove one layer of depth, balancing the result out for all non-'1'
inputs.)
Python 2, 45 bytes (maps 1 to True
)
f=lambda a,n=2,p=1:`-a`in`-p`or-~f(a,n+1,p*n)
This is another variation, by @Jo King and @xnor, which takes input as a number and returns True
for input 1
. Some people think this is fair game, but I personally find it a little weird.
But it costs only 3 bytes to wrap the icky Boolean result in +()
, giving us a shorter "nice" solution:
Python 2, 48 bytes
f=lambda a,n=2,p=1:+(`-a`in`-p`)or-~f(a,n+1,p*n)
This is my previous solution, which returns
0
for input'1'
. It would have been valid if the question concerned a non-negativeN
.
Python 2, 47 bytes (invalid)
f=lambda a,n=1,p=1:`p`.find(a)and-~f(a,n+1,p*n)
Try it online!
Takes a string as input, like
f('18')
.
The trick here is that
x.find(y) == 0
precisely whenx.startswith(y)
.
The
and
-expression will short circuit at`p`.find(a)
with result0
as soon as`p`
starts witha
; otherwise, it will evaluate to-~f(a,n+1,p*n)
, id est1 + f(a,n+1,p*n)
.
The end result is
1 + (1 + (1 + (... + 0)))
,n
layers deep, son
.
$endgroup$
Python 2, 50 bytes
f=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
Try it online!
This is a variation of the 47-byte solution explained below, adjusted to return 1
for input '1'
. (Namely, we add 1
to the full expression rather than the recursive call, and start counting from n==2
to remove one layer of depth, balancing the result out for all non-'1'
inputs.)
Python 2, 45 bytes (maps 1 to True
)
f=lambda a,n=2,p=1:`-a`in`-p`or-~f(a,n+1,p*n)
This is another variation, by @Jo King and @xnor, which takes input as a number and returns True
for input 1
. Some people think this is fair game, but I personally find it a little weird.
But it costs only 3 bytes to wrap the icky Boolean result in +()
, giving us a shorter "nice" solution:
Python 2, 48 bytes
f=lambda a,n=2,p=1:+(`-a`in`-p`)or-~f(a,n+1,p*n)
This is my previous solution, which returns
0
for input'1'
. It would have been valid if the question concerned a non-negativeN
.
Python 2, 47 bytes (invalid)
f=lambda a,n=1,p=1:`p`.find(a)and-~f(a,n+1,p*n)
Try it online!
Takes a string as input, like
f('18')
.
The trick here is that
x.find(y) == 0
precisely whenx.startswith(y)
.
The
and
-expression will short circuit at`p`.find(a)
with result0
as soon as`p`
starts witha
; otherwise, it will evaluate to-~f(a,n+1,p*n)
, id est1 + f(a,n+1,p*n)
.
The end result is
1 + (1 + (1 + (... + 0)))
,n
layers deep, son
.
edited 8 hours ago
answered 2 days ago
LynnLynn
51.5k899236
51.5k899236
2
$begingroup$
@EriktheOutgolfer hmm, I can think off=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
, a +3 byte fix.
$endgroup$
– Lynn
2 days ago
$begingroup$
Nice solution by the way. I was working on the same method but calculating the factorial on each iteration; implementing your approach saved me a few bytes so+1
anyway.
$endgroup$
– Shaggy
2 days ago
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
18 hours ago
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
8 hours ago
add a comment |
2
$begingroup$
@EriktheOutgolfer hmm, I can think off=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
, a +3 byte fix.
$endgroup$
– Lynn
2 days ago
$begingroup$
Nice solution by the way. I was working on the same method but calculating the factorial on each iteration; implementing your approach saved me a few bytes so+1
anyway.
$endgroup$
– Shaggy
2 days ago
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
18 hours ago
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
8 hours ago
2
2
$begingroup$
@EriktheOutgolfer hmm, I can think of
f=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
, a +3 byte fix.$endgroup$
– Lynn
2 days ago
$begingroup$
@EriktheOutgolfer hmm, I can think of
f=lambda a,n=2,p=1:(`p`.find(a)and f(a,n+1,p*n))+1
, a +3 byte fix.$endgroup$
– Lynn
2 days ago
$begingroup$
Nice solution by the way. I was working on the same method but calculating the factorial on each iteration; implementing your approach saved me a few bytes so
+1
anyway.$endgroup$
– Shaggy
2 days ago
$begingroup$
Nice solution by the way. I was working on the same method but calculating the factorial on each iteration; implementing your approach saved me a few bytes so
+1
anyway.$endgroup$
– Shaggy
2 days ago
1
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition taking
a
as a number.$endgroup$
– xnor
18 hours ago
$begingroup$
For your True-for-1 version, you can shorten the base case condition taking
a
as a number.$endgroup$
– xnor
18 hours ago
$begingroup$
@xnor I would have not thought of ``
-a
in-p
``, that's a neat trick :)$endgroup$
– Lynn
8 hours ago
$begingroup$
@xnor I would have not thought of ``
-a
in-p
``, that's a neat trick :)$endgroup$
– Lynn
8 hours ago
add a comment |
$begingroup$
Brachylog, 3 5 bytes
ℕ₁ḟa₀
Try it online!
Takes input through its output variable, and outputs through its input variable. (The other way around, it just finds arbitrary prefixes of the input's factorial, which isn't quite as interesting.) Times out on the second-to-last test case on TIO, but does fine on the last one. I've been running it on 841 on my laptop for several minutes at the time of writing this, and it hasn't actually spit out an answer yet, but I have faith in it.
The (implicit) output variable
a₀ is a prefix of
ḟ the factorial of
the (implicit) input variable
ℕ₁ which is a positive integer.
Since the only input ḟa₀
doesn't work for is 1, and 1 is a positive prefix of 1! = 1, 1|ḟa₀
works just as well.
Also, as of this edit, 841 has been running for nearly three hours and it still hasn't produced an output. I guess computing the factorial of every integer from 1 to 12745 isn't exactly fast.
$endgroup$
2
$begingroup$
The implementation of the factorial predicate in Brachylog is a bit convoluted so that it can be used both ways with acceptable efficiency. One could implement a much faster algorithm to compute the factorial, but it would be extremely slow running the other way (i.e. finding the original number from the factorial).
$endgroup$
– Fatalize
yesterday
$begingroup$
Oh, cool! Looking at the source for it, I can't tell what all it's doing, but I can tell you put a lot of good thought into it.
$endgroup$
– Unrelated String
yesterday
add a comment |
$begingroup$
Brachylog, 3 5 bytes
ℕ₁ḟa₀
Try it online!
Takes input through its output variable, and outputs through its input variable. (The other way around, it just finds arbitrary prefixes of the input's factorial, which isn't quite as interesting.) Times out on the second-to-last test case on TIO, but does fine on the last one. I've been running it on 841 on my laptop for several minutes at the time of writing this, and it hasn't actually spit out an answer yet, but I have faith in it.
The (implicit) output variable
a₀ is a prefix of
ḟ the factorial of
the (implicit) input variable
ℕ₁ which is a positive integer.
Since the only input ḟa₀
doesn't work for is 1, and 1 is a positive prefix of 1! = 1, 1|ḟa₀
works just as well.
Also, as of this edit, 841 has been running for nearly three hours and it still hasn't produced an output. I guess computing the factorial of every integer from 1 to 12745 isn't exactly fast.
$endgroup$
2
$begingroup$
The implementation of the factorial predicate in Brachylog is a bit convoluted so that it can be used both ways with acceptable efficiency. One could implement a much faster algorithm to compute the factorial, but it would be extremely slow running the other way (i.e. finding the original number from the factorial).
$endgroup$
– Fatalize
yesterday
$begingroup$
Oh, cool! Looking at the source for it, I can't tell what all it's doing, but I can tell you put a lot of good thought into it.
$endgroup$
– Unrelated String
yesterday
add a comment |
$begingroup$
Brachylog, 3 5 bytes
ℕ₁ḟa₀
Try it online!
Takes input through its output variable, and outputs through its input variable. (The other way around, it just finds arbitrary prefixes of the input's factorial, which isn't quite as interesting.) Times out on the second-to-last test case on TIO, but does fine on the last one. I've been running it on 841 on my laptop for several minutes at the time of writing this, and it hasn't actually spit out an answer yet, but I have faith in it.
The (implicit) output variable
a₀ is a prefix of
ḟ the factorial of
the (implicit) input variable
ℕ₁ which is a positive integer.
Since the only input ḟa₀
doesn't work for is 1, and 1 is a positive prefix of 1! = 1, 1|ḟa₀
works just as well.
Also, as of this edit, 841 has been running for nearly three hours and it still hasn't produced an output. I guess computing the factorial of every integer from 1 to 12745 isn't exactly fast.
$endgroup$
Brachylog, 3 5 bytes
ℕ₁ḟa₀
Try it online!
Takes input through its output variable, and outputs through its input variable. (The other way around, it just finds arbitrary prefixes of the input's factorial, which isn't quite as interesting.) Times out on the second-to-last test case on TIO, but does fine on the last one. I've been running it on 841 on my laptop for several minutes at the time of writing this, and it hasn't actually spit out an answer yet, but I have faith in it.
The (implicit) output variable
a₀ is a prefix of
ḟ the factorial of
the (implicit) input variable
ℕ₁ which is a positive integer.
Since the only input ḟa₀
doesn't work for is 1, and 1 is a positive prefix of 1! = 1, 1|ḟa₀
works just as well.
Also, as of this edit, 841 has been running for nearly three hours and it still hasn't produced an output. I guess computing the factorial of every integer from 1 to 12745 isn't exactly fast.
edited yesterday
answered yesterday
Unrelated StringUnrelated String
1,891312
1,891312
2
$begingroup$
The implementation of the factorial predicate in Brachylog is a bit convoluted so that it can be used both ways with acceptable efficiency. One could implement a much faster algorithm to compute the factorial, but it would be extremely slow running the other way (i.e. finding the original number from the factorial).
$endgroup$
– Fatalize
yesterday
$begingroup$
Oh, cool! Looking at the source for it, I can't tell what all it's doing, but I can tell you put a lot of good thought into it.
$endgroup$
– Unrelated String
yesterday
add a comment |
2
$begingroup$
The implementation of the factorial predicate in Brachylog is a bit convoluted so that it can be used both ways with acceptable efficiency. One could implement a much faster algorithm to compute the factorial, but it would be extremely slow running the other way (i.e. finding the original number from the factorial).
$endgroup$
– Fatalize
yesterday
$begingroup$
Oh, cool! Looking at the source for it, I can't tell what all it's doing, but I can tell you put a lot of good thought into it.
$endgroup$
– Unrelated String
yesterday
2
2
$begingroup$
The implementation of the factorial predicate in Brachylog is a bit convoluted so that it can be used both ways with acceptable efficiency. One could implement a much faster algorithm to compute the factorial, but it would be extremely slow running the other way (i.e. finding the original number from the factorial).
$endgroup$
– Fatalize
yesterday
$begingroup$
The implementation of the factorial predicate in Brachylog is a bit convoluted so that it can be used both ways with acceptable efficiency. One could implement a much faster algorithm to compute the factorial, but it would be extremely slow running the other way (i.e. finding the original number from the factorial).
$endgroup$
– Fatalize
yesterday
$begingroup$
Oh, cool! Looking at the source for it, I can't tell what all it's doing, but I can tell you put a lot of good thought into it.
$endgroup$
– Unrelated String
yesterday
$begingroup$
Oh, cool! Looking at the source for it, I can't tell what all it's doing, but I can tell you put a lot of good thought into it.
$endgroup$
– Unrelated String
yesterday
add a comment |
$begingroup$
Jelly, 8 bytes
1!w⁼1ʋ1#
Try it online!
Takes an integer and returns a singleton.
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1!w⁼1ʋ1#
Try it online!
Takes an integer and returns a singleton.
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1!w⁼1ʋ1#
Try it online!
Takes an integer and returns a singleton.
$endgroup$
Jelly, 8 bytes
1!w⁼1ʋ1#
Try it online!
Takes an integer and returns a singleton.
answered 2 days ago
Erik the OutgolferErik the Outgolfer
33.3k429106
33.3k429106
add a comment |
add a comment |
$begingroup$
05AB1E, 7 bytes
∞.Δ!IÅ?
Try it online or verify -almost- all test cases (841
times out, so is excluded).
Explanation:
∞.Δ # Find the first positive integer which is truthy for:
! # Get the factorial of the current integer
IÅ? # And check if it starts with the input
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 7 bytes
∞.Δ!IÅ?
Try it online or verify -almost- all test cases (841
times out, so is excluded).
Explanation:
∞.Δ # Find the first positive integer which is truthy for:
! # Get the factorial of the current integer
IÅ? # And check if it starts with the input
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 7 bytes
∞.Δ!IÅ?
Try it online or verify -almost- all test cases (841
times out, so is excluded).
Explanation:
∞.Δ # Find the first positive integer which is truthy for:
! # Get the factorial of the current integer
IÅ? # And check if it starts with the input
# (after which the result is output implicitly)
$endgroup$
05AB1E, 7 bytes
∞.Δ!IÅ?
Try it online or verify -almost- all test cases (841
times out, so is excluded).
Explanation:
∞.Δ # Find the first positive integer which is truthy for:
! # Get the factorial of the current integer
IÅ? # And check if it starts with the input
# (after which the result is output implicitly)
answered yesterday
Kevin CruijssenKevin Cruijssen
43.8k573223
43.8k573223
add a comment |
add a comment |
$begingroup$
C++ (gcc), 107 95 bytes, using -lgmp
and -lgmpxx
Thanks to the people in the comments for pointing out some silly mishaps.
#import<gmpxx.h>
auto f(auto A){mpz_class n,x=1,z;for(;z!=A;)for(z=x*=++n;z>A;z/=10);return n;}
Try it online!
Computes $n!$ by multiplying $(n-1)!$ by $n$, then repeatedly divides it by $10$ until it is no longer greater than the passed integer. At this point, the loop terminates if the factorial equals the passed integer, or proceeds to the next $n$ otherwise.
$endgroup$
$begingroup$
You don't need to count flags anymore, so this is107
bytes.
$endgroup$
– AdmBorkBork
yesterday
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
yesterday
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
C++ (gcc), 107 95 bytes, using -lgmp
and -lgmpxx
Thanks to the people in the comments for pointing out some silly mishaps.
#import<gmpxx.h>
auto f(auto A){mpz_class n,x=1,z;for(;z!=A;)for(z=x*=++n;z>A;z/=10);return n;}
Try it online!
Computes $n!$ by multiplying $(n-1)!$ by $n$, then repeatedly divides it by $10$ until it is no longer greater than the passed integer. At this point, the loop terminates if the factorial equals the passed integer, or proceeds to the next $n$ otherwise.
$endgroup$
$begingroup$
You don't need to count flags anymore, so this is107
bytes.
$endgroup$
– AdmBorkBork
yesterday
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
yesterday
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
C++ (gcc), 107 95 bytes, using -lgmp
and -lgmpxx
Thanks to the people in the comments for pointing out some silly mishaps.
#import<gmpxx.h>
auto f(auto A){mpz_class n,x=1,z;for(;z!=A;)for(z=x*=++n;z>A;z/=10);return n;}
Try it online!
Computes $n!$ by multiplying $(n-1)!$ by $n$, then repeatedly divides it by $10$ until it is no longer greater than the passed integer. At this point, the loop terminates if the factorial equals the passed integer, or proceeds to the next $n$ otherwise.
$endgroup$
C++ (gcc), 107 95 bytes, using -lgmp
and -lgmpxx
Thanks to the people in the comments for pointing out some silly mishaps.
#import<gmpxx.h>
auto f(auto A){mpz_class n,x=1,z;for(;z!=A;)for(z=x*=++n;z>A;z/=10);return n;}
Try it online!
Computes $n!$ by multiplying $(n-1)!$ by $n$, then repeatedly divides it by $10$ until it is no longer greater than the passed integer. At this point, the loop terminates if the factorial equals the passed integer, or proceeds to the next $n$ otherwise.
edited 3 hours ago
answered yesterday
Neil A.Neil A.
1,498120
1,498120
$begingroup$
You don't need to count flags anymore, so this is107
bytes.
$endgroup$
– AdmBorkBork
yesterday
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
yesterday
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
You don't need to count flags anymore, so this is107
bytes.
$endgroup$
– AdmBorkBork
yesterday
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
yesterday
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
yesterday
$begingroup$
You don't need to count flags anymore, so this is
107
bytes.$endgroup$
– AdmBorkBork
yesterday
$begingroup$
You don't need to count flags anymore, so this is
107
bytes.$endgroup$
– AdmBorkBork
yesterday
$begingroup$
Why do you need the second semicolon before
return
?$endgroup$
– Ruslan
yesterday
$begingroup$
Why do you need the second semicolon before
return
?$endgroup$
– Ruslan
yesterday
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
yesterday
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
Pyth - 8 bytes
f!x`.!Tz
f filter. With no second arg, it searches 1.. for first truthy
! logical not, here it checks for zero
x z indexof. z is input as string
` string repr
.!T Factorial of lambda var
Try it online.
$endgroup$
add a comment |
$begingroup$
Pyth - 8 bytes
f!x`.!Tz
f filter. With no second arg, it searches 1.. for first truthy
! logical not, here it checks for zero
x z indexof. z is input as string
` string repr
.!T Factorial of lambda var
Try it online.
$endgroup$
add a comment |
$begingroup$
Pyth - 8 bytes
f!x`.!Tz
f filter. With no second arg, it searches 1.. for first truthy
! logical not, here it checks for zero
x z indexof. z is input as string
` string repr
.!T Factorial of lambda var
Try it online.
$endgroup$
Pyth - 8 bytes
f!x`.!Tz
f filter. With no second arg, it searches 1.. for first truthy
! logical not, here it checks for zero
x z indexof. z is input as string
` string repr
.!T Factorial of lambda var
Try it online.
answered 2 days ago
MaltysenMaltysen
21.5k445118
21.5k445118
add a comment |
add a comment |
$begingroup$
JavaScript, 47 43 bytes
Output as a BigInt.
n=>(g=x=>`${x}`.search(n)?g(x*++i):i)(i=1n)
Try It Online!
Saved a few bytes by taking Lynn's approach of "building" the factorial rather than calculating it on each iteration so please upvote her solution as well if you're upvoting this one.
$endgroup$
$begingroup$
Sadly,_Ês bU}f1
in Japt doesn't work
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
2 days ago
add a comment |
$begingroup$
JavaScript, 47 43 bytes
Output as a BigInt.
n=>(g=x=>`${x}`.search(n)?g(x*++i):i)(i=1n)
Try It Online!
Saved a few bytes by taking Lynn's approach of "building" the factorial rather than calculating it on each iteration so please upvote her solution as well if you're upvoting this one.
$endgroup$
$begingroup$
Sadly,_Ês bU}f1
in Japt doesn't work
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
2 days ago
add a comment |
$begingroup$
JavaScript, 47 43 bytes
Output as a BigInt.
n=>(g=x=>`${x}`.search(n)?g(x*++i):i)(i=1n)
Try It Online!
Saved a few bytes by taking Lynn's approach of "building" the factorial rather than calculating it on each iteration so please upvote her solution as well if you're upvoting this one.
$endgroup$
JavaScript, 47 43 bytes
Output as a BigInt.
n=>(g=x=>`${x}`.search(n)?g(x*++i):i)(i=1n)
Try It Online!
Saved a few bytes by taking Lynn's approach of "building" the factorial rather than calculating it on each iteration so please upvote her solution as well if you're upvoting this one.
edited yesterday
answered 2 days ago
ShaggyShaggy
19.2k21768
19.2k21768
$begingroup$
Sadly,_Ês bU}f1
in Japt doesn't work
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
2 days ago
add a comment |
$begingroup$
Sadly,_Ês bU}f1
in Japt doesn't work
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
2 days ago
$begingroup$
Sadly,
_Ês bU}f1
in Japt doesn't work$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
Sadly,
_Ês bU}f1
in Japt doesn't work$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space after
s
.$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space after
s
.$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, you could also remove the
1
if 0
can be returned for n=1
.$endgroup$
– Shaggy
2 days ago
$begingroup$
@EmbodimentofIgnorance, you could also remove the
1
if 0
can be returned for n=1
.$endgroup$
– Shaggy
2 days ago
add a comment |
$begingroup$
C# (.NET Core), 69 + 22 = 91 bytes
a=>{var n=a/a;for(var b=n;!(b+"").StartsWith(a+"");b*=++n);return n;}
Try it online!
Uses System.Numerics.BigInteger
which requires a using
statement.
-1 byte thanks to @ExpiredData!
$endgroup$
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
yesterday
add a comment |
$begingroup$
C# (.NET Core), 69 + 22 = 91 bytes
a=>{var n=a/a;for(var b=n;!(b+"").StartsWith(a+"");b*=++n);return n;}
Try it online!
Uses System.Numerics.BigInteger
which requires a using
statement.
-1 byte thanks to @ExpiredData!
$endgroup$
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
yesterday
add a comment |
$begingroup$
C# (.NET Core), 69 + 22 = 91 bytes
a=>{var n=a/a;for(var b=n;!(b+"").StartsWith(a+"");b*=++n);return n;}
Try it online!
Uses System.Numerics.BigInteger
which requires a using
statement.
-1 byte thanks to @ExpiredData!
$endgroup$
C# (.NET Core), 69 + 22 = 91 bytes
a=>{var n=a/a;for(var b=n;!(b+"").StartsWith(a+"");b*=++n);return n;}
Try it online!
Uses System.Numerics.BigInteger
which requires a using
statement.
-1 byte thanks to @ExpiredData!
edited yesterday
answered yesterday
danadana
2,221168
2,221168
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
yesterday
add a comment |
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
yesterday
1
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
yesterday
$begingroup$
69 + 22
$endgroup$
– Expired Data
yesterday
add a comment |
$begingroup$
Jelly, 16 bytes
‘ɼ!³;D®ß⁼Lḣ@¥¥/?
Try it online!
Explanation
‘ɼ | Increment the register (initially 0)
! | Factorial
³; | Prepend the input
D | Convert to decimal digits
⁼ ¥¥/? | If the input diguts are equal to...
Lḣ@ | The same number of diguts from the head of the factorial
® | Return the register
ß | Otherwise run the link again
$endgroup$
add a comment |
$begingroup$
Jelly, 16 bytes
‘ɼ!³;D®ß⁼Lḣ@¥¥/?
Try it online!
Explanation
‘ɼ | Increment the register (initially 0)
! | Factorial
³; | Prepend the input
D | Convert to decimal digits
⁼ ¥¥/? | If the input diguts are equal to...
Lḣ@ | The same number of diguts from the head of the factorial
® | Return the register
ß | Otherwise run the link again
$endgroup$
add a comment |
$begingroup$
Jelly, 16 bytes
‘ɼ!³;D®ß⁼Lḣ@¥¥/?
Try it online!
Explanation
‘ɼ | Increment the register (initially 0)
! | Factorial
³; | Prepend the input
D | Convert to decimal digits
⁼ ¥¥/? | If the input diguts are equal to...
Lḣ@ | The same number of diguts from the head of the factorial
® | Return the register
ß | Otherwise run the link again
$endgroup$
Jelly, 16 bytes
‘ɼ!³;D®ß⁼Lḣ@¥¥/?
Try it online!
Explanation
‘ɼ | Increment the register (initially 0)
! | Factorial
³; | Prepend the input
D | Convert to decimal digits
⁼ ¥¥/? | If the input diguts are equal to...
Lḣ@ | The same number of diguts from the head of the factorial
® | Return the register
ß | Otherwise run the link again
edited 2 days ago
answered 2 days ago
Nick KennedyNick Kennedy
1,92159
1,92159
add a comment |
add a comment |
$begingroup$
Perl 6, 23 bytes
{+([*](1..*).../^$_/)}
Try it online!
Explanation
{ } # Anonymous code block
[*](1..*) # From the infinite list of factorials
... # Take up to the first element
/^$_/ # That starts with the input
+( ) # And return the length of the sequence
$endgroup$
add a comment |
$begingroup$
Perl 6, 23 bytes
{+([*](1..*).../^$_/)}
Try it online!
Explanation
{ } # Anonymous code block
[*](1..*) # From the infinite list of factorials
... # Take up to the first element
/^$_/ # That starts with the input
+( ) # And return the length of the sequence
$endgroup$
add a comment |
$begingroup$
Perl 6, 23 bytes
{+([*](1..*).../^$_/)}
Try it online!
Explanation
{ } # Anonymous code block
[*](1..*) # From the infinite list of factorials
... # Take up to the first element
/^$_/ # That starts with the input
+( ) # And return the length of the sequence
$endgroup$
Perl 6, 23 bytes
{+([*](1..*).../^$_/)}
Try it online!
Explanation
{ } # Anonymous code block
[*](1..*) # From the infinite list of factorials
... # Take up to the first element
/^$_/ # That starts with the input
+( ) # And return the length of the sequence
answered 2 days ago
Jo KingJo King
27.8k366134
27.8k366134
add a comment |
add a comment |
$begingroup$
Charcoal, 16 bytes
⊞υ¹W⌕IΠυθ⊞υLυI⊟υ
Try it online! Link is to verbose version of code. Explanation:
⊞υ¹
Push 1
to the empty list so that it starts off with a defined product.
W⌕IΠυθ
Repeat while the input cannot be found at the beginning of the product of the list...
⊞υLυ
... push the length of the list to itself.
I⊟υ
Print the last value pushed to the list.
$endgroup$
add a comment |
$begingroup$
Charcoal, 16 bytes
⊞υ¹W⌕IΠυθ⊞υLυI⊟υ
Try it online! Link is to verbose version of code. Explanation:
⊞υ¹
Push 1
to the empty list so that it starts off with a defined product.
W⌕IΠυθ
Repeat while the input cannot be found at the beginning of the product of the list...
⊞υLυ
... push the length of the list to itself.
I⊟υ
Print the last value pushed to the list.
$endgroup$
add a comment |
$begingroup$
Charcoal, 16 bytes
⊞υ¹W⌕IΠυθ⊞υLυI⊟υ
Try it online! Link is to verbose version of code. Explanation:
⊞υ¹
Push 1
to the empty list so that it starts off with a defined product.
W⌕IΠυθ
Repeat while the input cannot be found at the beginning of the product of the list...
⊞υLυ
... push the length of the list to itself.
I⊟υ
Print the last value pushed to the list.
$endgroup$
Charcoal, 16 bytes
⊞υ¹W⌕IΠυθ⊞υLυI⊟υ
Try it online! Link is to verbose version of code. Explanation:
⊞υ¹
Push 1
to the empty list so that it starts off with a defined product.
W⌕IΠυθ
Repeat while the input cannot be found at the beginning of the product of the list...
⊞υLυ
... push the length of the list to itself.
I⊟υ
Print the last value pushed to the list.
answered 2 days ago
NeilNeil
83.3k745179
83.3k745179
add a comment |
add a comment |
$begingroup$
Perl 5 -Mbigint -p
, 25 bytes
1while($.*=++$)!~/^$_/}{
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -Mbigint -p
, 25 bytes
1while($.*=++$)!~/^$_/}{
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -Mbigint -p
, 25 bytes
1while($.*=++$)!~/^$_/}{
Try it online!
$endgroup$
Perl 5 -Mbigint -p
, 25 bytes
1while($.*=++$)!~/^$_/}{
Try it online!
answered yesterday
XcaliXcali
5,605521
5,605521
add a comment |
add a comment |
$begingroup$
J, 28 22 bytes
-6 bytes thanks to FrownyFrog
(]+1-0{(E.&":!))^:_&1x
Try it online!
original answer J, 28 bytes
>:@]^:(-.@{.@E.&":!)^:_ x:@1
Try it online!
>:@] ... x:@1
starting with an extended precision1
, keep incrementing it while...
-.@
its not the case that...
{.@
the first elm is a starting match of...
E.&":
all the substring matches (after stringfying both arguments&":
) of searching for the original input in...
!
the factorial of the number we're incrementing
$endgroup$
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
yesterday
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
yesterday
add a comment |
$begingroup$
J, 28 22 bytes
-6 bytes thanks to FrownyFrog
(]+1-0{(E.&":!))^:_&1x
Try it online!
original answer J, 28 bytes
>:@]^:(-.@{.@E.&":!)^:_ x:@1
Try it online!
>:@] ... x:@1
starting with an extended precision1
, keep incrementing it while...
-.@
its not the case that...
{.@
the first elm is a starting match of...
E.&":
all the substring matches (after stringfying both arguments&":
) of searching for the original input in...
!
the factorial of the number we're incrementing
$endgroup$
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
yesterday
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
yesterday
add a comment |
$begingroup$
J, 28 22 bytes
-6 bytes thanks to FrownyFrog
(]+1-0{(E.&":!))^:_&1x
Try it online!
original answer J, 28 bytes
>:@]^:(-.@{.@E.&":!)^:_ x:@1
Try it online!
>:@] ... x:@1
starting with an extended precision1
, keep incrementing it while...
-.@
its not the case that...
{.@
the first elm is a starting match of...
E.&":
all the substring matches (after stringfying both arguments&":
) of searching for the original input in...
!
the factorial of the number we're incrementing
$endgroup$
J, 28 22 bytes
-6 bytes thanks to FrownyFrog
(]+1-0{(E.&":!))^:_&1x
Try it online!
original answer J, 28 bytes
>:@]^:(-.@{.@E.&":!)^:_ x:@1
Try it online!
>:@] ... x:@1
starting with an extended precision1
, keep incrementing it while...
-.@
its not the case that...
{.@
the first elm is a starting match of...
E.&":
all the substring matches (after stringfying both arguments&":
) of searching for the original input in...
!
the factorial of the number we're incrementing
edited yesterday
answered yesterday
JonahJonah
3,0781019
3,0781019
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
yesterday
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
yesterday
add a comment |
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
yesterday
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
yesterday
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
yesterday
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
yesterday
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
yesterday
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
yesterday
add a comment |
$begingroup$
C (gcc) -lgmp, 161 bytes
#include"gmp.h"
f(a,n,_,b)char*a,*b;mpz_t n,_;{for(mpz_init_set_si(n,1),mpz_init_set(_,n);b=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n));}
Try it online!
$endgroup$
$begingroup$
Suggeststrstr(b=mpz_get_str(0,10,_),a)-b;mpz_mul(_,_,n))mpz_add_ui(n,n,1)
instead ofb=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n))
$endgroup$
– ceilingcat
yesterday
add a comment |
$begingroup$
C (gcc) -lgmp, 161 bytes
#include"gmp.h"
f(a,n,_,b)char*a,*b;mpz_t n,_;{for(mpz_init_set_si(n,1),mpz_init_set(_,n);b=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n));}
Try it online!
$endgroup$
$begingroup$
Suggeststrstr(b=mpz_get_str(0,10,_),a)-b;mpz_mul(_,_,n))mpz_add_ui(n,n,1)
instead ofb=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n))
$endgroup$
– ceilingcat
yesterday
add a comment |
$begingroup$
C (gcc) -lgmp, 161 bytes
#include"gmp.h"
f(a,n,_,b)char*a,*b;mpz_t n,_;{for(mpz_init_set_si(n,1),mpz_init_set(_,n);b=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n));}
Try it online!
$endgroup$
C (gcc) -lgmp, 161 bytes
#include"gmp.h"
f(a,n,_,b)char*a,*b;mpz_t n,_;{for(mpz_init_set_si(n,1),mpz_init_set(_,n);b=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n));}
Try it online!
answered yesterday
LambdaBetaLambdaBeta
2,289418
2,289418
$begingroup$
Suggeststrstr(b=mpz_get_str(0,10,_),a)-b;mpz_mul(_,_,n))mpz_add_ui(n,n,1)
instead ofb=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n))
$endgroup$
– ceilingcat
yesterday
add a comment |
$begingroup$
Suggeststrstr(b=mpz_get_str(0,10,_),a)-b;mpz_mul(_,_,n))mpz_add_ui(n,n,1)
instead ofb=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n))
$endgroup$
– ceilingcat
yesterday
$begingroup$
Suggest
strstr(b=mpz_get_str(0,10,_),a)-b;mpz_mul(_,_,n))mpz_add_ui(n,n,1)
instead of b=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n))
$endgroup$
– ceilingcat
yesterday
$begingroup$
Suggest
strstr(b=mpz_get_str(0,10,_),a)-b;mpz_mul(_,_,n))mpz_add_ui(n,n,1)
instead of b=mpz_get_str(0,10,_),strstr(b,a)-b;mpz_add_ui(n,n,1),mpz_mul(_,_,n))
$endgroup$
– ceilingcat
yesterday
add a comment |
$begingroup$
Python 3, 61 bytes
lambda x,a=2,b=1:str(b).find(str(x))==0and a-1or f(x,a+1,b*a)
Try it online!
-24 bytes thanks to Jo King
-3 bytes thanks to Chas Brown
$endgroup$
$begingroup$
64 bytes
$endgroup$
– Jo King
2 days ago
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
61 bytes
$endgroup$
– Chas Brown
yesterday
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
yesterday
add a comment |
$begingroup$
Python 3, 61 bytes
lambda x,a=2,b=1:str(b).find(str(x))==0and a-1or f(x,a+1,b*a)
Try it online!
-24 bytes thanks to Jo King
-3 bytes thanks to Chas Brown
$endgroup$
$begingroup$
64 bytes
$endgroup$
– Jo King
2 days ago
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
61 bytes
$endgroup$
– Chas Brown
yesterday
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
yesterday
add a comment |
$begingroup$
Python 3, 61 bytes
lambda x,a=2,b=1:str(b).find(str(x))==0and a-1or f(x,a+1,b*a)
Try it online!
-24 bytes thanks to Jo King
-3 bytes thanks to Chas Brown
$endgroup$
Python 3, 61 bytes
lambda x,a=2,b=1:str(b).find(str(x))==0and a-1or f(x,a+1,b*a)
Try it online!
-24 bytes thanks to Jo King
-3 bytes thanks to Chas Brown
edited yesterday
answered 2 days ago
HyperNeutrinoHyperNeutrino
19.1k437148
19.1k437148
$begingroup$
64 bytes
$endgroup$
– Jo King
2 days ago
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
61 bytes
$endgroup$
– Chas Brown
yesterday
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
yesterday
add a comment |
$begingroup$
64 bytes
$endgroup$
– Jo King
2 days ago
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
61 bytes
$endgroup$
– Chas Brown
yesterday
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
64 bytes
$endgroup$
– Jo King
2 days ago
$begingroup$
64 bytes
$endgroup$
– Jo King
2 days ago
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
61 bytes
$endgroup$
– Chas Brown
yesterday
$begingroup$
61 bytes
$endgroup$
– Chas Brown
yesterday
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
yesterday
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
yesterday
add a comment |
$begingroup$
Jelly, 11 bytes
‘ɼµ®!Dw³’µ¿
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 11 bytes
‘ɼµ®!Dw³’µ¿
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 11 bytes
‘ɼµ®!Dw³’µ¿
Try it online!
$endgroup$
Jelly, 11 bytes
‘ɼµ®!Dw³’µ¿
Try it online!
edited 2 days ago
answered 2 days ago
HyperNeutrinoHyperNeutrino
19.1k437148
19.1k437148
add a comment |
add a comment |
$begingroup$
Clean, 88 bytes
import StdEnv,Data.Integer,Text
$a=hd[n\n<-[a/a..]|startsWith(""<+a)(""<+prod[one..n])]
Try it online!
Defines $ :: Integer -> Integer
.
Uses Data.Integer
's arbitrary size integers for IO.
$endgroup$
add a comment |
$begingroup$
Clean, 88 bytes
import StdEnv,Data.Integer,Text
$a=hd[n\n<-[a/a..]|startsWith(""<+a)(""<+prod[one..n])]
Try it online!
Defines $ :: Integer -> Integer
.
Uses Data.Integer
's arbitrary size integers for IO.
$endgroup$
add a comment |
$begingroup$
Clean, 88 bytes
import StdEnv,Data.Integer,Text
$a=hd[n\n<-[a/a..]|startsWith(""<+a)(""<+prod[one..n])]
Try it online!
Defines $ :: Integer -> Integer
.
Uses Data.Integer
's arbitrary size integers for IO.
$endgroup$
Clean, 88 bytes
import StdEnv,Data.Integer,Text
$a=hd[n\n<-[a/a..]|startsWith(""<+a)(""<+prod[one..n])]
Try it online!
Defines $ :: Integer -> Integer
.
Uses Data.Integer
's arbitrary size integers for IO.
answered yesterday
ΟurousΟurous
7,47611136
7,47611136
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 62 bytes
(b=1;While[⌊b!/10^((i=IntegerLength)[b!]-i@#)⌋!=#,b++];b)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 62 bytes
(b=1;While[⌊b!/10^((i=IntegerLength)[b!]-i@#)⌋!=#,b++];b)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 62 bytes
(b=1;While[⌊b!/10^((i=IntegerLength)[b!]-i@#)⌋!=#,b++];b)&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 62 bytes
(b=1;While[⌊b!/10^((i=IntegerLength)[b!]-i@#)⌋!=#,b++];b)&
Try it online!
edited yesterday
answered yesterday
J42161217J42161217
14.5k21354
14.5k21354
add a comment |
add a comment |
$begingroup$
Ruby, 40 bytes
->n{a=b=1;a*=b+=1until"%d"%a=~/^#{n}/;b}
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 40 bytes
->n{a=b=1;a*=b+=1until"%d"%a=~/^#{n}/;b}
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 40 bytes
->n{a=b=1;a*=b+=1until"%d"%a=~/^#{n}/;b}
Try it online!
$endgroup$
Ruby, 40 bytes
->n{a=b=1;a*=b+=1until"%d"%a=~/^#{n}/;b}
Try it online!
answered yesterday
G BG B
8,3261429
8,3261429
add a comment |
add a comment |
$begingroup$
Icon, 65 63 bytes
procedure f(a);p:=1;every n:=seq()&1=find(a,p*:=n)&return n;end
Try it online!
$endgroup$
add a comment |
$begingroup$
Icon, 65 63 bytes
procedure f(a);p:=1;every n:=seq()&1=find(a,p*:=n)&return n;end
Try it online!
$endgroup$
add a comment |
$begingroup$
Icon, 65 63 bytes
procedure f(a);p:=1;every n:=seq()&1=find(a,p*:=n)&return n;end
Try it online!
$endgroup$
Icon, 65 63 bytes
procedure f(a);p:=1;every n:=seq()&1=find(a,p*:=n)&return n;end
Try it online!
edited yesterday
answered yesterday
Galen IvanovGalen Ivanov
7,74211034
7,74211034
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%2f184776%2fa-note-on-n%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
22
$begingroup$
I... why did he prove that theorem? Did he just wake up one day and say "I shall solve this!" or did it serve a purpose?
$endgroup$
– Magic Octopus Urn
2 days ago
5
$begingroup$
Can we return
0
for input1
? Lynn's answer currently does.$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko My question is whether we're actually required to output a positive integer or not, though, that quote itself isn't really enough to specify that, and nowhere does it say that the test cases include the least possible output for each input.
$endgroup$
– Erik the Outgolfer
2 days ago
5
$begingroup$
@SolomonUcko Yes, "positive" excludes 0, but, again, nowhere in the challenge does it say that the output must be positive. Well, technically, it does restrict the output, but you really need to see into the details to figure that out (the challenge text also uses the "N" variable), so it's not at all clear if OP actually intended to restrict the output to the positive integers or if we can output
0
for input1
as well.$endgroup$
– Erik the Outgolfer
2 days ago
6
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
yesterday