New answers tagged

1

Short way to convert bits to integer: if you trust that $args contains int only (see Joey's comments below): $args|%{$r+=$_+$r};$r if you assume that $args is an array of int or string representation: $args|%{$r+=+$r+$_};$r $args is an array of char 48, 49: $args|%{$r+=+$r+"$_"};$r A sliding byte containing 8 bits from the array of int: $args|%{($r=2*...


1

Capturing groups hold the last value matched (REGEX)* will hold in capturing group 1 the last match of REGEX. (REGEX) can be combined with any such repeaters. For getting the last character of a string, there is the straightforward 5-byter .*(.) which captures the last character in capturing group 1. Another byte can be saved by noting the point in the ...


1

Use the new() method instead of New-Object For example, instead of doing the following (37 bytes): New-Object Drawing.Bitmap(1024,1024) Try (32 bytes): [Drawing.Bitmap]::new(1024,1024) Kind of an edge case, but you can do this pretty much anytime you initialize a new .NET object. Sadly, there's no equivalent for COM objects so you still have to use New-...


0

Constructing a long complex string (char vector) Original idea from @ngn. We can (ab)use rotation n⌽ and enlist ∊ to shorten multiple concatenations: '(',(⍺∇r),'|',(⍺∇s),')' → Rotate the last ')' to front and apply 1⌽ 1⌽')(',(⍺∇r),'|',(⍺∇s) (-1 byte) → We don't need parens at the end 1⌽')(',(⍺∇r),'|',⍺∇s (-3 bytes in total) → Remove some concats(...


0

Use dynamic instead of types with longer names in function declarations For example, instead of DateTime f(int y)=>… use dynamic f(int y)=>…


0

Use closure parameter to define variable instead of let {let(a,b)=(A,B);X} can be replaced by (|a,b|X)(A,B) to save 5 bytes if the type of a and b can be inferred, it usually works when they are integers or are passed to another function directly in X. This works well on 2 or more variables, but for a single variable, this could still save 2 bytes if it ...


14

Python 3, 32 bytes lambda a,b:(a-b*5>60)+(a-b*5>80) Try it online! Python 3, 50 bytes If io must be done with stdin and stdout s=int(input())-5*int(input());print((s>60)+(s>80)) Try it online!


2

Python 3, 51 bytes lambda a,b:(min(2,max(0,(int(a)-5*int(b)-41)//20))) Try it online! I was able to shave 6 bytes from your approach by using everyone's favourite python golfing keyword: lambda. This turns your program into an anonymous function, which then can be called in the footer of a program.


2

Python 3, 75 bytes lambda a:' '.join(''.join(map(chr,map(int,a.split())))[::-1].split()[::-1]) Try it online! Python 3, 70 bytes If taking input from STDIN and outputing to STDOUT is fine then it takes only 70 bytes this is mostly because the spread operator (*) is shorter than ' '.join() print(*''.join(map(chr,map(int,input().split())))[::-1].split()[::...


2

Python 3,  131 130 128 126  125 bytes i=input L=int(i()) exec("t=[L*[27,ord(c)%32][c.isalpha()]for c in i()]"+";r=i();print(''.join(r[j-L:j]for j in t))"*int(i())) A few golfs of the provided code. Note: I upper-cased l to L and replaced a couple of ; with newlines just for legibility. Try it online! When characters are alphabetical their ...


1

I think eta-reduction is severely overrated. I see a lot more attempts at eta-reduction in the wild than I think is reasonable. So it is in this case: eta-reducing this function is not helpful, I think. It's much more readable and elegant in its full form: f :: (a -> a -> c) -> (a -> b) -> b -> b -> c f g h a b = g (h a) (h b) On a ...


5

Python 2, 78 bytes lambda m:' '.join(x[::-1]for x in''.join(map(chr,map(int,m.split()))).split()) Try it online! Edit changed to a Python 2 answer as the lambda is shorter than the print/input version in Python 2. This uses a couple of maps to get the list of characters which we then join on "", split again on space, reverse each element then rejoin ...


6

Use lambdas def f(a,b):return c can be shortened to f=lambda a,b:c (the f= can also be removed per CGCC site standards) Remove excess []s x.join([a for b in c]) can be x.join(a for b in c) since join can take a generator instead of a list Split is on spaces by default Thanks ElPedro for reminding me about this So the split(' ')s can be shortened, ...


Top 50 recent answers are included