28
\$\begingroup\$

NOTE: Some terminology used in this challenge is fake.

For two integers n and k both greater than or equal to 2 with n > k, n is semidivisible by k if and only if n/k = r/10 for some integer r. However, n may not be divisible by k. Put more simply, the base 10 representation of n/k has exactly one digit after the decimal place. For example, 6 is semidivisible by 4 because 6/4=15/10, but 8 is not semidivisible by 4 because 8 % 4 == 0.

Your task is to write a program which takes in two integers as input, in any convenient format, and outputs a truthy (respectively falsy) value if the first input is semidivisible by the second, and a falsey (respectively truthy) value otherwise. Standard loopholes are forbidden. You may assume that n > k and that both n and k are at least 2.

Test cases:

[8, 4] -> falsey
[8, 5] -> truthy
[9, 5] -> truthy
[7, 3] -> falsey

This question is therefore shortest answer in bytes wins.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Do our chosen outputs for truthy & falsey need to be consistent? \$\endgroup\$
    – Shaggy
    Mar 6, 2021 at 23:44
  • \$\begingroup\$ @Shaggy not necessarily \$\endgroup\$
    – user100690
    Mar 7, 2021 at 7:50

34 Answers 34

1
2
1
\$\begingroup\$

Brachylog, 7 bytes

/ṫkt"."

Try it online!

Explanation

/          Divide n by k
 ṫ         Cast to string
  kt"."    The penultimate character must be "."
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog Unicode), 18 bytes

{≠/0=1|q,10×q←⍺÷⍵}

Not as clever as this solution, but whatcha gonna do... :shrug:

≠/ ⍝ fold by way of not equals (xor)
  0=1| ⍝ divisibility check
      q,10×q ⍝ concatenate 
           q←⍺÷⍵ ⍝ assignment

Try it online!

\$\endgroup\$
0
\$\begingroup\$

VBScript, 45 bytes

sub f(n,k)
msgbox 10*n mod k<>n mod k
end sub

Porting of @xnor's answer a little changed.

Check if 10n is multiple of k but n itself not by checking those conditions aren't equal with <>

\$\endgroup\$
0
\$\begingroup\$

Piet + ascii-piet, 37 bytes (29×2=58 codels)

TABLiIiIAQJjJjJBDFjJBRLBiIIAQJAMVcRrr

Try Piet online!

As an image:

enter image description here

This is just rotated to make the ASCII encoding shorter. In ASCII, unminified, without being rotated:

tabliiaqjjjbdfjbrlbiiaqjamvcr
    ii   jj   j    i       rr

As an image:

enter image description here

Explanation generated by Bubbler's interpreter:

enter image description here

So basically input, duplicate, input, duplicate, push top value of stack three values down (producing b,a,a,b), multiply by 10, swap, modulo, logical not, push top value of stack two values down, modulo, multiply, logical not, logical not, output.

\$\endgroup\$
1
2

Your Answer

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