16
\$\begingroup\$

Echo numbers (A383896) are positive integers k such that the largest prime factor of k-1 is a suffix of k.

example
k = 4971 is an Echo number because k-1 = 4970 = 2*5*7*71 and k ends in 71

Here are the first Echo numbers:

13, 57, 73, 111, 127, 163, 193, 197, 313, 323, 337, 419, 433, 687, 757, 817, 847, 897, 929, 931, 973...

Input
A positive integer n

Output
The n-th Echo Number or the first n Echo numbers

n -> n-th Echo number 
1 -> 13 
10 -> 323 
101 -> 17191 
1015 -> 692231 
10158 -> 23421249

0 or 1 indexed is allowed, just specify which one your code uses.

This is Code-Golf: shortest answer in bytes wins!

Jordan
11.9k1 gold badge36 silver badges56 bronze badges
asked May 19 at 15:29
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Can we return a lazy enumerator/generator that yields the sequence, as in the default sequence rules? \$\endgroup\$ Commented May 19 at 19:55
  • 1
    \$\begingroup\$ @Jordan yes, you can \$\endgroup\$ Commented May 19 at 20:15

17 Answers 17

8
\$\begingroup\$

JQ, 112 bytes

1|recurse(.+1)|select(. as$b|"\(.)"|test($b-1|last(recurse(. as$a|./first(range(2;.)|select($a%.<1))))|"\(.)$"))

Link: https://play.jqlang.org/s/1H_9T-EpbqgqtMA

answered May 19 at 18:46
\$\endgroup\$
7
\$\begingroup\$

Racket, 196 bytes

(require math/number-theory)
(define(f n[i 3])(let([k(+ i 1)][e(car(last(factorize(- i 1))))])(if(= 0 n)'()(if(= 0(modulo(- i e)(expt 10(ceiling(/(log e)(log 10))))))(cons i(f(- n 1)k))(f n k)))))

Try it online!

Returns the first n echo numbers.

TIO doesn't seem to recognize (log z [b]) and that's why I used (/ (log z) (log b)) instead. The suffix matching could most probably be done nuch shorter with regex.

answered May 19 at 19:48
\$\endgroup\$
5
\$\begingroup\$

Jelly, 12 bytes

DḌÐƤf’ÆfṪƊƲ#

A full program that accepts the count, \$n\$, from stdin and prints the first \$n\$ echo numbers.

Try it online!

How?

DḌÐƤf’ÆfṪƊƲ# - Main Link: no arguments
 # - start at k=0 and count up finding the first {stdin} k for which:
 Ʋ - last four links as a monad - f(k):
D - decimal digits of {k}
 ḌÐƤ - convert suffixes of {that} from decimals to integers
 Ɗ - last three links as a monad - f(k):
 ’ - decrement {k}
 Æf - prime factors
 Ṫ - tail (maximal)
 f - {suffix integers} filter keep {maximal prime factor of k-1}
 - implicit print
answered May 19 at 19:35
\$\endgroup\$
5
\$\begingroup\$

Arturo, (削除) 65 (削除ここまで) 64 bytes

$=>[select.n:&1..∞'x->suffix?~"|x|"~"|x-1last factors.prime|"]

Try it!

Returns the 1-indexed \$n\$th term.

answered May 19 at 21:48
\$\endgroup\$
5
\$\begingroup\$

Ruby, 56 bytes

-10 bytes thanks to Value Ink

Prints the sequence indefinitely.

i=2
loop{p i if/#{i.prime_division[-1][0]}$/=~"#{i+=1}"}

Attempt This Online!

answered May 19 at 19:55
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Since infinite printing is allowed in the sequence rules you can do Ruby, 56 bytes: i=2;loop{p i if/#{i.prime_division[-1][0]}$/=~"#{i+=1}"} \$\endgroup\$ Commented May 23 at 0:44
  • \$\begingroup\$ @ValueInk Nice. Thanks! \$\endgroup\$ Commented May 23 at 1:42
4
\$\begingroup\$

Factor + lists.lazy math.primes.factors, 65 bytes

[ 3 lfrom [ dup >dec swap 1 - factors last >dec tail? ] lfilter ]

Attempt This Online!

Returns a lazy list of the sequence.

answered May 19 at 22:47
\$\endgroup\$
3
\$\begingroup\$

Vyxal r, 10 bytes

λ‹ǏGSnøE;ȯ

Try it Online!

Vyxal 3 still needs a prime factors element but it has prime exponents :p

answered May 19 at 22:38
\$\endgroup\$
3
\$\begingroup\$

Maple, 78 bytes

for n do`if`(n mod 10^(1+ilog10((p:=max(op~(ifactors(n-1)[2])))))=p,n,NULL)od;

Prints an infinite sequence. A golfed version of @Robert Israel's code on the OEIS page.

answered May 20 at 0:19
\$\endgroup\$
3
\$\begingroup\$

JavaScript (V8), 76 bytes

Prints the sequence indefinitely.

for(k=9;++k;)(g=x=>x>1?g(x%d++?x:x/--d):k+g)(k-1,d=2).match(d+"x")&&print(k)

Try it online!


JavaScript (ES6), 79 bytes

Returns the \$n\$-th term of the sequence, 1-indexed.

f=(n,k)=>!(g=x=>x>1?g(x%d++?x:x/--d):k+g)(k-1,d=2).match(d+"x")||n--?f(n,-~k):k

Try it online!

Commented

f = ( // f is a recursive function taking:
 n, // n = input
 k // k = counter, initially undefined
) => //
!( //
 g = x => // g is a recursive function taking x:
 x > 1 ? // if x is greater than 1:
 g( // do a recursive call to g:
 x % d++ ? // if d is not a divisor of x
 // (increment d afterwards):
 x // leave x unchanged
 : // else:
 x / --d // restore d and divide x by d
 ) // end of recursive call
 : // else:
 k + g // return k, converted to a string with
) // a suffix starting with "x"
(k - 1, d = 2) // initial call to g with k - 1 and d = 2
.match(d + "x") // if d is not a suffix of k
|| n-- ? // or n is not 0 (decrement it afterwards):
 f(n, -~k) // try again with k + 1
: // else:
 k // stop and return k
answered May 19 at 21:28
\$\endgroup\$
3
\$\begingroup\$

05AB1E, (削除) 9 (削除ここまで) 8 bytes

∞ʒD<fθÅ¿

Outputs a lazy infinite list.

Try it online.

Explanation:

∞ # Push an infinite positive list: [1,2,3,...]
 ʒ # Filter this list by:
 D # Duplicate the current value
 < # Decrease the copy by 1
 f # Pop and push a list of its prime factors
 θ # Pop and leave the last/maximum value
 # (for n=1 or n=2, the list is empty, and this will be a no-op)
 Å¿ # Check whether the value has this maximum prime factor as prefix
 # (which will be falsey for the empty lists of n=1 or n=2)
 # (after which the infinite lazy list is output implicitly)
answered May 21 at 14:15
\$\endgroup\$
2
\$\begingroup\$

Uiua 0.17.0-dev.1, (削除) (削除ここまで) 28 bytes SBCS

⍥(+1.⍢+1(×ばつ-1.))⊙3

Try on Uiua Pad!

Takes \$n\$ on the stack and outputs an array with the first \$n\$ terms.

Explanation

⍥(+1.⍢+1(×ばつ-1.))⊙3
⊙3 # Starting at 3
⍥ # do the following n times...
(×ばつ-1.)# test if n is NOT an echo numbe×ばつ-1. # factor n-1
⊣ # last factor
∩°⋕ # stringify both
∩⇌ # reverse both
⌕ # find occurances
¬⊢ # !(first element)
⍢+1 # add 1 while TRUE
+1. # leave result on stack, add 1, start over
answered May 19 at 20:29
\$\endgroup\$
2
\$\begingroup\$

Retina, 69 bytes

K`9
"$+"{/(.+)¶1円$/^{L$`^.+
$.(*__)¶$&*
+`¶(__+)1円+$
¶1ドル
)`_+
$.&
G`^

Try it online! Outputs the 1-indexed nth number. Explanation:

K`9

Start with k=9.

"$+"{`

Repeat n times.

L$`^.+
$.(*__)¶$&*

Increment k, then follow it with the new k-1 in unary.

+`¶(__+)1円+$
¶1ドル

Find the largest prime factor of k-1.

_+
$.&

Convert it back to decimal.

/(.+)¶1円$/^`{
)`

Repeat until k ends with that prime factor. (The inner loop automatically restarts because the prime factor was removed on the previous iteration of the outer loop.)

G`^

Remove the prime factor.

answered May 20 at 7:14
\$\endgroup\$
2
\$\begingroup\$

Charcoal, 39 bytes

NθW‹jθ«≦⊕χ¿¬⌕⮌Iχ⮌I⊟Φ...2χ∧¬%⊖χκ⬤...2κ%κμ⟦Iχ

Try it online! Link is to verbose version of code. Outputs the first n numbers. Explanation:

Input n.

W‹jθ«

Repeat until n numbers have been output.

≦⊕χ

Increment k, using the variable that is predefined to the value 10.

¿¬⌕⮌Iχ⮌I⊟Φ...2χ∧¬%⊖χκ⬤...2κ%κμ

Find all factors of k-1, filter on those that are prime, take the largest, and see wither k ends with it.

⟦Iχ

If so then output k.

answered May 20 at 7:40
\$\endgroup\$
2
\$\begingroup\$

Pyth, 13 bytes

.f!x_`Z_`&FPt

Try it online!

Outputs the first n numbers.

Explanation

.f!x_`Z_`&FPtZQ # implicitly add ZQ
 # implicitly assign Q = eval(input())
.f Q # return the first Q integers that are truthy in lambda Z
 tZ # Z - 1
 P # prime factors as a sorted list
 &F # take the last element (unless list is empty, then return [])
 _` # stringify and reverse
 x_`Z # find within Z stringified and reversed
 ! # not (is truthy only when result is 0)
answered May 20 at 15:07
\$\endgroup\$
2
\$\begingroup\$

Vyxal 3, 15 bytes

kNʎ‹K~℗G⇄n⇄Pc}i

There's probably a better way to check for suffixes than this but i can't figure it out. My lack of sleep doesn't help.

Vyxal It Online!

kNʎ‹K~℗G⇄n⇄Pc}i­⁡​‎‎⁡⁠⁤⁣‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤⁢‏⁠‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁤‏⁠⁠⁠‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏‏​⁡⁠⁡‌­
 i # ‎⁡index implicit input in list
kN # ‎⁢natural numbers
 ʎ } # ‎⁣filtered by...
 ‹ # ‎⁤is n-1's
 K~℗G # ‎⁢⁡biggest prime factor
 ⇄n⇄Pc # ‎⁢⁢a suffix of n?
💎

Created with the help of Luminespire.

<script type="vyxal3">
kNʎ‹K~℗G⇄n⇄Pc}i
</script>
<script>
 args=[["0"],["1"],["2"],["3"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>

answered May 21 at 9:24
\$\endgroup\$
2
\$\begingroup\$

TI-BASIC (TI-83 Plus), 115 bytes

not my proudest one.

Input I
1→O
While I
O+2→O
O-1→N
For(A,N-1,2,-1
N/A→Z
If not(fPart(Z
Then
sum(not(fPart(seq(Z/B,B,2,Z→C
If C=1
Z→U
End
End
If sum(seq(U=10^(E)fPart(O/10^(E)),E,1,1+log(O
Then
Disp O
I-1→I
End
End

Keep in mind this is EXTREMELY SLOW.

this is 1-indexed

answered May 22 at 13:00
\$\endgroup\$
0
\$\begingroup\$

Python, 259 bytes


Golfed version. Try It Online!

def C(n):
 B=[];A=2
 while n>1:
 while n%A==0:B.append(A);n=n//A
 A+=1
 return B
def D(factors):
 A={}
 for B in factors:A[B]=A.get(B,0)+1
 return A
A=10
while True:
 E=C(A-1);F=D(E);B=False
 for(H,G)in F.items():
 if G==A:B=True;break
 if B:print(A)
 A+=1

Ungolfed version. Try It Online!

def get_prime_factorization(n):
 """Get prime factorization of n as a list of factors"""
 factors = []
 divisor = 2
 
 while n > 1:
 while n % divisor == 0:
 factors.append(divisor)
 n = n // divisor
 divisor += 1
 
 return factors
def count_factor_occurrences(factors):
 """Count occurrences of each factor"""
 counts = {}
 for factor in factors:
 counts[factor] = counts.get(factor, 0) + 1
 return counts
# Main loop starting from k = 10
k = 10
while True:
 factors = get_prime_factorization(k - 1)
 factor_counts = count_factor_occurrences(factors)
 
 # Check if any factor appears exactly k times
 found = False
 for factor, count in factor_counts.items():
 if count == k:
 found = True
 break
 
 if found:
 print(k)
 
 k += 1
answered May 23 at 8:58
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.