| Bytes | Lang | Time | Link |
|---|---|---|---|
| 005 | Thunno 2 | 230729T113814Z | The Thon |
| 045 | Vyxal G | 230429T132104Z | The Thon |
| 045 | Nibbles | 230429T144020Z | xigoi |
| 044 | Scala | 230429T002233Z | 138 Aspe |
| 037 | Regex ECMAScript | 190227T041641Z | Deadcode |
| 006 | Jelly | 200627T082129Z | fireflam |
| 010 | GolfScript | 200109T041615Z | user8505 |
| 016 | Perl 6 | 190319T194055Z | bb94 |
| 026 | ES6 | 190228T180155Z | elipszil |
| 005 | 05AB1E | 190307T182029Z | ThePlasm |
| 024 | Kotlin | 190304T104008Z | snail_ |
| 021 | Java 8 | 190304T034243Z | Daniel W |
| 040 | Java 1 | 190304T040500Z | Daniel W |
| 023 | JavaScript SpiderMonkey | 190227T041740Z | tsh |
| 014 | x86 machine code | 190304T002114Z | Peter Co |
| 029 | Wolfram Language Mathematica | 190227T090344Z | Rainer G |
| 028 | ><> | 190301T103416Z | Emigna |
| 045 | Batch | 190301T005027Z | Neil |
| 008 | MATL | 190228T135707Z | Sanchise |
| 017 | x86 Machine Code | 190301T070413Z | Cody Gra |
| 008 | K 8 Bytes | 190228T170006Z | J. Sendr |
| 036 | Ink | 190227T213458Z | Sara J |
| 031 | C# Visual C# Interactive Compiler | 190227T053921Z | Gymhgy |
| 026 | Cubix | 190228T213435Z | MickyT |
| 048 | R | 190228T001258Z | Nick Ken |
| 031 | Haskell | 190228T040715Z | xnor |
| 032 | Python 2 | 190227T064733Z | Chas Bro |
| 018 | Tidy | 190227T150620Z | Conor O& |
| 033 | Java 8 | 190227T125610Z | Kevin Cr |
| 043 | Perl 5 | 190227T135037Z | Kjetil S |
| 031 | Retina 0.8.2 | 190227T132842Z | Neil |
| 004 | Catholicon | 190227T131155Z | Okx |
| 005 | 05AB1E | 190227T123809Z | Kevin Cr |
| 006 | Charcoal | 190227T123800Z | Neil |
| 005 | APL dzaima/APL | 190227T054220Z | Adá |
| 034 | C gcc | 190227T100316Z | celtschk |
| 025 | Julia 1.0 | 190227T094951Z | Kirill L |
| 043 | Python 3 | 190227T053018Z | Neil A. |
| 012 | J | 190227T073130Z | Galen Iv |
| 010 | APL+WIN | 190227T044508Z | Graham |
| 016 | Perl 6 | 190227T042618Z | Jo King |
| 019 | Ruby | 190227T033744Z | Doorknob |
| 005 | Japt | 190227T042053Z | ASCII-on |
Thunno 2, 5 bytes
32B4Ƈ
Try it online! or see all the rude numbers up to 200
Does the base-32 (32B) version of the input contain 4 (4Ƈ)?
Vyxal G, 36 bits1, 4.5 bytes
32τ4=
Try it Online! (link is to bitstring)
Suggested by @lyxal
Vyxal, 37 bits1, 4.625 bytes
32τ4c
Try it Online! (link is to bitstring) or see all the rude numbers up to 200
Explanation
32τ4= # Implicit input
32τ # Input in base 32
4= # Equals 4 (vectorised)?
# Implicit output of maximum
32τ4c # Implicit input
32τ # Input in base 32
4c # Contains 4?
# Implicit output
Nibbles, 4.5 bytes
?`@32$4
?`@32$4
? Find the first index of
4 4
`@32 in the base 32 representation of
$ input
Regex (ECMAScript), 37 bytes
Input is in unary, as the length of a string of xs.
^((?=(x+)(\2{31}x*))\3)*(x{32})*x{4}$
^
(
(?=(x+)(\2{31}x*)) # \2 = floor(tail / 32); \3 = tool to make tail = \2
\3 # tail = \2
)* # Loop the above as many times as necessary to make
# the below match
(x{32})*x{4}$ # Assert that tail % 32 == 4
Jelly, 6 bytes
ḃ32=4Ẹ
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??
GolfScript, 10 bytes
Empty list is false, a list with something is true. (Seems like cheating. But it isn't.)
~32base 4&
Explanation
~ # Evaluate the input
32base # Convert to base-32
# Copy
4& # Setwise and: does this list have 4?
Perl 6, 16 bytes
{.base(32)~~/4/}
Returns 「4」 (truthy) when given a rude number and Nil (falsy) otherwise.
ES6, 31 30 26 bytes
b=>b.toString(32).match`4`
Feel free to say ideas on how to reduce this further, if any.
05AB1E, 5 bytes
32в4¢
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)
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
}
Java 8, 28 22 21 bytes
n->n%32==4|n>>5%32==4
Inspired by @kevin-cruijssen's answer. Only works for 2 hands.
Explanation:
n-> // Method with int parameter and boolean return-type
n%32 // Only consider right 5 bytes (fingers)
==4 // Middle finger
| ... n>>5 // Repeat with shifted bits for other hand
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
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
JavaScript (SpiderMonkey), 23 bytes
f=x=>x&&x%32==4|f(x>>5)
This is a trivial solution, you just want to convert to base 32 and check if there is a 4 in it.
JavaScript (SpiderMonkey), 26 bytes
x=>x.toString(32).match(4)
It's interesting that /4/.test(...) cost one more byte than ....match(4).
x86 machine code, 14 bytes
(same machine code works in 16-bit, 32-bit, and 64-bit. In 16-bit mode, it uses AX and DI instead of EAX and EDI in 32 and 64-bit mode.)
Algorithm: check low 5 bits with x & 31 == 4, then right-shift by 5 bits, and repeat if the shift result is non-zero.
Callable from C with char isrude(unsigned n); according to the x86-64 System V calling convention. 0 is truthy, non-0 is falsy (this is asm, not C1).
line addr code bytes
num
1 ; input: number in EDI
2 ; output: integer result in AL: 0 -> rude, non-zero non-rude
3 ; clobbers: RDI
4 isrude:
5 .check_low_bitgroup:
6 00000000 89F8 mov eax, edi
7 00000002 241F and al, 31 ; isolate low 5 bits
8 00000004 2C04 sub al, 4 ; like cmp but leaves AL 0 or non-zero
9 00000006 7405 jz .rude ; if (al & 31 == 4) return 0;
10
11 00000008 C1EF05 shr edi, 5
12 0000000B 75F3 jnz .check_low_bitgroup
13 ;; fall through to here is only possible if AL is non-zero
14 .rude:
15 0000000D C3 ret
16 0E size: db $ - isrude
This takes advantage of the short-form op al, imm8 encoding for AND and SUB. I could have used XOR al,4 to produce 0 on equality, but SUB is faster because it can macro-fuse with JZ into a single sub-and-branch uop on Sandybridge-family.
Fun fact: using the flag-result of a shift by more than 1 will be slow on P6-family (front-end stalls until the shift retires), but that's fine.
Footnote 1: This is an assembly language function, and x86 asm has both jz and jnz, so as per meta I can choose either way. I'm not intending this to match C truthy/falsy.
It happened to be convenient to return in AL instead of EFLAGS, so we can describe the function to a C compiler without a wrapper, but my choice of truthy/falsy isn't constrained by using a C caller to test it.
Wolfram Language (Mathematica), 37 bytes 36 bytes 29 bytes
-2 bytes by Jonathan Frech
#~IntegerDigits~32~MemberQ~4&
31-byte solution:
MemberQ[IntegerDigits[#,32],4]&
><>, 28 bytes
Outputs 4 for rude numbers throws an exception for non-rude numbers.
:1(?^:" ":\
,&-v?=4:%&/
;n<
Batch, 77 45 bytes
@cmd/cset/a"m=34636833,n=%1^m*4,(n-m)&~n&m*16
Based on these bit twiddling hacks. Explanation: Only 6 hands need to be checked due to the limited range (30 bits) of the input that's required to be supported. The magic number m is equivalent to 111111 in base 32, so that the first operation toggles the rude bits in the input number. It then remains to find which of the 6 hands is now zero.
x86 Machine Code, 17 bytes
6A 20 59 85 C0 74 09 99 F7 F9 83 FA 04 75 F4 91 C3
The above bytes define a function that takes the number as input in the EAX register, and returns the result as a Boolean value in the EAX register (EAX == 0 if the input is not a rude number; EAX != 0 if the input is a rude number).
In human-readable assembly mnemonics:
; Determines whether the specified number is a "rude" number.
; Input: The number to check, in EAX
; Output: The Boolean result, in EAX (non-zero if rude; zero otherwise)
; Clobbers: ECX, EDX
IsRudeNumber:
push 32 ; \ standard golfing way to enregister a constant value
pop ecx ; / (in this case: ECX <= 32)
CheckNext:
test eax, eax ; \ if EAX == 0, jump to the end and return EAX (== 0)
jz TheEnd ; / otherwise, fall through and keep executing
cdq ; zero-out EDX because EAX is unsigned (shorter than XOR)
idiv ecx ; EAX <= (EAX / 32)
; EDX <= (EAX % 32)
cmp edx, 4 ; \ if EDX != 4, jump back to the start of the loop
jne CheckNext ; / otherwise, fall through and keep executing
xchg eax, ecx ; store ECX (== 32, a non-zero value) in EAX
TheEnd:
ret ; return, with result in EAX
K 8 Bytes
|/4=32\:
True if any digit of 32-base is 4
32\:converts its argument to 32-base4=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\:131returns1b(1bfor true0bfor false)For all the case tests:
(|/4=32\:)'0 3 4 25 36 127 131returns0010101bIf a function is needed, use
{|/4=32\:x}(lambda, 11 Bytes) or with namer:{|/4=32\:x}. For all case tests{|/4=32\:x}'0 3 4 25 36 127 131orr'0 3 4 25 36 127 1314 in 32\:is easier to read than|/4=32\:, but it's longer (9 bytes)
Ink, 38 36 bytes
=r(n)
{n:{n%32-4:->r(n/32)|1}|0}->->
Edit: Saved 2 bytes by simplifying the first conditional to "if n" rather than "if n>0".
C# (Visual C# Interactive Compiler), 31 bytes
n=>{for(;n>0;n/=n%32==4?0:32);}
Outputs by throwing an exception. The way you convert one number from decimal to another base is to divide the decimal number by that base repeatedly and take the remainder as a digit. That is what we do, and we check if any of the digits have a value of 4 in base-32;
Cubix, 26 bytes
u!@-W14;OIS%/\;;,p;?wO@u/s
Wraps onto a cube with edge length 3 as follows
u ! @
- W 1
4 ; O
I S % / \ ; ; , p ; ? w
O @ u / s . . . . . . .
. . . . . . . . . . . .
. . .
. . .
. . .
A fairly basic implementation, without all the redirects it does :
ISinitiates the program by pushing the input and 32 to the stack%4-!gets the remainder and checks if it is 4 by subtraction1O@output 1 if it was 4 and halt;;,clean up the stack and do integer dividep;?clean up bottom of the stack and check div result for 0O@if div result zero output and haltsswap the top of stack and start back at step 2 above
R, 50 48 bytes
any(2^(0:4)%*%matrix(scan()%/%2^(0:34)%%2,5)==4)
Uses a neat matrix-based approach now (courtesy of @Giueseppe). It generates a 5x7 matrix of bits, converts this to a series of base 32 integers, and checks for any 4s.
Tidy, 18 bytes
{x:4∈base(32,x)}
Try it online! Checks if 4 is an element of base(32,x) (base conversion).
Java 8, 40 33 bytes
n->n.toString(n,32).contains("4")
Port of @Adám's APL (dzaima/APL) answer.
Explanation:
n-> // Method with Integer parameter and boolean return-type
n.toString(n,32) // Convert the input to a base-32 String
.contains("4") // And check if it contains a "4"
Retina 0.8.2, 31 bytes
.+
$*
+`(1+)\1{31}
$1;
\b1111\b
Try it online! Link includes test cases. Outputs zero unless the number is rude. Works by converting the input to unary and then to unary-encoded base 32 and counting the number of 4s in the result.
05AB1E, 5 bytes
32B4å
Port of @Adám's APL (dzaima/APL) answer.
Try it online or verify all test cases.
Explanation:
32B # Convert the (implicit) input to Base-32
4å # And check if it contains a 4
# (output the result implicitly)
Charcoal, 6 bytes
№⍘N³²4
Try it online! Link is to verbose version of code. Outputs -s according to how rude the number is. Explanation:
N Input as a number
⍘ Convert to base as a string
³² Literal 32
№ Count occurrences of
4 Literal string `4`
I use string base conversion to avoid having to separate the numeric literals for 32 and 4.
Julia 1.0, 25 bytes
f(n)=n%32==4||n>0<f(n>>5)
Julia 1.0, 26 bytes
Alternative that is 1 character shorter, but 1 byte longer, too bad that ∈ takes 3 bytes in unicode.
n->'4'∈string(n,base=32)
Python 3, 43 bytes
Checks every 5-bit chunk to see if it is rude (equal to 4).
lambda n:any(n>>5*i&31==4for i in range(n))
APL+WIN, 10 bytes
Prompts for input of integer
4∊(6⍴32)⊤⎕
Noting six hands are required to represent 10^9 converts to vector of 6 elements of the base 32 representation and checks if a 4 exists in any element.
Perl 6, 16 bytes
{.base(32)~~/4/}
Checks if there is a 4 in the base 32 representation of the number. Returns either Nil as false or a Match containing a 4.
You can prove this by the fact that \$2^5 = 32\$ so each digit is the state of each hand.
Japt, 5 bytes
sH ø4
Explanation
// Implicit input
sH // To a base-H (=32) string
ø // Contains
4 // 4 (JavaScript interprets this as a string)