7
\$\begingroup\$

My user id is 106959

How to check if the number is Fmbalbuena number?

First Step: Check if the number of digits is a multiple of 3: 6 = 3 * 2

Second step: Split the digits into even thirds: 106959 -> 10 69 59

Third step: Subtract the first set of digits from the second modulo 10: 6 - 1 = 5, 9 - 0 = 9

Last step: Check that the result is the same as the third set of digits: 59 = 59

Sequence

Here is the sequence until 106959

109, 110, 121, 132, 143, 154, 165, 176, 187, 198, 208, 219, 220, 231, 242, 253, 264, 275, 286, 297, 307, 318, 329, 330, 341, 352, 363, 374, 385, 396, 406, 417, 428, 439, 440, 451, 462, 473, 484, 495, 505, 516, 527, 538, 549, 550, 561, 572, 583, 594, 604, 615, 626, 637, 648, 659, 660, 671, 682, 693, 703, 714, 725, 736, 747, 758, 769, 770, 781, 792, 802, 813, 824, 835, 846, 857, 868, 879, 880, 891, 901, 912, 923, 934, 945, 956, 967, 978, 989, 990, 100090, 100191, 100292, 100393, 100494, 100595, 100696, 100797, 100898, 100999, 101000, 101101, 101202, 101303, 101404, 101505, 101606, 101707, 101808, 101909, 102010, 102111, 102212, 102313, 102414, 102515, 102616, 102717, 102818, 102919, 103020, 103121, 103222, 103323, 103424, 103525, 103626, 103727, 103828, 103929, 104030, 104131, 104232, 104333, 104434, 104535, 104636, 104737, 104838, 104939, 105040, 105141, 105242, 105343, 105444, 105545, 105646, 105747, 105848, 105949, 106050, 106151, 106252, 106353, 106454, 106555, 106656, 106757, 106858, 106959

You can generate the first N numbers, infinite numbers, Check if the number is Fmbalbuena number or get Nth number of the sequence

Test cases

Truthy

106959
109
219
103222
666666000
777666999

Falsy

100
230
320
666666666
125466
1069592
\$\endgroup\$
0

10 Answers 10

5
\$\begingroup\$

05AB1E, 14 13 bytes

Checks if a given number is a Fmbalbuena:

S3äR`-T%Q*g3Ö

Could be 12 bytes by taking the input as a list of digits, removing the leading S.

Try it online or verify all test cases.

We can add a leading ∞ʒD to output the infinite sequence:
Try it online.

Explanation:

S          # Split the (implicit) input-integer to a list of digits
 3ä        # (Try to) split it into three equal-sized parts
   R       # Reverse these parts from [A,B,C] to [C,B,A]
    `      # Pop and push all three lists separated to the stack
     -     # Subtract the digits of the top two lists: B-A
      T%   # Modulo-10
        Q  # Check if it's equal to C: B-A=C (1 if truthy; 0 if falsey)
*          # Multiply this by the (implicit) input-integer
           # (remains unchanged if the check was truthy or becomes 0 otherwise)
 g         # Pop and push its length
  3Ö       # Check if this is divisible by 3
           # (after which it is output implicitly as result)
∞          # Push an infinite positive list: [1,2,3,...]
 ʒ         # Filter it by:
  D        #  Duplicate the current integer
   S3äR`-T%Q*g3Ö
           #  Same as above
           # (after which the filtered infinite list is output implicitly as result)
\$\endgroup\$
3
  • \$\begingroup\$ Test cases are added, can you change the test cases? \$\endgroup\$
    – Fmbalbuena
    Jan 13, 2022 at 12:07
  • \$\begingroup\$ @Fmbalbuena Done, although one of your test cases is incorrect. \$\endgroup\$ Jan 13, 2022 at 12:25
  • \$\begingroup\$ Edited a test case \$\endgroup\$
    – Fmbalbuena
    Jan 13, 2022 at 16:37
4
\$\begingroup\$

JavaScript (ES6), 66 bytes

Expects the input number as a string. Returns a Boolean value.

n=>![...n].some((d,i)=>i<(l=n.length/3)&(n[i+=l]-d+10)%10!=n[i+l])

Try it online!

How?

We don't explicitly test whether the length of the input number is a multiple of 3. When it's not, l is a non-integer value, both n[i+l] and n[i+2*l] are undefined, n[i+l]-d+10 is NaN, and we end up testing NaN != undefined, which is true and makes the test fail as expected.

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

Brachylog, 13 9 8 bytes

ḍ₃\-ᵐtᵛ0

Try it online! (infinite sequence version)

Not sure how I missed that by making it about congruence to 0, I dodged any thorny sign issues in taking the last digit versus performing a proper mod 10.

ḍ₃          Split the input into three digit lists of similar lengths.
  \         Check that the lengths are strictly equal, and transpose.
    ᵐ       For each triple,
   -        subtract the second digit from the sum of the first and third.
     tᵛ0    Is the last digit of every difference 0?
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Finally is useful for something! \$\endgroup\$
    – Fatalize
    Jan 14, 2022 at 15:02
  • \$\begingroup\$ @Fatalize I haven't been too active with Brachylog lately, but has always felt pretty useful to me--granted, a lot of the time it ends up being ≡ᵛ, which can usually be equivalent to =h. I'd say the real standout here is how - generalizes to longer lists: it seems like it should broadly be the more useful behavior than, say, reducing by subtraction, but I can't say I remember the last time it actually came up. \$\endgroup\$ Jan 14, 2022 at 16:59
3
\$\begingroup\$

Charcoal, 27 bytes

¬∨﹪Lθ³⊙∕θ³﹪⍘⭆³§§⪪θ÷Lθ³λκ±¹χ

Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - if the input is an Fmbalbuena number, nothing if not. Explanation:

    θ                       Input as a string
   L                        Length
  ﹪  ³                      Is not divisible by `3`
 ∨                          Logical Or
        θ                   Input as a string
       ∕ ³                  Reduced to a third in length
      ⊙                     Any index satisfies
             ³              Literal integer `3`
            ⭆               Map over implicit range and join
                 θ          Input string
                ⪪ ÷Lθ³      Split into three parts
               §            Indexed by
                      λ     Inner value
              §             Indexed by
                       κ    Outer index
           ⍘            ±¹  Interpreted as base `-1`
          ﹪               χ Is not divisible by `10`
¬                           Logical Not
                            Implicitly print
\$\endgroup\$
2
  • \$\begingroup\$ 666777999 must give - because 6 - 7 gives -1 and mod by 10 gives 9 \$\endgroup\$
    – Fmbalbuena
    Jan 13, 2022 at 12:29
  • 5
    \$\begingroup\$ @Fmbalbuena Then it wouldn't work for your user id, because 0 - 9 gives -9 and mod by 10 gives 1. \$\endgroup\$
    – Neil
    Jan 13, 2022 at 13:53
3
\$\begingroup\$

Vyxal, 19 14 bytes

L3/₌ẎȯI÷‟-ȧ₀%⁼

Try it Online!

Checks whether an input number is a Fmbalbuena number. Takes input as a list of digits.

can't believe I forgot to handle the case where the length isn't divisible by 3...

-5 thanks to Fmbalbuena

Explained

L3/₌ẎȯI÷‟-ȧ₀%⁼
L                   # Push the length of the input
 3/                 # divide that by 3
   ₌Ẏȯ              # and push input[0:that], input[that:-1]
      I             # split input[that:-1] into two lists
       ÷            # and dump that onto the stack - the stack is now [first N/3, remaining first half, remaining second half]
        ‟           # rotate the stack right - this sets it up for the subtraction
         -ȧ         # subtract the first N/3 digits from the second half and take the absolute value
           ₀%       # and modulo by 10
             ⁼      # does that exactly equal the first half?
\$\endgroup\$
10
  • \$\begingroup\$ The input must be a number \$\endgroup\$
    – Fmbalbuena
    Jan 13, 2022 at 11:56
  • 4
    \$\begingroup\$ @Fmbalbuena no it doesn't \$\endgroup\$
    – lyxal
    Jan 13, 2022 at 11:57
  • \$\begingroup\$ just kidding, explain? \$\endgroup\$
    – Fmbalbuena
    Jan 13, 2022 at 11:57
  • \$\begingroup\$ I'm working on that right now lol \$\endgroup\$
    – lyxal
    Jan 13, 2022 at 11:57
  • 1
    \$\begingroup\$ @Fmbalbuena I just need a second to change the explanation lol \$\endgroup\$
    – lyxal
    Jan 13, 2022 at 12:18
3
\$\begingroup\$

Factor + grouping.extras, 75 45 bytes

[ 3 n-group first3 spin v- [ 10 rem ] map = ]

Returns whether or not the input is a Fmbalbuena number.

enter image description here

Explanation

                   ! { 1 0 6 9 5 9 }
3 n-group          ! { { 1 0 } { 6 9 } { 5 9 } }
first3             ! { 1 0 } { 6 9 } { 5 9 }
spin               ! { 5 9 } { 6 9 } { 1 0 }
v-                 ! { 5 9 } { 5 9 }
[ 10 rem ] map     ! { 5 9 } { 5 9 }
=                  ! t
\$\endgroup\$
3
\$\begingroup\$

Jelly, 14 bytes

Dœs3µZI%⁵z-Ḣ⁼Ṫ

A monadic Link accepting a positive integer that yields 1 if it is Fmbalbuena, or 0 if not.

Try it online!
Or test every positive integer up to and including \$106959\$ here.

How?

Dœs3µZI%⁵z-Ḣ⁼Ṫ - Link: positive integer, I
D              - digits of I
   3           - literal three
 œs            - split the digits into three equal(ish) parts
                  (if not equally splittable leftmost get longer first)
    µ          - start a new monadic chain with X=that as the argument
             Ṫ - tail X (gets the digits in the last part and modifies X)
     Z         - transpose the remaining parts
      I        - deltas
        ⁵      - literal ten
       %       - modulo (the deltas)
          -    - literal minus one
         z     - transpose with filler -1 (avoiding false positives like 1009)
           Ḣ   - head
            ⁼  - does that equal the tail we removed?
\$\endgroup\$
3
\$\begingroup\$

R, 65 bytes

function(x,y=matrix(x,,3))!any((y[,2]-y[,1])%%10-y[,3],sum(x,-y))

Try it online!

Input as list of digits; checks whether this is a 'Fmalbuena' number.
+24 bytes for input as integer.

Pretty straightforward, except that we can check whether length of x is divisible by 3 using sum(x,-y) instead of length(x)%%3 (or its usual R golf sum(x|1)%%3), since we know that all elements of x must be non-negative, and the first one must be positive.

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

Python3, 246 bytes

This can probably be cut down a bit, but I didn't see a Python answer, so I thought I'd try it out. Just counting the actual code in the byte count, not the characters assigning the n variable.

n=106959
c=lambda:int(len(str(n))/3);f=lambda z,x,y:int(list(z[x])[y])
j=str(n);a=[j,list(j),len(list(j))];
if(len(a[0])%3==0):z=[a[0][x:x+c()]for x in range(0,a[2],c())];p="%s%s"%(f(z,1,0)-f(z,0,0),f(z,1,1)-f(z,0,1));print(p==z[-1:][0])
else:print(False)
\$\endgroup\$
0
\$\begingroup\$

J, 64 bytes

Check whether a number is Fmbalbuena. The input is a number as a string, for example '219'. Yield 1 if the number is Fmbalbuena, 0 otherwise.

([:>(2{])((9|~[)=9|~])&.>(1{])-&.>0{])(]$~3,3%~#)".&.>(#$1<;.1])

                                                      (#$1<;.1]) split into digits (characters)
                                                 ".&.> convert digits into real digits
                                      (]$~3,3%~#) reshape into thirds
([:>(2{])((9|~[)=9|~])&.>(1{])-&.>0{]) substract modulo 9 and check for equality

It can probably golfed a lot more but I am helpless when it comes to performing operations on cells.

\$\endgroup\$

Your Answer

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

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