18
\$\begingroup\$

The Meeker numbers are a 7 digit number in form of \$abcdefg\$, where \$a×b=10c+d\$ and \$d×e=10f+g\$. As an example \$6742612\$ is a meeker number, here \$6×7=10×4+2\$ and \$2×6=10×1+2\$, so it is a meeker number.

Additionally, a Meeker number does not have any leading zeros (so \$a \ne 0\$)

The Challenge

Your program can do one of the following tasks:

  • Take a positive integer \$n\$ and output the \$n\$th Meeker number (0 or 1 indexed, your choice. If 0 indexed, \$n\$ will be a non-negative integer)
  • Take a positive integer \$n\$ and output the first \$n\$ Meeker numbers
  • Output all 900 Meeker numbers

Rules

  • You may take an empty input if you output all Meeker numbers
  • Standard loopholes are forbidden.
  • Trailing whitespace is allowed.
  • If possible, please link to an online interpreter (e.g. TIO) to run your program on.
  • Please explain your answer. This is not necessary, but it makes it easier for others to understand.
  • Languages newer than the question are allowed. This means you could create your own language where the empty program calculates this number, but don't expect any upvotes.
  • This is , so shortest code in bytes wins!

The first few Meeker numbers are

1000000
1000100
1000200
1000300
1000400
1000500
1000600
1000700
1000800
1000900
1101000
1101101
1101202
1101303
1101404
1101505
1101606
1101707
1101808
1101909
...

Thanks to @Adám for the detailed analysis and @cairdcoinheringaahing for the editing rework

\$\endgroup\$
3
  • \$\begingroup\$ Sandbox \$\endgroup\$ – Wasif Apr 13 at 8:15
  • \$\begingroup\$ Is our program/function allowed not to terminate (i.e. print/return all the Meeker numbers and then hang forever)? \$\endgroup\$ – Delfad0r Apr 13 at 10:36
  • \$\begingroup\$ @Delfad0r yes it's allowed \$\endgroup\$ – Wasif Apr 13 at 10:49

17 Answers 17

6
\$\begingroup\$

APL (Dyalog Extended), 45 bytes (SBCS)

Full program. Prints all meeker numbers. Requires 0-based indexing (⎕IO←0).

1e6+⍸{(×⌿i⊇⍵)≡10⊥⍵[2+i←0 1,⍪3 4]}¨10⊤¨1e6…1e7

Try it online! (limited to upper bound of 2 000 000 ― above code works offline)

1e6…1e7 numbers 1 000 000 through 10 000 000

10⊤¨ base-10 representation of each (splits digits of numbers into lists of digits)

{ apply the following lambda to each:

⍵[] index the digits of the current number using the following:

  ⍪3 4 the column-vector [[3],[4]]

  0 1, prepend a column consisting of [0,1] yielding [[0,3],[1,4]]

  i← assign to i (for indices)

  2+ increase by two; [[2,5],[3,6]]

10⊥ evaluate as base-10, using the top row as tens place and bottom row as ones place

()≡ check if it matches the following:

i⊇⍵ select the elements from the digits at indices i

×⌿ multiply the elements of the top row with the elements of the bottom row

ɩndices where true

1e6+ offset to the first candidate

\$\endgroup\$
6
\$\begingroup\$

Python 2, 121 115 98 bytes

def f(n,t=10):p,q=n%100/t,1+n/100;r=p*q;s=n%t*(r%t);print`t+n/t`+'0'*(r<t)+`r`+`n%t`+'0'*(s<t)+`s`

Try it online!

On noticing the digits, I observed a pattern and got this constant time solution. Takes n as input (0-indexed) and prints n'th meeker number.

For example, the first 2 digits follow the pattern: 10, 11, 12, ... 99 (with each number occuring 10 times in a row).

thanks to ovs for -23 bytes

\$\endgroup\$
1
6
\$\begingroup\$

C (gcc), 107 \$\cdots\$ 74 73 bytes

Saved 8 bytes thanks to the man himself Arnauld!!!
Saved 5 bytes thanks to tsh!!!
Saved a whopping 20 bytes thanks to Olivier Grégoire!!!

t=10;h=100;a;b;f(n){a=n/h+1;b=n/t%t;a=(a*t*h+b*h+a*b)*t*h+n%t*(h+a*b%t);}

Try it online!

Inputs \$0\$-based \$n\$ and returns the \$n^{\text{th}}\$ Meeker number.

\$\endgroup\$
7
  • \$\begingroup\$ a*b%10*e++ without parentheses should be fine. \$\endgroup\$ – Arnauld Apr 13 at 12:27
  • \$\begingroup\$ 99 bytes \$\endgroup\$ – Arnauld Apr 13 at 12:47
  • \$\begingroup\$ @Arnauld Very nice - thanks! :D \$\endgroup\$ – Noodle9 Apr 13 at 19:26
  • \$\begingroup\$ a;b;p;q;main(){for(;b%100||9/++a;)printf("%d%d%02d%d%02d ",a,p=b/10%10,p*=a,q=b++%10,p%10*q);} \$\endgroup\$ – tsh Apr 14 at 0:36
  • \$\begingroup\$ @tsh Nice one - thanks! :D \$\endgroup\$ – Noodle9 Apr 14 at 15:00
5
\$\begingroup\$

JavaScript (SpiderMonkey), 65 bytes

for(i=99;i<999;print((e-i+'0'-a*b+e)*~99+a*b%10*e))[a,b,e]=++i+''

Try it online!

For example, when i == 267:

i=267;
[a,b,e]=i+'';
print([a, b, e]); // ["2", "6", "7"]
print(e-i); // -260
print(e-i+'0'); // "-2600"
print(a*b); // 12
print(e-i+'0'-a*b); // -2612
print(e-i+'0'-a*b+e); // "-26127"
print((e-i+'0'-a*b+e)*~99); // 2612700
print((e-i+'0'-a*b+e)*~99+a*b%10*e); // 2612714

Try it online!


JavaScript (Firefox), 72 bytes

for(f='%.2d',i=99;i<999;console.log(a+b+f+e+f,a*=b,a%10*e))[a,b,e]=++i+f

Thanks Neil for pointing out that Firefox support %.2d for padding zeros.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Sad story: Firefox support %2d but not %02d in console.log... All other browsers (Opera 12, IE 11, Chrome, Edge) does not support %2d in console.log at all. \$\endgroup\$ – tsh Apr 13 at 10:34
  • \$\begingroup\$ Nice, you didn't bruteforce it! \$\endgroup\$ – A username Apr 14 at 4:34
  • \$\begingroup\$ @tsh Use%.2d for leading zeros. \$\endgroup\$ – Neil Apr 14 at 8:44
  • \$\begingroup\$ @Neil Aha, it works! Thanks for pointing out that. But after more modification, it seems using console.log not saving bytes any more.. \$\endgroup\$ – tsh Apr 14 at 8:49
5
\$\begingroup\$

R, 101 91 71 69 bytes

Edit: -2 bytes thanks to Giuseppe, amazingly within <5 mins of posting

outer(10:99,0:9,function(a,e,d=a%%10)((a*100+a%/%10*d)*10+e)*100+d*e)

Try it online!


The original version - inspired by and taking a similar approach to Manish Kundu's answer, and also golfed-down from 101 to 96 bytes by Giuseppe:

R, 96 bytes

z=c(0,'')
paste0(a<-100:999%/%100,b<-0:99%/%10,z[(a*b>9)+1],d<-a*b,0:9,z[((f=d%%10*0:9)>9)+1],f)

Try it online!

(Note on z=c(0,''): we need to 'pad' the single digit products with a zero when building our text string, and this needs to be done in way that's compatible with the vectorized paste function. So z[(a*b>9)+1] is equivalent to (but shorter than) ifelse(a*b>9,'',0))

\$\endgroup\$
3
  • \$\begingroup\$ If you're going to only use two loops, may as well use outer for 69 bytes \$\endgroup\$ – Giuseppe Apr 14 at 16:10
  • \$\begingroup\$ @Giuseppe - I don't think I can even type that fast, let alone golf a computer program! Thanks! \$\endgroup\$ – Dominic van Essen Apr 14 at 16:19
  • \$\begingroup\$ Haha, well, I was looking at your 96 byter (again, still can't figure out how to shorten it on a fundamental level) and saw you had made an edit, and it kinda all just went from there. \$\endgroup\$ – Giuseppe Apr 14 at 18:22
4
\$\begingroup\$

Husk, 27 bytes

föΛo§=oΠ←od→C2§e←→X4dfo=7LN

Try it online!

returns the list of all meeker numbers. It's horribly inefficient, so here's a version which starts from 1e7, and shows the first n values.

EDIT: corrected the answer after Dominic Van Essen found a bug.

\$\endgroup\$
6
  • \$\begingroup\$ I wonder if anyone isn't going to brute-force it... \$\endgroup\$ – A username Apr 13 at 8:44
  • \$\begingroup\$ What about non-7-digit numbers where the first-4 and last-4 digits meet the product-digits condition? I think this will mistakenly output them as meeker numbers: try it... \$\endgroup\$ – Dominic van Essen Apr 13 at 13:13
  • \$\begingroup\$ hm, I'll change it. \$\endgroup\$ – Razetime Apr 13 at 13:51
  • \$\begingroup\$ Even with ¡→!7İ⁰ you'll still get >7-digit numbers (try this to get the idea)... \$\endgroup\$ – Dominic van Essen Apr 13 at 14:07
  • \$\begingroup\$ ok, time for more inefficiency \$\endgroup\$ – Razetime Apr 13 at 14:15
4
\$\begingroup\$

Perl 5, 58 56 bytes

/(.)(.)(.(.))(.)/,$1*$2-$3||$5*$4-$'||say for 1e6..1e7-1

Try it online!

Outputs the entire list of Meeker numbers.

\$\endgroup\$
1
  • \$\begingroup\$ The first || can be just | and 1e7-1 is the same as 9x7 for 53 bytes. \$\endgroup\$ – ovs Apr 14 at 17:07
4
\$\begingroup\$

05AB1E, 32 24 bytes

θsт+2£DSPsт*+ìD2.£SPsт*+

Try it online! Outputs the \$n^\text{th}\$ Meeker number.

\$\endgroup\$
3
\$\begingroup\$

JavaScript (Node.js), 86 bytes

_=>[...Array(1e7).keys()].filter(x=>(s=x+'')[0]*s[1]==s[2]+s[3]&&s[3]*s[4]==s[5]+s[6])

Try it online!

I feel like this is too long.

Explanation

Basically, this gets all numbers from 0 to 9999999, coerces each to a string and checks character-wise.

One of Javascript's quirks is that multiplied strings are coerced to numbers, but added ones are not. So '5'*'6' is 30, but '5'+'6' is 56.

So in s[0]*s[1]==s[2]+s[3], the first half is a number which is the product of the first two, the second half is the two cocatenated into a string, and using == allows type conversion.

Since it gets the numbers from 0 to 9999999, the numbers from 0 to 999999 are invalid and shouldn't be counted. Fortunately, since the number is coerced to a string, taking its 6th (0-indexed) character will return undefined, so it will be counted as invalid.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ 72 bytes (full V8 program) \$\endgroup\$ – Arnauld Apr 13 at 9:15
  • \$\begingroup\$ @Arnauld I knew I was doing something wrong. \$\endgroup\$ – A username Apr 13 at 9:18
  • \$\begingroup\$ You can save one byte by using bitwise AND instead of regular AND. So _=>[...Array(1e7).keys()].filter(e=>(s=e+'')[0]*s[1]==s[2]+s[3]&s[3]*s[4]==s[5]+s[6]) or similar \$\endgroup\$ – ophact Apr 13 at 9:35
  • \$\begingroup\$ @ophact Thanks. I've kind of given up - see Arnauld's comment above. \$\endgroup\$ – A username Apr 13 at 9:36
  • 1
    \$\begingroup\$ for(i=0;++i<1e7;){[a,b,c,d,e,f,g]=''+i;a*b==c+d&d*e==f+g?alert(i):0} for 68 bytes. hint: don't run this as you will have to click through 900 alert boxes. idea stolen from @Arnauld, all I did was change [...''+i] to ''+i because you can also destructure from strings \$\endgroup\$ – ophact Apr 13 at 9:41
3
\$\begingroup\$

Haskell, 82 80 76 bytes

  • -6 bytes thanks to kops, for rearranging things and proposing a better interpretation of the rules :P
[n|n<-show<$>[1..],[a,b,c,d,e,f,g]<-[read.pure<$>n],a*b==10*c+d,d*e==10*f+g]

Try it online!

The list of all Meeker numbers, represented as strings.

Haskell, 80 bytes

[n>>=show|n@[a,b,c,d,e,f,g]<-mapM([0..9]<$id)[1..7],a>0,a*b==10*c+d,d*e==10*f+g]

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ I'm not at all sure if this is allowed by the rules, but I got to 79 bytes by combining your solutions and not terminating. I guess this should at least be the shortest if you were to naively convert to doing one of the other tasks (nth term or first n terms). \$\endgroup\$ – kops Apr 13 at 10:15
  • \$\begingroup\$ 76, actually (missed your trick of just starting at 1). I guess this puts it even with your first solution at 80 bytes even if you terminate at 10^7. \$\endgroup\$ – kops Apr 13 at 10:21
  • \$\begingroup\$ @kops I wasn't sure either, but your trick still saves 2 bytes from my second solution. I don't know what the general rules about termination are for finite sequences, I'll probably ask the OP. Thanks! \$\endgroup\$ – Delfad0r Apr 13 at 10:30
3
\$\begingroup\$

Husk, 34 31 30 bytes

₁`:%10¹d₁↑2d+100
§+o*100doΠ↑_2

Try it online! or Get the whole meeker sequence

Calculates (rather than brute-forcing) the nth meeker number.

Not as short as Razetime's answer, but inspired by A username's comment "I wonder if anyone isn't going to brute-force it..." underneath it.

A nice feature of this approach is that it actually completes the task, although there were obviously never any brownie-points on offer for achieving this questionable goal…

How?

§+o*100doΠ↑_2      # helper function (₁):
                   # takes a list of digits, and returns the number formed 
                   # by appending the product of the last 2 digits.
§+                 # Add together        
        oΠ         #  product of
          ↑_2      #  last 2 digits, and
  o*100            #  100x 
       d           #  the number represented by the digits

₁`:%10¹d₁↑2d+100   # main program:
            +100   # add 100 to the input,
           d       # get the digits,
        ₁↑2        # apply helper function ₁ to the first 2 digits,
       d           # and convert this back into a list of digits;
 `:                # now append with   
   %10¹            # the input modulo 10 = last digit of input;
₁                  # finally apply helper function ₁ to the result
\$\endgroup\$
1
3
\$\begingroup\$

Jelly,  20  19 bytes

-1 thanks to Makonede (Output first \$n\$ instead of the \$n^\text{th}\$.)

DḌ,PƊƝFḊm3⁼2/Ạ
ȷ6Ç#

A monadic Link accepting an integer, \$n\in[1,900]\$, that yields the first \$n\$ Meeker numbers

Try it online! Very slow so will probably time out for \$n \gt 36\$.

How?

ȷ6Ç# - Main Link: integer, n
ȷ6   - 10^6
   # - find the first n integers starting at 10^6 for which:
  Ç  -   call Link 1

DḌ,PƊƝFḊm3⁼2/Ạ - Link 1: integer, x   e.g. 9218756
D              - digits (x)                [9,2,1,8,7,5,6]
     Ɲ         - for neighbours:
    Ɗ          -   last three links as a monad f([a,b]):
 Ḍ             -     from digits ([a,b])   [92, 21, 18, 87, 75, 56]
   P           -     product ([a,b])       [18, 2,  8, 56, 35, 30]
  ,            -     pair                  [[92, 18], [21, 2], [18, 8], [87, 56], [75, 35], [56, 30]]
      F        - flatten                   [92, 18, 21, 2, 18, 8, 87, 56, 75, 35, 56, 30]
       Ḋ       - dequeue                   [18, 21, 2, 18, 8, 87, 56, 75, 35, 56, 30]
        m3     - modulo-3-slice            [18,        18,        56,         56]
           2/  - pairwise reduce by:
          ⁼    -   equal?                  [1,1]
             Ạ - all?                      1
\$\endgroup\$
5
  • 1
    \$\begingroup\$ What prevents this from incorrectly outputting non-meeker numbers for indices >900 (or doesn't that matter?) \$\endgroup\$ – Dominic van Essen Apr 14 at 16:26
  • \$\begingroup\$ @DominicvanEssen I am 99% sure that's undefined behavior. \$\endgroup\$ – Makonede Apr 14 at 16:34
  • \$\begingroup\$ By the way, -1 by removing to output the first \$n\$ Meeker numbers. \$\endgroup\$ – Makonede Apr 14 at 16:37
  • 1
    \$\begingroup\$ @DominicvanEssen I was assuming we may Do Anything when given invalid input. \$\endgroup\$ – Jonathan Allan Apr 14 at 17:04
  • 1
    \$\begingroup\$ @Makonede Oh yeah, silly me; thanks! \$\endgroup\$ – Jonathan Allan Apr 14 at 17:04
3
\$\begingroup\$

Java (JDK), 75 bytes

n->{int a=n/100+1,b=n/10%10;return(a*1e3+b*100+a*b)*1e3+n%10*(100+a*b%10);}

Try it online!

Outputs the nth number, 0-indexed.

Credits

\$\endgroup\$
1
  • 1
    \$\begingroup\$ -2 bytes by outputting as double and changing the 1000 to 1e3. \$\endgroup\$ – Kevin Cruijssen yesterday
2
\$\begingroup\$

Charcoal, 33 bytes

F…χ¹⁰⁰Fχ⟦⪫⟦ι﹪%02dΠικ﹪%02d×﹪Πιχκ⟧ω

Try it online! Link is to verbose version of code. Prints all 900 Meeker numbers. Explanation:

F…χ¹⁰⁰

Loop over all possible first pairs of digits.

Fχ

Loop over all possible fifth digits.

⟦⪫⟦...⟧ω

Print the following items on one line and then move to the next line.

ι

The first two digits.

﹪%02dΠι

The product of the first two digits, left zero-padded to 2 digits.

κ

The fifth digit.

﹪%02d×﹪Πιχκ

The last two digits.

\$\endgroup\$
2
\$\begingroup\$

Pyth, 58 bytes

A(/%Q100T+1/Q100)A(*GH*%*GHT%QT)s[+T/QT*"0"<GTG%QT*"0"<HTH

Try it online!

Same as my Python solution. A assigns the two provided elements to the variables G and H respectively. Q is the input (zero-indexed).

\$\endgroup\$
2
\$\begingroup\$

Scala, 103 bytes

Stream from 1 map "".+filter{x=>x.size==7&&x.map(_-48).sliding(4,3).forall{x=>x(0)*x(1)==10*x(2)+x(3)}}

Try it in Scastie!

A pretty straightforward answer. You can treat it like a function giving the nth Meeker number (0-indexed) or as a list of all Meeker numbers.

\$\endgroup\$
1
\$\begingroup\$

Retina, 65 bytes


999*¶

$.`
G`...

;
+`(.);(.)
$1$2,0$.($1*$2*
;|,0?(?=...,|..;)

Try it online! Outputs all 900 Meeker numbers. Explanation:


999*¶

$.`

Insert all the numbers from 0 to 999.

G`...

Keep only the 3-digit numbers.

;

Insert separators around all of the digits.

+`(.);(.)
$1$2,0$.($1*$2*

Multiply the first and second digits, then multiply the last digit of the result by the third digit, inserting an extra 0 prefix for each result.

;|,0?(?=...,|..;)

Delete unnecessary separators and 0s.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.