Generate some rough numbers
up vote
15
down vote
favorite
Background
A number n
can be described as B
-rough if all of the prime factors of n
strictly exceed B
.
The Challenge
Given two positive integers B
and k
, output the first k
B
-rough numbers.
Examples
Let f(B, k)
be a function which returns the set containing the first k
B
-rough numbers.
> f(1, 10)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
> f(2, 5)
1, 3, 5, 7, 9
> f(10, 14)
1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
code-golf number-theory primes factoring
|
show 5 more comments
up vote
15
down vote
favorite
Background
A number n
can be described as B
-rough if all of the prime factors of n
strictly exceed B
.
The Challenge
Given two positive integers B
and k
, output the first k
B
-rough numbers.
Examples
Let f(B, k)
be a function which returns the set containing the first k
B
-rough numbers.
> f(1, 10)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
> f(2, 5)
1, 3, 5, 7, 9
> f(10, 14)
1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
code-golf number-theory primes factoring
2
Can you elaborate on the challenge? I don't understand it. Maybe explain the examples?
– d-b
Nov 3 at 17:41
I don't understand why you include 1 in all your answers when it's never greater thanB
?
– kamoroso94
Nov 3 at 17:56
1
1 has no prime factors, so every prime factor of 1 is larger than B and 1 should appear in the output independent of B.
– Hood
Nov 3 at 19:41
@d-b Factorizen
into primes. If all of those primes are greater thanB
, n isB
-rough.
– Addison Crump
Nov 3 at 20:06
@AddisonCrump So for example, since the primes for 35 are 5 and 7, 35 is 4-rough? Is this some recognized common terminology? Never heard of it before. I still don't under the examples, especially not the last one. 14 numbers but what is 10??
– d-b
Nov 3 at 20:30
|
show 5 more comments
up vote
15
down vote
favorite
up vote
15
down vote
favorite
Background
A number n
can be described as B
-rough if all of the prime factors of n
strictly exceed B
.
The Challenge
Given two positive integers B
and k
, output the first k
B
-rough numbers.
Examples
Let f(B, k)
be a function which returns the set containing the first k
B
-rough numbers.
> f(1, 10)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
> f(2, 5)
1, 3, 5, 7, 9
> f(10, 14)
1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
code-golf number-theory primes factoring
Background
A number n
can be described as B
-rough if all of the prime factors of n
strictly exceed B
.
The Challenge
Given two positive integers B
and k
, output the first k
B
-rough numbers.
Examples
Let f(B, k)
be a function which returns the set containing the first k
B
-rough numbers.
> f(1, 10)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
> f(2, 5)
1, 3, 5, 7, 9
> f(10, 14)
1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
code-golf number-theory primes factoring
code-golf number-theory primes factoring
asked Nov 3 at 6:10
Addison Crump
8,30913282
8,30913282
2
Can you elaborate on the challenge? I don't understand it. Maybe explain the examples?
– d-b
Nov 3 at 17:41
I don't understand why you include 1 in all your answers when it's never greater thanB
?
– kamoroso94
Nov 3 at 17:56
1
1 has no prime factors, so every prime factor of 1 is larger than B and 1 should appear in the output independent of B.
– Hood
Nov 3 at 19:41
@d-b Factorizen
into primes. If all of those primes are greater thanB
, n isB
-rough.
– Addison Crump
Nov 3 at 20:06
@AddisonCrump So for example, since the primes for 35 are 5 and 7, 35 is 4-rough? Is this some recognized common terminology? Never heard of it before. I still don't under the examples, especially not the last one. 14 numbers but what is 10??
– d-b
Nov 3 at 20:30
|
show 5 more comments
2
Can you elaborate on the challenge? I don't understand it. Maybe explain the examples?
– d-b
Nov 3 at 17:41
I don't understand why you include 1 in all your answers when it's never greater thanB
?
– kamoroso94
Nov 3 at 17:56
1
1 has no prime factors, so every prime factor of 1 is larger than B and 1 should appear in the output independent of B.
– Hood
Nov 3 at 19:41
@d-b Factorizen
into primes. If all of those primes are greater thanB
, n isB
-rough.
– Addison Crump
Nov 3 at 20:06
@AddisonCrump So for example, since the primes for 35 are 5 and 7, 35 is 4-rough? Is this some recognized common terminology? Never heard of it before. I still don't under the examples, especially not the last one. 14 numbers but what is 10??
– d-b
Nov 3 at 20:30
2
2
Can you elaborate on the challenge? I don't understand it. Maybe explain the examples?
– d-b
Nov 3 at 17:41
Can you elaborate on the challenge? I don't understand it. Maybe explain the examples?
– d-b
Nov 3 at 17:41
I don't understand why you include 1 in all your answers when it's never greater than
B
?– kamoroso94
Nov 3 at 17:56
I don't understand why you include 1 in all your answers when it's never greater than
B
?– kamoroso94
Nov 3 at 17:56
1
1
1 has no prime factors, so every prime factor of 1 is larger than B and 1 should appear in the output independent of B.
– Hood
Nov 3 at 19:41
1 has no prime factors, so every prime factor of 1 is larger than B and 1 should appear in the output independent of B.
– Hood
Nov 3 at 19:41
@d-b Factorize
n
into primes. If all of those primes are greater than B
, n is B
-rough.– Addison Crump
Nov 3 at 20:06
@d-b Factorize
n
into primes. If all of those primes are greater than B
, n is B
-rough.– Addison Crump
Nov 3 at 20:06
@AddisonCrump So for example, since the primes for 35 are 5 and 7, 35 is 4-rough? Is this some recognized common terminology? Never heard of it before. I still don't under the examples, especially not the last one. 14 numbers but what is 10??
– d-b
Nov 3 at 20:30
@AddisonCrump So for example, since the primes for 35 are 5 and 7, 35 is 4-rough? Is this some recognized common terminology? Never heard of it before. I still don't under the examples, especially not the last one. 14 numbers but what is 10??
– d-b
Nov 3 at 20:30
|
show 5 more comments
11 Answers
11
active
oldest
votes
up vote
5
down vote
Haskell, 53 44 bytes
b%k=take k[n|n<-[1..],all((>0).mod n)[2..b]]
Try it online!
Thanks to H.PWiz for -9 bytes!
b%k= -- given inputs b and k
take k -- take the first k elements from
[n|n<-[1..] -- the infinite list of all n > 0
,all [2..b]] -- where all numbers from 2 to b (inclusive)
((>0).mod n) -- do not divide n.
This can be simplified somewhat
– H.PWiz
Nov 3 at 12:47
@H.PWiz Right, somehow I only thought about taking the(>b)
-part inside the comprehension (which does not work) but not the other way around. Thanks!
– Laikoni
Nov 3 at 12:57
add a comment |
up vote
5
down vote
Python 3, 80, 75 bytes
lambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
Try it online!
Thanks to shooqie for saving 5 bytes.
This assumes that the k'th B-rough number will never exceed $B * k$, which I don't know how to prove, but seems like a fairly safe assumption (and I can't find any counterexamples).
Alternate solution:
Python 2, 78 bytes
B,k=input()
i=1
while k:
if all(i%j for j in range(2,B+1)):print i;k-=1
i+=1
Try it online!
This solution does not make the above solution. And is much more efficient.
3
Hmm, that assumption is probably verifiable, but an interesting problem nonetheless. I'll bounty for a proof.
– Addison Crump
Nov 3 at 7:07
1
Why notlambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
?
– shooqie
Nov 3 at 10:59
1
@BlackOwlKai That sounds cool. See also math.stackexchange.com/questions/2983364/…
– Anush
2 days ago
@Anush Sadly, my proof didn't work, because I made a mistake
– Black Owl Kai
2 days ago
add a comment |
up vote
3
down vote
Jelly, 7 bytes
1Æf>Ạɗ#
Try it online!
add a comment |
up vote
3
down vote
Perl 6, 35 32 bytes
-3 bytes thanks to nwellnof!
{grep(*%all(2..$^b),1..*)[^$^k]}
Try it online!
An anonymous code block that takes two integers and returns a list of integers.
Explanation
{ } # Anonymous code block
grep( ,1..*) # Filter from the positive integers
* # Is the number
% # Not divisible by
all( ) # All of the numbers
2..$^b # From 2 to b
[^$^k] # And take the first k numbers
What doesall
do?
– Addison Crump
Nov 3 at 7:07
1
@AddisonCrumpall
checks if all the elements in the list are truthy. I will be adding an explanation for the whole thing shortly
– Jo King
Nov 3 at 7:10
@nwellnhof Wow! So that's what Junctions are useful for!
– Jo King
Nov 3 at 10:56
Yes, note that you could also use[&]
instead ofall
.
– nwellnhof
Nov 3 at 10:57
@AddisonCrump I guessall
isn't being used in that way any more, so I should update my answer.all
creates a Junction of the values in the range2..b
, and any operations performed on the Junction gets performed on all the values simulataneously. When it is evaluated in Boolean context by thegrep
, this collapses into whether all the values in the Junction are truthy, ie non-zero
– Jo King
Nov 3 at 11:07
add a comment |
up vote
2
down vote
Husk, 9 8 bytes
↑foΛ>⁰pN
Try it online!
Takes $B$ as first and $ k $ as second input.
↑ -- take the first k elements
N -- from the natural numbers
f -- filtered by
o p -- the prime factors
Λ>⁰ -- are all larger than the first input
add a comment |
up vote
2
down vote
Charcoal, 33 bytes
NθNη≔⁰ζW‹Lυη«≦⊕ζ¿¬Φθ∧κ¬﹪ζ⊕κ⊞υζ»Iυ
Try it online! Link is to verbose version of code. Explanation:
NθNη
Input B
and k
.
≔⁰ζ
Set z
to 0.
W‹Lυη«
Repeat until we have k
values.
≦⊕ζ
Increment z
.
¿¬Φθ∧κ¬﹪ζ⊕κ
Divide z
by all the numbers from 2
to B
and see if any remainder is zero.
⊞υζ»
If not then push z
to the predefined empty list.
Iυ
Cast the list to string and implicitly output it.
add a comment |
up vote
2
down vote
JavaScript (ES6), 68 bytes
Takes input as (b)(k)
.
b=>k=>(o=,n=1,g=d=>(d<2?o.push(n)==k:n%d&&g(d-1))||g(b,n++))(b)&&o
Try it online!
Commented
b => k => ( // input = b and k
o = , // o = output array
n = 1, // n = value to test
g = d => ( // g = recursive function, taking the divisor d
d < 2 ? // if d = 1:
o.push(n) == k // push n into o and test whether o contains k elements
: // else:
n % d && g(d - 1) // if d is not a divisor of n, do a recursive call with d - 1
) || // if the final result of g() is falsy,
g(b, n++) // do a recursive call with d = b and n + 1
)(b) // initial call to g() with d = b
&& o // return o
add a comment |
up vote
1
down vote
Jelly, 10 bytes
1µg³!¤Ịµ⁴#
Try it online!
How it works
1µg³!¤Ịµ⁴# Dyadic main link. Left = B, right = k
µ⁴# Take first k numbers satisfying...
g GCD with
³!¤ B factorial
Ị is insignificant (abs(x) <= 1)?
1µ ... starting from 1.
add a comment |
up vote
1
down vote
JavaScript (Node.js), 68 bytes
b=>g=(k,i=1,j=b)=>k?j>1?i%j?g(k,i,j-1):g(k,i+1):[i,...g(k-1,i+1)]:
Try it online!
add a comment |
up vote
1
down vote
APL(NARS), 52 chars, 104 bytes
r←a f w;i
r←,i←1⋄→3
i+←1⋄→3×⍳∨/a≥πi⋄r←r,i
→2×⍳w>↑⍴r
Above it seems the rows after 'r←a f w;i' have names 1 2 3;test:
o←⎕fmt
o 1 h 2
┌2───┐
│ 1 2│
└~───┘
o 1 h 1
┌1─┐
│ 1│
└~─┘
o 10 h 14
┌14───────────────────────────────────────┐
│ 1 11 13 17 19 23 29 31 37 41 43 47 53 59│
└~────────────────────────────────────────┘
add a comment |
up vote
1
down vote
05AB1E, 9 bytes
∞ʒÒ¹›P}²£
Try it online or verify all test cases.
Explanation:
∞ # Infinite list starting at 1: [1,...]
ʒ } # Filter it by:
Ò # Get all prime factors of the current number
¹› # Check for each if they are larger than the first input
P # And check if it's truthy for all of them
²£ # Leave only the leading amount of items equal to the second input
add a comment |
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Haskell, 53 44 bytes
b%k=take k[n|n<-[1..],all((>0).mod n)[2..b]]
Try it online!
Thanks to H.PWiz for -9 bytes!
b%k= -- given inputs b and k
take k -- take the first k elements from
[n|n<-[1..] -- the infinite list of all n > 0
,all [2..b]] -- where all numbers from 2 to b (inclusive)
((>0).mod n) -- do not divide n.
This can be simplified somewhat
– H.PWiz
Nov 3 at 12:47
@H.PWiz Right, somehow I only thought about taking the(>b)
-part inside the comprehension (which does not work) but not the other way around. Thanks!
– Laikoni
Nov 3 at 12:57
add a comment |
up vote
5
down vote
Haskell, 53 44 bytes
b%k=take k[n|n<-[1..],all((>0).mod n)[2..b]]
Try it online!
Thanks to H.PWiz for -9 bytes!
b%k= -- given inputs b and k
take k -- take the first k elements from
[n|n<-[1..] -- the infinite list of all n > 0
,all [2..b]] -- where all numbers from 2 to b (inclusive)
((>0).mod n) -- do not divide n.
This can be simplified somewhat
– H.PWiz
Nov 3 at 12:47
@H.PWiz Right, somehow I only thought about taking the(>b)
-part inside the comprehension (which does not work) but not the other way around. Thanks!
– Laikoni
Nov 3 at 12:57
add a comment |
up vote
5
down vote
up vote
5
down vote
Haskell, 53 44 bytes
b%k=take k[n|n<-[1..],all((>0).mod n)[2..b]]
Try it online!
Thanks to H.PWiz for -9 bytes!
b%k= -- given inputs b and k
take k -- take the first k elements from
[n|n<-[1..] -- the infinite list of all n > 0
,all [2..b]] -- where all numbers from 2 to b (inclusive)
((>0).mod n) -- do not divide n.
Haskell, 53 44 bytes
b%k=take k[n|n<-[1..],all((>0).mod n)[2..b]]
Try it online!
Thanks to H.PWiz for -9 bytes!
b%k= -- given inputs b and k
take k -- take the first k elements from
[n|n<-[1..] -- the infinite list of all n > 0
,all [2..b]] -- where all numbers from 2 to b (inclusive)
((>0).mod n) -- do not divide n.
edited Nov 3 at 13:02
answered Nov 3 at 9:55
Laikoni
19.3k43596
19.3k43596
This can be simplified somewhat
– H.PWiz
Nov 3 at 12:47
@H.PWiz Right, somehow I only thought about taking the(>b)
-part inside the comprehension (which does not work) but not the other way around. Thanks!
– Laikoni
Nov 3 at 12:57
add a comment |
This can be simplified somewhat
– H.PWiz
Nov 3 at 12:47
@H.PWiz Right, somehow I only thought about taking the(>b)
-part inside the comprehension (which does not work) but not the other way around. Thanks!
– Laikoni
Nov 3 at 12:57
This can be simplified somewhat
– H.PWiz
Nov 3 at 12:47
This can be simplified somewhat
– H.PWiz
Nov 3 at 12:47
@H.PWiz Right, somehow I only thought about taking the
(>b)
-part inside the comprehension (which does not work) but not the other way around. Thanks!– Laikoni
Nov 3 at 12:57
@H.PWiz Right, somehow I only thought about taking the
(>b)
-part inside the comprehension (which does not work) but not the other way around. Thanks!– Laikoni
Nov 3 at 12:57
add a comment |
up vote
5
down vote
Python 3, 80, 75 bytes
lambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
Try it online!
Thanks to shooqie for saving 5 bytes.
This assumes that the k'th B-rough number will never exceed $B * k$, which I don't know how to prove, but seems like a fairly safe assumption (and I can't find any counterexamples).
Alternate solution:
Python 2, 78 bytes
B,k=input()
i=1
while k:
if all(i%j for j in range(2,B+1)):print i;k-=1
i+=1
Try it online!
This solution does not make the above solution. And is much more efficient.
3
Hmm, that assumption is probably verifiable, but an interesting problem nonetheless. I'll bounty for a proof.
– Addison Crump
Nov 3 at 7:07
1
Why notlambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
?
– shooqie
Nov 3 at 10:59
1
@BlackOwlKai That sounds cool. See also math.stackexchange.com/questions/2983364/…
– Anush
2 days ago
@Anush Sadly, my proof didn't work, because I made a mistake
– Black Owl Kai
2 days ago
add a comment |
up vote
5
down vote
Python 3, 80, 75 bytes
lambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
Try it online!
Thanks to shooqie for saving 5 bytes.
This assumes that the k'th B-rough number will never exceed $B * k$, which I don't know how to prove, but seems like a fairly safe assumption (and I can't find any counterexamples).
Alternate solution:
Python 2, 78 bytes
B,k=input()
i=1
while k:
if all(i%j for j in range(2,B+1)):print i;k-=1
i+=1
Try it online!
This solution does not make the above solution. And is much more efficient.
3
Hmm, that assumption is probably verifiable, but an interesting problem nonetheless. I'll bounty for a proof.
– Addison Crump
Nov 3 at 7:07
1
Why notlambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
?
– shooqie
Nov 3 at 10:59
1
@BlackOwlKai That sounds cool. See also math.stackexchange.com/questions/2983364/…
– Anush
2 days ago
@Anush Sadly, my proof didn't work, because I made a mistake
– Black Owl Kai
2 days ago
add a comment |
up vote
5
down vote
up vote
5
down vote
Python 3, 80, 75 bytes
lambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
Try it online!
Thanks to shooqie for saving 5 bytes.
This assumes that the k'th B-rough number will never exceed $B * k$, which I don't know how to prove, but seems like a fairly safe assumption (and I can't find any counterexamples).
Alternate solution:
Python 2, 78 bytes
B,k=input()
i=1
while k:
if all(i%j for j in range(2,B+1)):print i;k-=1
i+=1
Try it online!
This solution does not make the above solution. And is much more efficient.
Python 3, 80, 75 bytes
lambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
Try it online!
Thanks to shooqie for saving 5 bytes.
This assumes that the k'th B-rough number will never exceed $B * k$, which I don't know how to prove, but seems like a fairly safe assumption (and I can't find any counterexamples).
Alternate solution:
Python 2, 78 bytes
B,k=input()
i=1
while k:
if all(i%j for j in range(2,B+1)):print i;k-=1
i+=1
Try it online!
This solution does not make the above solution. And is much more efficient.
edited Nov 3 at 17:49
answered Nov 3 at 7:00
DJMcMayhem♦
40.5k11143307
40.5k11143307
3
Hmm, that assumption is probably verifiable, but an interesting problem nonetheless. I'll bounty for a proof.
– Addison Crump
Nov 3 at 7:07
1
Why notlambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
?
– shooqie
Nov 3 at 10:59
1
@BlackOwlKai That sounds cool. See also math.stackexchange.com/questions/2983364/…
– Anush
2 days ago
@Anush Sadly, my proof didn't work, because I made a mistake
– Black Owl Kai
2 days ago
add a comment |
3
Hmm, that assumption is probably verifiable, but an interesting problem nonetheless. I'll bounty for a proof.
– Addison Crump
Nov 3 at 7:07
1
Why notlambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
?
– shooqie
Nov 3 at 10:59
1
@BlackOwlKai That sounds cool. See also math.stackexchange.com/questions/2983364/…
– Anush
2 days ago
@Anush Sadly, my proof didn't work, because I made a mistake
– Black Owl Kai
2 days ago
3
3
Hmm, that assumption is probably verifiable, but an interesting problem nonetheless. I'll bounty for a proof.
– Addison Crump
Nov 3 at 7:07
Hmm, that assumption is probably verifiable, but an interesting problem nonetheless. I'll bounty for a proof.
– Addison Crump
Nov 3 at 7:07
1
1
Why not
lambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
?– shooqie
Nov 3 at 10:59
Why not
lambda B,k:[i for i in range(1,-~B*k)if all(i%j for j in range(2,B+1))][:k]
?– shooqie
Nov 3 at 10:59
1
1
@BlackOwlKai That sounds cool. See also math.stackexchange.com/questions/2983364/…
– Anush
2 days ago
@BlackOwlKai That sounds cool. See also math.stackexchange.com/questions/2983364/…
– Anush
2 days ago
@Anush Sadly, my proof didn't work, because I made a mistake
– Black Owl Kai
2 days ago
@Anush Sadly, my proof didn't work, because I made a mistake
– Black Owl Kai
2 days ago
add a comment |
up vote
3
down vote
Jelly, 7 bytes
1Æf>Ạɗ#
Try it online!
add a comment |
up vote
3
down vote
Jelly, 7 bytes
1Æf>Ạɗ#
Try it online!
add a comment |
up vote
3
down vote
up vote
3
down vote
Jelly, 7 bytes
1Æf>Ạɗ#
Try it online!
Jelly, 7 bytes
1Æf>Ạɗ#
Try it online!
answered Nov 3 at 10:04
Erik the Outgolfer
30.1k428100
30.1k428100
add a comment |
add a comment |
up vote
3
down vote
Perl 6, 35 32 bytes
-3 bytes thanks to nwellnof!
{grep(*%all(2..$^b),1..*)[^$^k]}
Try it online!
An anonymous code block that takes two integers and returns a list of integers.
Explanation
{ } # Anonymous code block
grep( ,1..*) # Filter from the positive integers
* # Is the number
% # Not divisible by
all( ) # All of the numbers
2..$^b # From 2 to b
[^$^k] # And take the first k numbers
What doesall
do?
– Addison Crump
Nov 3 at 7:07
1
@AddisonCrumpall
checks if all the elements in the list are truthy. I will be adding an explanation for the whole thing shortly
– Jo King
Nov 3 at 7:10
@nwellnhof Wow! So that's what Junctions are useful for!
– Jo King
Nov 3 at 10:56
Yes, note that you could also use[&]
instead ofall
.
– nwellnhof
Nov 3 at 10:57
@AddisonCrump I guessall
isn't being used in that way any more, so I should update my answer.all
creates a Junction of the values in the range2..b
, and any operations performed on the Junction gets performed on all the values simulataneously. When it is evaluated in Boolean context by thegrep
, this collapses into whether all the values in the Junction are truthy, ie non-zero
– Jo King
Nov 3 at 11:07
add a comment |
up vote
3
down vote
Perl 6, 35 32 bytes
-3 bytes thanks to nwellnof!
{grep(*%all(2..$^b),1..*)[^$^k]}
Try it online!
An anonymous code block that takes two integers and returns a list of integers.
Explanation
{ } # Anonymous code block
grep( ,1..*) # Filter from the positive integers
* # Is the number
% # Not divisible by
all( ) # All of the numbers
2..$^b # From 2 to b
[^$^k] # And take the first k numbers
What doesall
do?
– Addison Crump
Nov 3 at 7:07
1
@AddisonCrumpall
checks if all the elements in the list are truthy. I will be adding an explanation for the whole thing shortly
– Jo King
Nov 3 at 7:10
@nwellnhof Wow! So that's what Junctions are useful for!
– Jo King
Nov 3 at 10:56
Yes, note that you could also use[&]
instead ofall
.
– nwellnhof
Nov 3 at 10:57
@AddisonCrump I guessall
isn't being used in that way any more, so I should update my answer.all
creates a Junction of the values in the range2..b
, and any operations performed on the Junction gets performed on all the values simulataneously. When it is evaluated in Boolean context by thegrep
, this collapses into whether all the values in the Junction are truthy, ie non-zero
– Jo King
Nov 3 at 11:07
add a comment |
up vote
3
down vote
up vote
3
down vote
Perl 6, 35 32 bytes
-3 bytes thanks to nwellnof!
{grep(*%all(2..$^b),1..*)[^$^k]}
Try it online!
An anonymous code block that takes two integers and returns a list of integers.
Explanation
{ } # Anonymous code block
grep( ,1..*) # Filter from the positive integers
* # Is the number
% # Not divisible by
all( ) # All of the numbers
2..$^b # From 2 to b
[^$^k] # And take the first k numbers
Perl 6, 35 32 bytes
-3 bytes thanks to nwellnof!
{grep(*%all(2..$^b),1..*)[^$^k]}
Try it online!
An anonymous code block that takes two integers and returns a list of integers.
Explanation
{ } # Anonymous code block
grep( ,1..*) # Filter from the positive integers
* # Is the number
% # Not divisible by
all( ) # All of the numbers
2..$^b # From 2 to b
[^$^k] # And take the first k numbers
edited Nov 3 at 11:01
answered Nov 3 at 6:59
Jo King
18.6k241100
18.6k241100
What doesall
do?
– Addison Crump
Nov 3 at 7:07
1
@AddisonCrumpall
checks if all the elements in the list are truthy. I will be adding an explanation for the whole thing shortly
– Jo King
Nov 3 at 7:10
@nwellnhof Wow! So that's what Junctions are useful for!
– Jo King
Nov 3 at 10:56
Yes, note that you could also use[&]
instead ofall
.
– nwellnhof
Nov 3 at 10:57
@AddisonCrump I guessall
isn't being used in that way any more, so I should update my answer.all
creates a Junction of the values in the range2..b
, and any operations performed on the Junction gets performed on all the values simulataneously. When it is evaluated in Boolean context by thegrep
, this collapses into whether all the values in the Junction are truthy, ie non-zero
– Jo King
Nov 3 at 11:07
add a comment |
What doesall
do?
– Addison Crump
Nov 3 at 7:07
1
@AddisonCrumpall
checks if all the elements in the list are truthy. I will be adding an explanation for the whole thing shortly
– Jo King
Nov 3 at 7:10
@nwellnhof Wow! So that's what Junctions are useful for!
– Jo King
Nov 3 at 10:56
Yes, note that you could also use[&]
instead ofall
.
– nwellnhof
Nov 3 at 10:57
@AddisonCrump I guessall
isn't being used in that way any more, so I should update my answer.all
creates a Junction of the values in the range2..b
, and any operations performed on the Junction gets performed on all the values simulataneously. When it is evaluated in Boolean context by thegrep
, this collapses into whether all the values in the Junction are truthy, ie non-zero
– Jo King
Nov 3 at 11:07
What does
all
do?– Addison Crump
Nov 3 at 7:07
What does
all
do?– Addison Crump
Nov 3 at 7:07
1
1
@AddisonCrump
all
checks if all the elements in the list are truthy. I will be adding an explanation for the whole thing shortly– Jo King
Nov 3 at 7:10
@AddisonCrump
all
checks if all the elements in the list are truthy. I will be adding an explanation for the whole thing shortly– Jo King
Nov 3 at 7:10
@nwellnhof Wow! So that's what Junctions are useful for!
– Jo King
Nov 3 at 10:56
@nwellnhof Wow! So that's what Junctions are useful for!
– Jo King
Nov 3 at 10:56
Yes, note that you could also use
[&]
instead of all
.– nwellnhof
Nov 3 at 10:57
Yes, note that you could also use
[&]
instead of all
.– nwellnhof
Nov 3 at 10:57
@AddisonCrump I guess
all
isn't being used in that way any more, so I should update my answer. all
creates a Junction of the values in the range 2..b
, and any operations performed on the Junction gets performed on all the values simulataneously. When it is evaluated in Boolean context by the grep
, this collapses into whether all the values in the Junction are truthy, ie non-zero– Jo King
Nov 3 at 11:07
@AddisonCrump I guess
all
isn't being used in that way any more, so I should update my answer. all
creates a Junction of the values in the range 2..b
, and any operations performed on the Junction gets performed on all the values simulataneously. When it is evaluated in Boolean context by the grep
, this collapses into whether all the values in the Junction are truthy, ie non-zero– Jo King
Nov 3 at 11:07
add a comment |
up vote
2
down vote
Husk, 9 8 bytes
↑foΛ>⁰pN
Try it online!
Takes $B$ as first and $ k $ as second input.
↑ -- take the first k elements
N -- from the natural numbers
f -- filtered by
o p -- the prime factors
Λ>⁰ -- are all larger than the first input
add a comment |
up vote
2
down vote
Husk, 9 8 bytes
↑foΛ>⁰pN
Try it online!
Takes $B$ as first and $ k $ as second input.
↑ -- take the first k elements
N -- from the natural numbers
f -- filtered by
o p -- the prime factors
Λ>⁰ -- are all larger than the first input
add a comment |
up vote
2
down vote
up vote
2
down vote
Husk, 9 8 bytes
↑foΛ>⁰pN
Try it online!
Takes $B$ as first and $ k $ as second input.
↑ -- take the first k elements
N -- from the natural numbers
f -- filtered by
o p -- the prime factors
Λ>⁰ -- are all larger than the first input
Husk, 9 8 bytes
↑foΛ>⁰pN
Try it online!
Takes $B$ as first and $ k $ as second input.
↑ -- take the first k elements
N -- from the natural numbers
f -- filtered by
o p -- the prime factors
Λ>⁰ -- are all larger than the first input
edited Nov 3 at 11:11
answered Nov 3 at 10:59
Laikoni
19.3k43596
19.3k43596
add a comment |
add a comment |
up vote
2
down vote
Charcoal, 33 bytes
NθNη≔⁰ζW‹Lυη«≦⊕ζ¿¬Φθ∧κ¬﹪ζ⊕κ⊞υζ»Iυ
Try it online! Link is to verbose version of code. Explanation:
NθNη
Input B
and k
.
≔⁰ζ
Set z
to 0.
W‹Lυη«
Repeat until we have k
values.
≦⊕ζ
Increment z
.
¿¬Φθ∧κ¬﹪ζ⊕κ
Divide z
by all the numbers from 2
to B
and see if any remainder is zero.
⊞υζ»
If not then push z
to the predefined empty list.
Iυ
Cast the list to string and implicitly output it.
add a comment |
up vote
2
down vote
Charcoal, 33 bytes
NθNη≔⁰ζW‹Lυη«≦⊕ζ¿¬Φθ∧κ¬﹪ζ⊕κ⊞υζ»Iυ
Try it online! Link is to verbose version of code. Explanation:
NθNη
Input B
and k
.
≔⁰ζ
Set z
to 0.
W‹Lυη«
Repeat until we have k
values.
≦⊕ζ
Increment z
.
¿¬Φθ∧κ¬﹪ζ⊕κ
Divide z
by all the numbers from 2
to B
and see if any remainder is zero.
⊞υζ»
If not then push z
to the predefined empty list.
Iυ
Cast the list to string and implicitly output it.
add a comment |
up vote
2
down vote
up vote
2
down vote
Charcoal, 33 bytes
NθNη≔⁰ζW‹Lυη«≦⊕ζ¿¬Φθ∧κ¬﹪ζ⊕κ⊞υζ»Iυ
Try it online! Link is to verbose version of code. Explanation:
NθNη
Input B
and k
.
≔⁰ζ
Set z
to 0.
W‹Lυη«
Repeat until we have k
values.
≦⊕ζ
Increment z
.
¿¬Φθ∧κ¬﹪ζ⊕κ
Divide z
by all the numbers from 2
to B
and see if any remainder is zero.
⊞υζ»
If not then push z
to the predefined empty list.
Iυ
Cast the list to string and implicitly output it.
Charcoal, 33 bytes
NθNη≔⁰ζW‹Lυη«≦⊕ζ¿¬Φθ∧κ¬﹪ζ⊕κ⊞υζ»Iυ
Try it online! Link is to verbose version of code. Explanation:
NθNη
Input B
and k
.
≔⁰ζ
Set z
to 0.
W‹Lυη«
Repeat until we have k
values.
≦⊕ζ
Increment z
.
¿¬Φθ∧κ¬﹪ζ⊕κ
Divide z
by all the numbers from 2
to B
and see if any remainder is zero.
⊞υζ»
If not then push z
to the predefined empty list.
Iυ
Cast the list to string and implicitly output it.
answered Nov 3 at 11:19
Neil
77.4k744174
77.4k744174
add a comment |
add a comment |
up vote
2
down vote
JavaScript (ES6), 68 bytes
Takes input as (b)(k)
.
b=>k=>(o=,n=1,g=d=>(d<2?o.push(n)==k:n%d&&g(d-1))||g(b,n++))(b)&&o
Try it online!
Commented
b => k => ( // input = b and k
o = , // o = output array
n = 1, // n = value to test
g = d => ( // g = recursive function, taking the divisor d
d < 2 ? // if d = 1:
o.push(n) == k // push n into o and test whether o contains k elements
: // else:
n % d && g(d - 1) // if d is not a divisor of n, do a recursive call with d - 1
) || // if the final result of g() is falsy,
g(b, n++) // do a recursive call with d = b and n + 1
)(b) // initial call to g() with d = b
&& o // return o
add a comment |
up vote
2
down vote
JavaScript (ES6), 68 bytes
Takes input as (b)(k)
.
b=>k=>(o=,n=1,g=d=>(d<2?o.push(n)==k:n%d&&g(d-1))||g(b,n++))(b)&&o
Try it online!
Commented
b => k => ( // input = b and k
o = , // o = output array
n = 1, // n = value to test
g = d => ( // g = recursive function, taking the divisor d
d < 2 ? // if d = 1:
o.push(n) == k // push n into o and test whether o contains k elements
: // else:
n % d && g(d - 1) // if d is not a divisor of n, do a recursive call with d - 1
) || // if the final result of g() is falsy,
g(b, n++) // do a recursive call with d = b and n + 1
)(b) // initial call to g() with d = b
&& o // return o
add a comment |
up vote
2
down vote
up vote
2
down vote
JavaScript (ES6), 68 bytes
Takes input as (b)(k)
.
b=>k=>(o=,n=1,g=d=>(d<2?o.push(n)==k:n%d&&g(d-1))||g(b,n++))(b)&&o
Try it online!
Commented
b => k => ( // input = b and k
o = , // o = output array
n = 1, // n = value to test
g = d => ( // g = recursive function, taking the divisor d
d < 2 ? // if d = 1:
o.push(n) == k // push n into o and test whether o contains k elements
: // else:
n % d && g(d - 1) // if d is not a divisor of n, do a recursive call with d - 1
) || // if the final result of g() is falsy,
g(b, n++) // do a recursive call with d = b and n + 1
)(b) // initial call to g() with d = b
&& o // return o
JavaScript (ES6), 68 bytes
Takes input as (b)(k)
.
b=>k=>(o=,n=1,g=d=>(d<2?o.push(n)==k:n%d&&g(d-1))||g(b,n++))(b)&&o
Try it online!
Commented
b => k => ( // input = b and k
o = , // o = output array
n = 1, // n = value to test
g = d => ( // g = recursive function, taking the divisor d
d < 2 ? // if d = 1:
o.push(n) == k // push n into o and test whether o contains k elements
: // else:
n % d && g(d - 1) // if d is not a divisor of n, do a recursive call with d - 1
) || // if the final result of g() is falsy,
g(b, n++) // do a recursive call with d = b and n + 1
)(b) // initial call to g() with d = b
&& o // return o
edited Nov 3 at 14:35
answered Nov 3 at 9:28
Arnauld
67.7k584288
67.7k584288
add a comment |
add a comment |
up vote
1
down vote
Jelly, 10 bytes
1µg³!¤Ịµ⁴#
Try it online!
How it works
1µg³!¤Ịµ⁴# Dyadic main link. Left = B, right = k
µ⁴# Take first k numbers satisfying...
g GCD with
³!¤ B factorial
Ị is insignificant (abs(x) <= 1)?
1µ ... starting from 1.
add a comment |
up vote
1
down vote
Jelly, 10 bytes
1µg³!¤Ịµ⁴#
Try it online!
How it works
1µg³!¤Ịµ⁴# Dyadic main link. Left = B, right = k
µ⁴# Take first k numbers satisfying...
g GCD with
³!¤ B factorial
Ị is insignificant (abs(x) <= 1)?
1µ ... starting from 1.
add a comment |
up vote
1
down vote
up vote
1
down vote
Jelly, 10 bytes
1µg³!¤Ịµ⁴#
Try it online!
How it works
1µg³!¤Ịµ⁴# Dyadic main link. Left = B, right = k
µ⁴# Take first k numbers satisfying...
g GCD with
³!¤ B factorial
Ị is insignificant (abs(x) <= 1)?
1µ ... starting from 1.
Jelly, 10 bytes
1µg³!¤Ịµ⁴#
Try it online!
How it works
1µg³!¤Ịµ⁴# Dyadic main link. Left = B, right = k
µ⁴# Take first k numbers satisfying...
g GCD with
³!¤ B factorial
Ị is insignificant (abs(x) <= 1)?
1µ ... starting from 1.
edited Nov 3 at 7:58
answered Nov 3 at 7:46
Bubbler
4,649749
4,649749
add a comment |
add a comment |
up vote
1
down vote
JavaScript (Node.js), 68 bytes
b=>g=(k,i=1,j=b)=>k?j>1?i%j?g(k,i,j-1):g(k,i+1):[i,...g(k-1,i+1)]:
Try it online!
add a comment |
up vote
1
down vote
JavaScript (Node.js), 68 bytes
b=>g=(k,i=1,j=b)=>k?j>1?i%j?g(k,i,j-1):g(k,i+1):[i,...g(k-1,i+1)]:
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
JavaScript (Node.js), 68 bytes
b=>g=(k,i=1,j=b)=>k?j>1?i%j?g(k,i,j-1):g(k,i+1):[i,...g(k-1,i+1)]:
Try it online!
JavaScript (Node.js), 68 bytes
b=>g=(k,i=1,j=b)=>k?j>1?i%j?g(k,i,j-1):g(k,i+1):[i,...g(k-1,i+1)]:
Try it online!
answered Nov 3 at 11:00
tsh
8,03511346
8,03511346
add a comment |
add a comment |
up vote
1
down vote
APL(NARS), 52 chars, 104 bytes
r←a f w;i
r←,i←1⋄→3
i+←1⋄→3×⍳∨/a≥πi⋄r←r,i
→2×⍳w>↑⍴r
Above it seems the rows after 'r←a f w;i' have names 1 2 3;test:
o←⎕fmt
o 1 h 2
┌2───┐
│ 1 2│
└~───┘
o 1 h 1
┌1─┐
│ 1│
└~─┘
o 10 h 14
┌14───────────────────────────────────────┐
│ 1 11 13 17 19 23 29 31 37 41 43 47 53 59│
└~────────────────────────────────────────┘
add a comment |
up vote
1
down vote
APL(NARS), 52 chars, 104 bytes
r←a f w;i
r←,i←1⋄→3
i+←1⋄→3×⍳∨/a≥πi⋄r←r,i
→2×⍳w>↑⍴r
Above it seems the rows after 'r←a f w;i' have names 1 2 3;test:
o←⎕fmt
o 1 h 2
┌2───┐
│ 1 2│
└~───┘
o 1 h 1
┌1─┐
│ 1│
└~─┘
o 10 h 14
┌14───────────────────────────────────────┐
│ 1 11 13 17 19 23 29 31 37 41 43 47 53 59│
└~────────────────────────────────────────┘
add a comment |
up vote
1
down vote
up vote
1
down vote
APL(NARS), 52 chars, 104 bytes
r←a f w;i
r←,i←1⋄→3
i+←1⋄→3×⍳∨/a≥πi⋄r←r,i
→2×⍳w>↑⍴r
Above it seems the rows after 'r←a f w;i' have names 1 2 3;test:
o←⎕fmt
o 1 h 2
┌2───┐
│ 1 2│
└~───┘
o 1 h 1
┌1─┐
│ 1│
└~─┘
o 10 h 14
┌14───────────────────────────────────────┐
│ 1 11 13 17 19 23 29 31 37 41 43 47 53 59│
└~────────────────────────────────────────┘
APL(NARS), 52 chars, 104 bytes
r←a f w;i
r←,i←1⋄→3
i+←1⋄→3×⍳∨/a≥πi⋄r←r,i
→2×⍳w>↑⍴r
Above it seems the rows after 'r←a f w;i' have names 1 2 3;test:
o←⎕fmt
o 1 h 2
┌2───┐
│ 1 2│
└~───┘
o 1 h 1
┌1─┐
│ 1│
└~─┘
o 10 h 14
┌14───────────────────────────────────────┐
│ 1 11 13 17 19 23 29 31 37 41 43 47 53 59│
└~────────────────────────────────────────┘
edited Nov 3 at 19:45
answered Nov 3 at 17:17
RosLuP
1,710514
1,710514
add a comment |
add a comment |
up vote
1
down vote
05AB1E, 9 bytes
∞ʒÒ¹›P}²£
Try it online or verify all test cases.
Explanation:
∞ # Infinite list starting at 1: [1,...]
ʒ } # Filter it by:
Ò # Get all prime factors of the current number
¹› # Check for each if they are larger than the first input
P # And check if it's truthy for all of them
²£ # Leave only the leading amount of items equal to the second input
add a comment |
up vote
1
down vote
05AB1E, 9 bytes
∞ʒÒ¹›P}²£
Try it online or verify all test cases.
Explanation:
∞ # Infinite list starting at 1: [1,...]
ʒ } # Filter it by:
Ò # Get all prime factors of the current number
¹› # Check for each if they are larger than the first input
P # And check if it's truthy for all of them
²£ # Leave only the leading amount of items equal to the second input
add a comment |
up vote
1
down vote
up vote
1
down vote
05AB1E, 9 bytes
∞ʒÒ¹›P}²£
Try it online or verify all test cases.
Explanation:
∞ # Infinite list starting at 1: [1,...]
ʒ } # Filter it by:
Ò # Get all prime factors of the current number
¹› # Check for each if they are larger than the first input
P # And check if it's truthy for all of them
²£ # Leave only the leading amount of items equal to the second input
05AB1E, 9 bytes
∞ʒÒ¹›P}²£
Try it online or verify all test cases.
Explanation:
∞ # Infinite list starting at 1: [1,...]
ʒ } # Filter it by:
Ò # Get all prime factors of the current number
¹› # Check for each if they are larger than the first input
P # And check if it's truthy for all of them
²£ # Leave only the leading amount of items equal to the second input
answered 2 days ago
Kevin Cruijssen
33k554176
33k554176
add a comment |
add a comment |
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175158%2fgenerate-some-rough-numbers%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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
2
Can you elaborate on the challenge? I don't understand it. Maybe explain the examples?
– d-b
Nov 3 at 17:41
I don't understand why you include 1 in all your answers when it's never greater than
B
?– kamoroso94
Nov 3 at 17:56
1
1 has no prime factors, so every prime factor of 1 is larger than B and 1 should appear in the output independent of B.
– Hood
Nov 3 at 19:41
@d-b Factorize
n
into primes. If all of those primes are greater thanB
, n isB
-rough.– Addison Crump
Nov 3 at 20:06
@AddisonCrump So for example, since the primes for 35 are 5 and 7, 35 is 4-rough? Is this some recognized common terminology? Never heard of it before. I still don't under the examples, especially not the last one. 14 numbers but what is 10??
– d-b
Nov 3 at 20:30