Search
Vyxal, 4 bytes Expects a string. O2%∑ Try it here! Explanation O2%∑ O ord 2% modulo 2 ∑ sum
65,535 The database field can already handle up to 65,535 (216 - 1) characters. Same for all post types and categories I don't see a need for different limits for questions and answers, or for d...
Haskell, 110 bytes c[]=1>0 c(a:b:_)|abs(a-b)==1=1<0 c(_:b)=c b f=0:1:zipWith(+)f(tail f) h=[g|g<-f,c.map fromEnum.show$g] r=(h!!) Try it online!
Given a positive integer, count its odd digits. Input An integer from 1 to 999,999,999, inclusive, in any of the following formats: A number (such as an integer or floating point number), li...
Python, 37 27 bytes First, with input as an integer: lambda i:sum(ord(x)&1for x in str(i)) This converts the number to string (in the base-10 default) and processes each character. It expl...
JavaScript, 25 bytes Input as an array of digits a=>a.map(x=>t+=x%2,t=0)|t Try it online! 26 bytes With input as a string (or an array of digit strings). f=([d,...a])=>d?d%2+f(a):0...
Japt -mx, 2 1 byte u Try it u :Implicit map of input array u :Modulo 2 :Implicit output of sum of resulting array
Python 3, 50 bytes We can simply omit the lambda name since we don't refer to it anywhere in the lambda definition. lambda l:[l[:i+1].count(j)for i,j in enumerate(l)] Example usage in the term...
Python 3.8, 44 bytes Uses a modulus of 2**16 == 4**8 == 65536. for i in range(1,98,2):print(pow(i,-1,4**8)) How it works: for i in # Iterator ra...
Assignment expressions (Python 3.8+) The assignment expression (aka the walrus operator) := was introduced in Python 3.8 as a result of PEP 572, which can be used inline to assign a variable as pa...
Vyxal, 4 bytes Ċvt≈ Try it Online! Outputs 1 for true, 0 for false. The footer is to convert the output to the provided test case format. Explained Ċvt≈...
Vyxal 3, 2 bytes ⊞≈ Vyxal It Online! Shortest you'll probably get barring fractional bytes. Explained ⊞≈ ## Input is a number ⊞ ## Counts of all items in the number ≈ ## Are they all the...
Emmental, 51 bytes #72.#101.#108::..#111:.#44.#32.#87..#114..#100.#33. Try it online! Basically what goes on is #[num] pushes the ASCII value of num onto the top of the stack, : duplicates t...
Python 3, 43 bytes lambda n:len({*map(str(n).count,str(n))})<2 Try it online!
Python 3, 26 bytes lambda n:(n+(n*n+4)**.5)/2 We can actually just compute this directly, although I could have taken an alternate path considering the fact that, given $R_n$ as the ratio betwe...
Lean 4, 111 bytes def c(l:List Nat):List Nat:=((λx=>((l.reverse).drop x).count (l.reverse)[x]!)<$>(List.range l.length)).reverse Try it online! Given how verbose Lean syntax is, and h...
Python 3, 131 75 62 bytes f=lambda n:n>0and 2+3*f(n-1)+4*f(n-2)+2*sum(map(f,range(n-2))) I know, a one-liner is boring. This is because I apparently didn't need a separate function/lambda to...
Lean 4, 183 181 bytes def c(t:String)(s:Nat):String:=t.map (λc=>if Char.isAlpha c then let b:=if Char.isLower c then 'a'else 'A';let h:=(Char.toNat c-Char.toNat b+s)%26+Char.toNat b;Char.ofNat ...
The code-golf-tips tag seems redundant since we already have code-golf and tips. It also has zero usages. Should this tag be deleted to avoid its future usage?
What tips do you have for saving bytes in Rust? Please post one tip per answer for ease of voting and commenting.
x86-64 machine code, 37 bytes 31 C0 50 50 FF 04 C4 AC 2C 30 79 F8 5A 48 B8 31 30 31 30 AE 51 F3 AB 59 51 F3 AA 88 27 59 FF CA 75 F1 88 17 C3 Try it online! Following the standard calling conve...
Avoid type annotations with a closure instead of a fn Function (24 bytes) A function requires types to be specified for its return value, and for any arguments it takes. fn f(a:u8,b:u8)->u8{a...
Lean 4, 103 100 95 83 bytes def h:=λi=>if i<16then s!"{"0123456789ABCDEF".get ⟨i⟩}"else h (i/16)++h (i%16) Try it online! I actually am not sure how this even works, lol. I had thought...
x86 machine code, 3 bytes 31 FF AB Try it online! In assembly: xor edi, edi stosd Set EDI to 0 by XORing it with itself, then use the 1-byte stosd instruction to try to write EAX to tha...