A Note on N!
$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$
add a comment |
$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$
26
$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
Apr 25 at 19:53
11
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
Apr 26 at 16:16
2
$begingroup$
Here's the proof it anyone's interested.
$endgroup$
– Esolanging Fruit
Apr 29 at 2:39
add a comment |
$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 Apr 26 at 15:21
flawr
asked Apr 25 at 19:44
flawrflawr
27.8k670198
27.8k670198
26
$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
Apr 25 at 19:53
11
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
Apr 26 at 16:16
2
$begingroup$
Here's the proof it anyone's interested.
$endgroup$
– Esolanging Fruit
Apr 29 at 2:39
add a comment |
26
$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
Apr 25 at 19:53
11
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
Apr 26 at 16:16
2
$begingroup$
Here's the proof it anyone's interested.
$endgroup$
– Esolanging Fruit
Apr 29 at 2:39
26
26
$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
Apr 25 at 19:53
$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
Apr 25 at 19:53
11
11
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
Apr 26 at 16:16
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
Apr 26 at 16:16
2
2
$begingroup$
Here's the proof it anyone's interested.
$endgroup$
– Esolanging Fruit
Apr 29 at 2:39
$begingroup$
Here's the proof it anyone's interested.
$endgroup$
– Esolanging Fruit
Apr 29 at 2:39
add a comment |
21 Answers
21
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$
$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
Apr 25 at 20:58
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
Apr 27 at 3:40
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
Apr 27 at 14:20
$begingroup$
If the proof still holds if N is restricted to even values, then this 45 byte solution will always output a number.
$endgroup$
– negative seven
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
Apr 26 at 9:28
$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
Apr 26 at 9:37
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
Apr 26 at 12:37
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
Apr 26 at 15:34
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
Apr 26 at 16:38
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$
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
Apr 25 at 21:12
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
Apr 25 at 21:13
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
Apr 25 at 21:45
$begingroup$
3 bytes less:x=i=1n;f=n=>`${x*=++i}`.search(n)?f(n):i
$endgroup$
– vrugtehagel
May 2 at 16:08
$begingroup$
@vrugtehagel, that wouldn't be reusable.
$endgroup$
– Shaggy
May 2 at 20:12
|
show 2 more comments
$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
Apr 26 at 16:56
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
Apr 26 at 14:07
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
Apr 26 at 14:15
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
Apr 26 at 22:07
add a comment |
$begingroup$
Python 3, 63 bytes
f=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$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
Apr 26 at 1:13
$begingroup$
61 bytes
$endgroup$
– Chas Brown
Apr 26 at 8:17
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
Apr 26 at 17:43
$begingroup$
I think thef=
that you've got in the header is supposed to count towards your bit count.
$endgroup$
– mypetlion
May 1 at 22:20
$begingroup$
@mypetlion You are correct; thanks for catching that.
$endgroup$
– HyperNeutrino
May 1 at 22:33
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 |
$begingroup$
Haskell, 89 bytes
import Data.List
a x=head$filter(isPrefixOf$show x)$((show.product.(x->[1..x]))<$>[1..])
If anyone knows how to bypass the required import, let me know.
$endgroup$
$begingroup$
It seems that you output $N!$ and not $N$ as required.
$endgroup$
– flawr
May 3 at 21:49
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
21 Answers
21
active
oldest
votes
21 Answers
21
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$
$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
Apr 25 at 20:58
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
Apr 27 at 3:40
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
Apr 27 at 14:20
$begingroup$
If the proof still holds if N is restricted to even values, then this 45 byte solution will always output a number.
$endgroup$
– negative seven
yesterday
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$
$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
Apr 25 at 20:58
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
Apr 27 at 3:40
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
Apr 27 at 14:20
$begingroup$
If the proof still holds if N is restricted to even values, then this 45 byte solution will always output a number.
$endgroup$
– negative seven
yesterday
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 Apr 27 at 14:32
answered Apr 25 at 20:10
LynnLynn
51.7k8101237
51.7k8101237
$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
Apr 25 at 20:58
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
Apr 27 at 3:40
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
Apr 27 at 14:20
$begingroup$
If the proof still holds if N is restricted to even values, then this 45 byte solution will always output a number.
$endgroup$
– negative seven
yesterday
add a comment |
$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
Apr 25 at 20:58
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition takinga
as a number.
$endgroup$
– xnor
Apr 27 at 3:40
$begingroup$
@xnor I would have not thought of ``-a
in-p
``, that's a neat trick :)
$endgroup$
– Lynn
Apr 27 at 14:20
$begingroup$
If the proof still holds if N is restricted to even values, then this 45 byte solution will always output a number.
$endgroup$
– negative seven
yesterday
$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
Apr 25 at 20:58
$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
Apr 25 at 20:58
1
1
$begingroup$
For your True-for-1 version, you can shorten the base case condition taking
a
as a number.$endgroup$
– xnor
Apr 27 at 3:40
$begingroup$
For your True-for-1 version, you can shorten the base case condition taking
a
as a number.$endgroup$
– xnor
Apr 27 at 3:40
$begingroup$
@xnor I would have not thought of ``
-a
in-p
``, that's a neat trick :)$endgroup$
– Lynn
Apr 27 at 14:20
$begingroup$
@xnor I would have not thought of ``
-a
in-p
``, that's a neat trick :)$endgroup$
– Lynn
Apr 27 at 14:20
$begingroup$
If the proof still holds if N is restricted to even values, then this 45 byte solution will always output a number.
$endgroup$
– negative seven
yesterday
$begingroup$
If the proof still holds if N is restricted to even values, then this 45 byte solution will always output a number.
$endgroup$
– negative seven
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
Apr 26 at 9:28
$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
Apr 26 at 9:37
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
Apr 26 at 9:28
$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
Apr 26 at 9:37
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 Apr 26 at 9:14
answered Apr 26 at 6:16
Unrelated StringUnrelated String
2,190313
2,190313
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
Apr 26 at 9:28
$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
Apr 26 at 9:37
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
Apr 26 at 9:28
$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
Apr 26 at 9:37
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
Apr 26 at 9:28
$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
Apr 26 at 9:28
$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
Apr 26 at 9:37
$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
Apr 26 at 9:37
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
Apr 26 at 12:37
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
Apr 26 at 15:34
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
Apr 26 at 16:38
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
Apr 26 at 12:37
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
Apr 26 at 15:34
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
Apr 26 at 16:38
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 Apr 27 at 18:58
answered Apr 26 at 4:38
Neil A.Neil A.
1,668222
1,668222
$begingroup$
You don't need to count flags anymore, so this is107
bytes.
$endgroup$
– AdmBorkBork
Apr 26 at 12:37
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
Apr 26 at 15:34
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
Apr 26 at 16:38
add a comment |
$begingroup$
You don't need to count flags anymore, so this is107
bytes.
$endgroup$
– AdmBorkBork
Apr 26 at 12:37
$begingroup$
Why do you need the second semicolon beforereturn
?
$endgroup$
– Ruslan
Apr 26 at 15:34
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
Apr 26 at 16:38
$begingroup$
You don't need to count flags anymore, so this is
107
bytes.$endgroup$
– AdmBorkBork
Apr 26 at 12:37
$begingroup$
You don't need to count flags anymore, so this is
107
bytes.$endgroup$
– AdmBorkBork
Apr 26 at 12:37
$begingroup$
Why do you need the second semicolon before
return
?$endgroup$
– Ruslan
Apr 26 at 15:34
$begingroup$
Why do you need the second semicolon before
return
?$endgroup$
– Ruslan
Apr 26 at 15:34
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
Apr 26 at 16:38
$begingroup$
You could use a single character name for the function, save a couple of bytes.
$endgroup$
– Shaggy
Apr 26 at 16:38
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 Apr 25 at 20:45
Erik the OutgolferErik the Outgolfer
33.5k430106
33.5k430106
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 Apr 26 at 7:05
Kevin CruijssenKevin Cruijssen
45.1k576226
45.1k576226
add a comment |
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 Apr 25 at 21:43
MaltysenMaltysen
21.6k445118
21.6k445118
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
Apr 25 at 21:12
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
Apr 25 at 21:13
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
Apr 25 at 21:45
$begingroup$
3 bytes less:x=i=1n;f=n=>`${x*=++i}`.search(n)?f(n):i
$endgroup$
– vrugtehagel
May 2 at 16:08
$begingroup$
@vrugtehagel, that wouldn't be reusable.
$endgroup$
– Shaggy
May 2 at 20:12
|
show 2 more comments
$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
Apr 25 at 21:12
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
Apr 25 at 21:13
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
Apr 25 at 21:45
$begingroup$
3 bytes less:x=i=1n;f=n=>`${x*=++i}`.search(n)?f(n):i
$endgroup$
– vrugtehagel
May 2 at 16:08
$begingroup$
@vrugtehagel, that wouldn't be reusable.
$endgroup$
– Shaggy
May 2 at 20:12
|
show 2 more comments
$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 Apr 26 at 14:31
answered Apr 25 at 20:41
ShaggyShaggy
19.5k31768
19.5k31768
$begingroup$
Sadly,_Ês bU}f1
in Japt doesn't work
$endgroup$
– Embodiment of Ignorance
Apr 25 at 21:12
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
Apr 25 at 21:13
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
Apr 25 at 21:45
$begingroup$
3 bytes less:x=i=1n;f=n=>`${x*=++i}`.search(n)?f(n):i
$endgroup$
– vrugtehagel
May 2 at 16:08
$begingroup$
@vrugtehagel, that wouldn't be reusable.
$endgroup$
– Shaggy
May 2 at 20:12
|
show 2 more comments
$begingroup$
Sadly,_Ês bU}f1
in Japt doesn't work
$endgroup$
– Embodiment of Ignorance
Apr 25 at 21:12
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space afters
.
$endgroup$
– Shaggy
Apr 25 at 21:13
$begingroup$
@EmbodimentofIgnorance, you could also remove the1
if0
can be returned forn=1
.
$endgroup$
– Shaggy
Apr 25 at 21:45
$begingroup$
3 bytes less:x=i=1n;f=n=>`${x*=++i}`.search(n)?f(n):i
$endgroup$
– vrugtehagel
May 2 at 16:08
$begingroup$
@vrugtehagel, that wouldn't be reusable.
$endgroup$
– Shaggy
May 2 at 20:12
$begingroup$
Sadly,
_Ês bU}f1
in Japt doesn't work$endgroup$
– Embodiment of Ignorance
Apr 25 at 21:12
$begingroup$
Sadly,
_Ês bU}f1
in Japt doesn't work$endgroup$
– Embodiment of Ignorance
Apr 25 at 21:12
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space after
s
.$endgroup$
– Shaggy
Apr 25 at 21:13
$begingroup$
@EmbodimentofIgnorance, yeah, I had that too. You could remove the space after
s
.$endgroup$
– Shaggy
Apr 25 at 21:13
$begingroup$
@EmbodimentofIgnorance, you could also remove the
1
if 0
can be returned for n=1
.$endgroup$
– Shaggy
Apr 25 at 21:45
$begingroup$
@EmbodimentofIgnorance, you could also remove the
1
if 0
can be returned for n=1
.$endgroup$
– Shaggy
Apr 25 at 21:45
$begingroup$
3 bytes less:
x=i=1n;f=n=>`${x*=++i}`.search(n)?f(n):i
$endgroup$
– vrugtehagel
May 2 at 16:08
$begingroup$
3 bytes less:
x=i=1n;f=n=>`${x*=++i}`.search(n)?f(n):i
$endgroup$
– vrugtehagel
May 2 at 16:08
$begingroup$
@vrugtehagel, that wouldn't be reusable.
$endgroup$
– Shaggy
May 2 at 20:12
$begingroup$
@vrugtehagel, that wouldn't be reusable.
$endgroup$
– Shaggy
May 2 at 20:12
|
show 2 more comments
$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
Apr 26 at 16:56
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
Apr 26 at 16:56
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 Apr 26 at 19:41
answered Apr 26 at 4:16
danadana
2,261168
2,261168
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
Apr 26 at 16:56
add a comment |
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
Apr 26 at 16:56
1
1
$begingroup$
69 + 22
$endgroup$
– Expired Data
Apr 26 at 16:56
$begingroup$
69 + 22
$endgroup$
– Expired Data
Apr 26 at 16:56
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 Apr 25 at 20:38
answered Apr 25 at 20:31
Nick KennedyNick Kennedy
2,65469
2,65469
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 Apr 25 at 21:52
Jo KingJo King
28.5k367134
28.5k367134
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 Apr 25 at 22:27
NeilNeil
84.6k845183
84.6k845183
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 Apr 25 at 23:10
XcaliXcali
5,890523
5,890523
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
Apr 26 at 14:07
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
Apr 26 at 14:15
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
Apr 26 at 14:07
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
Apr 26 at 14:15
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 Apr 26 at 14:14
answered Apr 26 at 4:26
JonahJonah
3,3781019
3,3781019
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
Apr 26 at 14:07
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
Apr 26 at 14:15
add a comment |
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
Apr 26 at 14:07
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
Apr 26 at 14:15
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
Apr 26 at 14:07
$begingroup$
(]+1-0{(E.&":!))^:_&1x
$endgroup$
– FrownyFrog
Apr 26 at 14:07
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
Apr 26 at 14:15
$begingroup$
I love that use of "fixed point" to avoid the traditional while.
$endgroup$
– Jonah
Apr 26 at 14:15
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
Apr 26 at 22:07
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
Apr 26 at 22:07
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 Apr 26 at 15:15
LambdaBetaLambdaBeta
2,339419
2,339419
$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
Apr 26 at 22:07
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
Apr 26 at 22:07
$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
Apr 26 at 22:07
$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
Apr 26 at 22:07
add a comment |
$begingroup$
Python 3, 63 bytes
f=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$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
Apr 26 at 1:13
$begingroup$
61 bytes
$endgroup$
– Chas Brown
Apr 26 at 8:17
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
Apr 26 at 17:43
$begingroup$
I think thef=
that you've got in the header is supposed to count towards your bit count.
$endgroup$
– mypetlion
May 1 at 22:20
$begingroup$
@mypetlion You are correct; thanks for catching that.
$endgroup$
– HyperNeutrino
May 1 at 22:33
add a comment |
$begingroup$
Python 3, 63 bytes
f=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$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
Apr 26 at 1:13
$begingroup$
61 bytes
$endgroup$
– Chas Brown
Apr 26 at 8:17
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
Apr 26 at 17:43
$begingroup$
I think thef=
that you've got in the header is supposed to count towards your bit count.
$endgroup$
– mypetlion
May 1 at 22:20
$begingroup$
@mypetlion You are correct; thanks for catching that.
$endgroup$
– HyperNeutrino
May 1 at 22:33
add a comment |
$begingroup$
Python 3, 63 bytes
f=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, 63 bytes
f=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 May 1 at 22:33
answered Apr 25 at 19:56
HyperNeutrinoHyperNeutrino
19.2k438148
19.2k438148
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
Apr 26 at 1:13
$begingroup$
61 bytes
$endgroup$
– Chas Brown
Apr 26 at 8:17
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
Apr 26 at 17:43
$begingroup$
I think thef=
that you've got in the header is supposed to count towards your bit count.
$endgroup$
– mypetlion
May 1 at 22:20
$begingroup$
@mypetlion You are correct; thanks for catching that.
$endgroup$
– HyperNeutrino
May 1 at 22:33
add a comment |
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
Apr 26 at 1:13
$begingroup$
61 bytes
$endgroup$
– Chas Brown
Apr 26 at 8:17
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
Apr 26 at 17:43
$begingroup$
I think thef=
that you've got in the header is supposed to count towards your bit count.
$endgroup$
– mypetlion
May 1 at 22:20
$begingroup$
@mypetlion You are correct; thanks for catching that.
$endgroup$
– HyperNeutrino
May 1 at 22:33
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
Apr 26 at 1:13
$begingroup$
@JoKing nice, thanks
$endgroup$
– HyperNeutrino
Apr 26 at 1:13
$begingroup$
61 bytes
$endgroup$
– Chas Brown
Apr 26 at 8:17
$begingroup$
61 bytes
$endgroup$
– Chas Brown
Apr 26 at 8:17
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
Apr 26 at 17:43
$begingroup$
@ChasBrown thanks
$endgroup$
– HyperNeutrino
Apr 26 at 17:43
$begingroup$
I think the
f=
that you've got in the header is supposed to count towards your bit count.$endgroup$
– mypetlion
May 1 at 22:20
$begingroup$
I think the
f=
that you've got in the header is supposed to count towards your bit count.$endgroup$
– mypetlion
May 1 at 22:20
$begingroup$
@mypetlion You are correct; thanks for catching that.
$endgroup$
– HyperNeutrino
May 1 at 22:33
$begingroup$
@mypetlion You are correct; thanks for catching that.
$endgroup$
– HyperNeutrino
May 1 at 22:33
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 Apr 25 at 21:05
answered Apr 25 at 20:22
HyperNeutrinoHyperNeutrino
19.2k438148
19.2k438148
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 Apr 25 at 23:39
Ο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 Apr 26 at 0:42
answered Apr 26 at 0:34
J42161217J42161217
15.1k21457
15.1k21457
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 Apr 26 at 7:25
G BG B
8,3061430
8,3061430
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 Apr 26 at 18:58
answered Apr 26 at 7:44
Galen IvanovGalen Ivanov
8,33211237
8,33211237
add a comment |
add a comment |
$begingroup$
Haskell, 89 bytes
import Data.List
a x=head$filter(isPrefixOf$show x)$((show.product.(x->[1..x]))<$>[1..])
If anyone knows how to bypass the required import, let me know.
$endgroup$
$begingroup$
It seems that you output $N!$ and not $N$ as required.
$endgroup$
– flawr
May 3 at 21:49
add a comment |
$begingroup$
Haskell, 89 bytes
import Data.List
a x=head$filter(isPrefixOf$show x)$((show.product.(x->[1..x]))<$>[1..])
If anyone knows how to bypass the required import, let me know.
$endgroup$
$begingroup$
It seems that you output $N!$ and not $N$ as required.
$endgroup$
– flawr
May 3 at 21:49
add a comment |
$begingroup$
Haskell, 89 bytes
import Data.List
a x=head$filter(isPrefixOf$show x)$((show.product.(x->[1..x]))<$>[1..])
If anyone knows how to bypass the required import, let me know.
$endgroup$
Haskell, 89 bytes
import Data.List
a x=head$filter(isPrefixOf$show x)$((show.product.(x->[1..x]))<$>[1..])
If anyone knows how to bypass the required import, let me know.
answered May 3 at 15:20
Mega ManMega Man
8141715
8141715
$begingroup$
It seems that you output $N!$ and not $N$ as required.
$endgroup$
– flawr
May 3 at 21:49
add a comment |
$begingroup$
It seems that you output $N!$ and not $N$ as required.
$endgroup$
– flawr
May 3 at 21:49
$begingroup$
It seems that you output $N!$ and not $N$ as required.
$endgroup$
– flawr
May 3 at 21:49
$begingroup$
It seems that you output $N!$ and not $N$ as required.
$endgroup$
– flawr
May 3 at 21:49
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
26
$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
Apr 25 at 19:53
11
$begingroup$
@MagicOctopusUrn Never dealt with a number theorist before, have you?
$endgroup$
– Brady Gilg
Apr 26 at 16:16
2
$begingroup$
Here's the proof it anyone's interested.
$endgroup$
– Esolanging Fruit
Apr 29 at 2:39