76
\$\begingroup\$

For a while now, I've been running into a problem when counting on my fingers, specifically, that I can only count to ten. My solution to that problem has been to count in binary on my fingers, putting up my thumb for one, my forefinger for two, both thumb and forefinger for three, etc. However, we run into a bit of a problem when we get to the number four. Specifically, it requires us to put up our middle finger, which results in a rather unfortunate gesture, which is not typically accepted in society. This type of number is a rude number. We come to the next rude number at 36, when we raise the thumb on our second hand and the middle finger of our first hand. The definition of a rude number is any number that, under this system of counting, results in us putting up only the middle finger of any hand. Once we pass 1023 (the maximum number reachable on one person, with two hands of five fingers each), assume we continue with a third hand, with additional hands added as required.

Your Task:

Write a program or function that receives an input and outputs a truthy/falsy value based on whether the input is a rude number.

Input:

An integer between 0 and 109 (inclusive).

Output:

A truthy/falsy value that indicates whether the input is a rude number.

Test Cases:

Input:    Output:
0   --->  falsy
3   --->  falsy
4   --->  truthy
25  --->  falsy
36  --->  truthy
127 --->  falsy
131 --->  truthy

Scoring:

This is , so the lowest score in bytes wins.

\$\endgroup\$
11
  • 46
    \$\begingroup\$ assume we continue with a third hand, When it comes to being rude, teamwork makes the dream work. \$\endgroup\$ – Veskah Feb 27 '19 at 3:24
  • 5
    \$\begingroup\$ @Veskah turns out that for the bounds of the question, you only need 3 people to make any given number. Sure beats the old kind of counting on fingers. \$\endgroup\$ – Gryphon Feb 27 '19 at 3:26
  • 12
    \$\begingroup\$ It's worse if you're British - 6 is rude too then! \$\endgroup\$ – Matthew Feb 27 '19 at 7:07
  • 1
    \$\begingroup\$ Is it OK to take input in a different base than 10? \$\endgroup\$ – wastl Feb 27 '19 at 20:08
  • 2
    \$\begingroup\$ 5 seems fairly rude too. Not sure anyone would say "Oh she had her thumb out, that's perfectly polite" \$\endgroup\$ – ale10ander Mar 1 '19 at 1:43

39 Answers 39

1
2
0
\$\begingroup\$

Perl 5, 43 bytes

sub f{sprintf("%099b",@_)=~/00100(.{5})*$/}

Try it online!

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

Ink, 38 36 bytes

=r(n)
{n:{n%32-4:->r(n/32)|1}|0}->->

Try it online!

Edit: Saved 2 bytes by simplifying the first conditional to "if n" rather than "if n>0".

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

K 8 Bytes

|/4=32\:

True if any digit of 32-base is 4

  • 32\: converts its argument to 32-base

  • 4=32\: compares 4 with each of the digits of 32: (generates a boolean list)

  • |/ is max-over the boolean list (any)

NOTES:

  • Use example: for argument 131 |/4=32\:131 returns 1b (1b for true 0b for false)

  • For all the case tests: (|/4=32\:)'0 3 4 25 36 127 131 returns 0010101b

  • If a function is needed, use {|/4=32\:x} (lambda, 11 Bytes) or with name r:{|/4=32\:x}. For all case tests {|/4=32\:x}'0 3 4 25 36 127 131 or r'0 3 4 25 36 127 131

  • 4 in 32\: is easier to read than |/4=32\:, but it's longer (9 bytes)

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

Java 1, 42 40 bytes

r(int n){return n>0&&(4==n%32|r(n>>5));}

Edit: Replaced ternary operator with && to save 1 char, thanks to @Dillon Davis, which works due to short-circuit; inspiring me to change || to | to save another character

Try it online.

Explanation:

r(int n)        // Method with int parameter and boolean return-type
  n>0           // Stop recursion if no more bits
  &&            // Short-circuit stops recursion
  n%32=4        // Rude
  | r(n>>5)     // Recurse with shifted bits
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Saves 1 byte r(int n){return n>0&&(4==n%32||r(n>>5));} \$\endgroup\$ – Dillon Davis Mar 4 '19 at 4:47
  • \$\begingroup\$ @DillonDavis Thanks! And that inspired me to save another byte changing || to | \$\endgroup\$ – Daniel Widdis Mar 4 '19 at 5:15
0
\$\begingroup\$

Kotlin, 24 bytes

Simple base-32 conversion approach.

{'4' in it.toString(32)}

{  // lambda implicitly takes an int and returns a boolean
 '4' in  // 4 is within...
        it.toString(32)  // arg written in base-32
}

Try it online!

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

05AB1E, 5 bytes

32в4¢

Try it online!

Returns a truthy value (> 1) if the input is a rude number, and 0 otherwise. Uses a conversion to base 32 (to group by 5 bits) and tests for a 4 (00100 in binary, a rude number)

\$\endgroup\$
2
  • \$\begingroup\$ lol, there's already a 5-byter \$\endgroup\$ – ASCII-only Mar 11 '19 at 0:01
  • \$\begingroup\$ That is a different language. \$\endgroup\$ – user85052 Jan 9 '20 at 4:28
0
\$\begingroup\$

Perl 6, 16 bytes

{.base(32)~~/4/}

Returns 「4」 (truthy) when given a rude number and Nil (falsy) otherwise.

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

GolfScript, 10 bytes

Empty list is false, a list with something is true. (Seems like cheating. But it isn't.)

~32base 4&

Try it online!

Explanation

~           # Evaluate the input
 32base     # Convert to base-32
            # Copy
        4&  # Setwise and: does this list have 4?
\$\endgroup\$
0
\$\begingroup\$

Jelly, 6 bytes

ḃ32=4Ẹ

Try it online!

Returns 1 if the number is rude, 0 otherwise

ḃ32=4Ẹ
ḃ32      # convert to base 32
   =4    # For each entry, is it equal to 4?
     Ẹ   # Are any equal to 4??
\$\endgroup\$
1
2

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.