Search
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 ...
Python 3.8, 64 bytes lambda s,_:((n:=s.count("1"))*"1"+"0"+n*"1010")*(len(s)-n)+n*"1" Try it online! Let Tn consist of (2n+1) 0s and 2n 1s alternating. Tn can consume a 1 on either side and ...
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...
Most challenges are code golf. Apart from being the name of the community, code golf is also easier to write both answers and challenges for (while a lot of time and effort can go into golfing, wri...
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...
Vyxal, 12 bitsv2, (actually 1.5 but the leaderboard needs to say) 2 bytes øṘ Try it Online! Bitstring: 000101111100 Very simple: call the built-in :p
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...
Lean 4, 111 97 bytes def d(l: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 how you can'...
Python 3, 86 85 bytes The reasoning behind why this works is basically that 1. we can directly compare the ordinal values of characters (apparently) and 2. we only need that if a character is alph...
Q/KDB+, 39 bytes {"#",?[4=count x;x 1 1 2 2 3 3;6#1_x]} Testing the function: q)cc:{"#",?[4=count x;x 1 1 2 2 3 3;6#1_x]} q)cc "#ABCDEF" "#ABCDEF" q)cc "#A" "#AAAAAA" q)cc "#AB" "#ABABAB...
This is somewhat of a [proof-golf]-like [cops-and-robbers]. This is the cops' thread; the robbers' thread is here Sections: Cops Scoring What is a rewrite rule? An example An example of...
BQN (CBQN), 9 bytes ++2⊸=∧=⟜2 This utilizes the "3-train"- any functions in the form w fgh x is turned into (w f x) g (w h x). In this case, 2⊸= and =⟜2 are functions that check if the right a...
Vyxal, 7 bytes ɾĖ∑?≥)ṅ Try it Online! Vyxal has arbitrary-precision rationals, so this will never run into precision errors. ṅ # Find the first integer -----) # where ∑ # sum of...
C (gcc), 55 bytes a;f(char*s){for(;atoi(s)&128>>a&&a<4;a++);return 65+a;} Try it online! Just call atoi and start masking with 0x80. If true, keep looping and next che...
Inspiration: Leetcode's [3Sum] linkLink on CG&CC Problem Given an array nums of n (not necessarily distinct) integers, and given a target number target, return an array of all of the unique...
Python, 89 Bytes import math as m def f(*n):return m.gcd(*n)==1and all(m.gcd(a,b)!=1for a in n for b in n) Note: The outdated Python interpreter at tio.run won't run this code (nor the ungolfe...
Haskell + hgl, 32 24 bytes tlM$tk6<cy<fiI(rl2~<)eL3 Explanation tlM map a over the tail of the input ... fiI if ... el3 the length is 3 (rl2~<) repeat each letter in place twi...
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...
APL (Dyalog Classic), 31 bytes '#',{4=≢⍵:⍵[2 2 3 3 4 4]⋄6⍴1↓⍵} Try it online!
Japt, 13 12 bytes Î+6îUÅË+pUÊv Try it (includes all test cases) Î+6îUÅË+pUÊv :Implicit input of string U Î :First character + :Append 6î : M...
BQN, 27 bytes •math.GCD{∧´∘⥊(1=𝔽´)∧1<𝔽⌜˜} Booleans in BQN are the integers 0‿1. Try all test cases on the: BQN online REPL
BQN, 23 bytes {𝕩{𝕊⍟(𝕗>·+´∘÷1+↕)𝕩+1}1} This recursion is more complicated than it should, but I managed to keep it purely functional. I use a modifier to mimic passing a left argument, that's...
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≈...
BQN, 31 bytes {⍷(+´⊸=⟜𝕩∧5=≠)¨⊸/⥊(↕2¨𝕨)/¨<∧𝕨}´ This block function returns the empty array ⟨⟩ if the conditions cannot be satisfied. It works by sorting the input list to prevent having to fi...
BQN, 15 bytes ⊢(«∘⊢-×)´˜1∾˜≠˜ A 3-train (fold with initial): we zero list of the same length as the input with a one appended (the base case), then for each root we do the multiplication by the...