New answers tagged

-2

WikiCode 498,109 bytes https://en.wikipedia.org/wiki/2020_United_States_House_of_Representatives_elections The code the wiki uses


0

Jelly, 155 154 bytes Ø.UN,ƊAN,Ɗ+Ṫ¥+œị⁾+|yⱮ$ɼ=⁾|=⁼Ø.Ɗɗ¡ƬṪ¥ƒ⁸’1¦⁺œị®⁼”|ƊпṖṪ+2¦œị®⁻1Ɗ¡ƬṪ¥ⱮØ+$“”¹? o@e¥€€ØẠ“-=“==”;U¤œṣjƭƒ$€ƬṪ©=1ŒṪ+2¦œị®ɗⱮØ+f⁾-+ƊÐḟWÇ€Ẏ$Ƭḣ3ẎƲ€Œcf/ÐḟḢ€€ȧœị¥>”ZIFẸ Try it online! Minor modification of my Cyrillic version. A monadic link that takes a list of Jelly strings and returns 1 for true and 0 for false. I’m sure this could be ...


0

Jelly, 160 159 bytes Ø.UN,ƊAN,Ɗ+Ṫ¥+œị2,5yⱮ$ɼ=5,6⁼Ø.Ɗɗ¡ƬṪ¥ƒ⁸’1¦⁺œị®⁼5ƊпṖṪ+2¦œị®⁻.Ɗ¡ƬṪ¥ⱮØ+$“”¹? Odȷ%⁴ỊḢịƊ€€H“¥©“©©‘;U¤œṣjƭƒ$€ƬṪ©=.ŒṪ+2¦œị®ɗⱮØ+f2,4ƊÐḟWÇ€Ẏ$Ƭḣ3ẎƲ€Œcf/ÐḟḢ€€ȧœị¥O>⁽¡FIFẸ Try it online! A monadic link that takes a list of Jelly strings and returns 1 for true and 0 for false. I’m sure this could be golfed more. Full explanation to follow.


1

Brainfuck, 475 bytes >,[>+++++++++++[<------>-]<[>++[<+++++>-]]<[<]>>++[<----->-]<---[>+++[<++++++>-]]<[<]>>+++[<------>-]<----[>++++[<++++++>-]]<[<]>>++++[<------>-]++[<----->-]<[>+++++[<++++++>-]]<[<]>>+++++[<------>-]++...


0

C# .NET, 84 bytes class P{static void Main(string[]a){System.Console.Write("".PadLeft(a[0].Length));}} Try Online


0

C# .NET, 98 bytes class P{static void Main(string[]a){System.Console.Write((int)" "[int.Parse(a[0])]);}} Try Online Uses Ascii control characters (RS, US and FS) and gets their absolute character value.


0

Perl 6, 19 bytes {TR/beisBEIS/8315/} Try it online! Kinda annoying that the case-insensitive adverb doesn't work with transliteration. That's made up a little by the second half cycling for both cases.


1

Python 3.8 (pre-release), 79 bytes Based on @galen-ivanov's answer. lambda x,y,z:(t:=1)and[t:=t+t*z/(i+j+1)for i in range(x)for j in range(y)]and t Try it online!


0

PHP, 57 bytes Input via space-delimited string on STDIN, output to STDOUT is "Yes" or "No" string. <?=strpos(($a=explode(' ',$argn))[1].$a[1],$a[0])?Yes:No; Try it online! Or with Default I/O input via command line args and output truthy/falsey. PHP, 37 bytes <?=strpos(($a=$argv)[2].$a[2],$a[1]); Try it online! Or as a function: PHP, 41 bytes ...


0

sed, 39 48 bytes, but score is 39, since each 👑 counts as 1. /..../s/^1+0/👑👑👑/ s/^/00/ s/.*(...)/\1/ Try it online!


1

Perl 6, 38 - 9 = 29 bytes -2 bytes thanks to Jo King {~m/...$/}o{S/1+0/👑👑👑/}o*+1e4 Try it online! Inspired by Arnauld's JavaScript solution.


1

Vim, 40 bytes :%s/\cb/5/g :%s/\ce/3/g :%s/\ci/1/g :%s/\cs/5/g


0

05AB1E, 13 bytes ā._Êßi„Noë”…Ü Try it online or verify all test cases. Explanation: ā # Push a list in the range [0, length] for the (implicit) input-string, # without popping this input-string itself # i.e. "CodeGolf" → [1,2,3,4,5,6,7,8] ._ # Rotate the string that many times towards the left (vectorized) # ...


0

05AB1E, 2 bytes tï Try it online or verify the first N test cases. Explanation: t # Square-root the (implicit) input-integer ï # Cast it to an integer (a.k.a. floors) # (after which the result is output implicitly)


0

Wren, 81 bytes Fn.new{|N| var e=0 for(i in 1..N)e=e+1/(1..i).reduce{|a,b|a*b} return e+1 } Try it online! (Not working because I don't have TIO yet.)


1

Clojure, 101 bytes (defn l[s](clojure.string/replace s #"[BEISbeis]"{"B""8""b""8""E""3""e""3""I""1""i""1""S""5""s""5"})) Try it online!


0

Gema, 28 characters _?=@upcase{?} ?=@downcase{?} Sample run: bash-5.0$ gema '_?=@upcase{?};?=@downcase{?}' <<< 'i_promise_1234_is_not_my_password' iPromise1234IsNotMyPassword Try it online!


2

Python 3, 51 bytes lambda s:s[0].lower()+s.title().replace('_','')[1:] Try it online! -4 bytes thanks to ReinstateMonica


0

Ruby, 39 bytes ->x{x.downcase.gsub(/_(.)/){$1.upcase}} Try it online! This does nothing to leading and trailing underscores.


0

Rail, 35 bytes $ 'main' -[q]?3c(!!)2co\ #oc1?n(!!)oc5?-& Try it online! Here's an expanded version: $ 'expanded' \ --[any string]-?-3c-(!discard!)-2c-o\ \ #-o-c1-?n---(!discard!)-o-c5?--& Rail works like a train track, with special 'stations' (functions) represented by characters that ...


0

Charcoal, 25 bytes NθNηFNFηFθ⊞υ⊕⁺λ⁺κιI÷Π⊕υΠυ Try it online! Link is to verbose version of code. Explanation: Uses the 0-indexed version of the given formula. NθNηFNFηFθ Input the three dimensions and loop over the implicit ranges. ⊞υ⊕⁺λ⁺κι Take each incremented sum and save it in a list, thus flattening the Cartesian product. I÷Π⊕υΠυ Divide the ...


0

05AB1E, 39 bytes εNUε'aåi„aaë¯.øX<X>‚è˜y2£lSδåPài„Aaë„A_ Port of my Java answer. Try it online or verify all test cases. Explanation: ε # Map over the rows of the (implicit) input-list: NU # Store the outer-map index in variable `X` ε # Map over the strings `y` of the current row: '...


1

J, 29 bytes [:*/[:(1+1%1++/)@>[:,@{<@i."0 Try it online! A J port of @JoKing's APL answer (don't forget to upvote it), but twice as long. I'll try to golf it...


1

IBM/Lotus Notes Formula, 76 bytes @ReplaceSubstring(i;@Explode("B b E e I i S s");@Explode("8 8 3 3 1 1 5 5")) Takes input as i. Works because @ReplaceSubstring can take a list of characters to replace and a list of replacement characters and match them one to one. There is no TIO for formula so a screenshot is shown below:


5

05AB1E, 13 11 bytes L.«â€˜OÍz>P Try it online or verify all test cases. Explanation: Uses the derived formula (inspired by @JoKing's answers): $$PL(x,y,z) = \prod_{i=1}^x \prod_{j=1}^y \prod_{k=1}^z \frac{1}{i+j+k-2}+1$$ L # Map each value in the (implicit) input-list to an inner [1,v]-ranged list .« # (Right-)reduce these lists ...


2

Pyth, 17 bytes XQ"BEISbeis""8315 Try it online! X # Translate characters in Q # the input "BEISbeis" # that are in this string from this string "8315" # to this string (modular indexing: "B"->"8", "b"->"8")


1

C (gcc),  71  70 bytes Saved 1 byte thanks to @ceilingcat This is essentially a port of my Node answer. c;f(char*s){for(;c=*s++;)putchar(index("BEISbeis",c)?48|16/(c&15):c);} Try it online!


1

Icon, 81, 78 70 bytes -8 bytes thanks to Peter Taylor procedure f(x,y,z) p:=1&p*:=(1+z/(seq()\x+seq()\y-1.))&\u return p end Try it online!


2

Retina, 20 19 16 bytes Y`B\EISbeis`8315 -1 byte thanks to @ovs (transliterating Ss to 5 due to (quote from docs): "If the to list is shorter than the from list and the current character appears after the end of the to list, it gets mapped to the last character in the to list (alternatively, you can think of it as padding to to the length of from using the ...


1

Ruby, 85 75 bytes ->x,y,z{w=->t{(0...x*y*z).map{|r|r%x+(r/=x)%y+r/y+t}.reduce &:*};w[2]/w[1]} Try it online!


1

Ruby -rprime, 65 bytes ->i{c=i.sum.abs;i.sum{|e|e*e}.prime?||[0]-i==[]&&c.prime?&&c%4>2} Try it online! If I can take a complex number as input, 59 bytes: ->i{i.abs2.prime?||[0]-i.rect==[]&&i.abs.prime?&&i.abs%4>2} Try it online!


2

Bash, 75 Inputs are passed as a comma-separated list. e={1..${1//,/\}+\{1..}} eval eval echo \\$\[1 *\\\($e-1\\\) /\\\($e-2\\\) ] Try it online! The last test fails due to integer overflow.


3

Haskell, 47 bytes f l=product[1+1/(sum r-2)|r<-mapM(\n->[1..n])l] Try it online! Outputs floats. Same length pointfree: product.map(\r->1+1/(sum r-2)).mapM(\n->[1..n]) Try it online!


10

Python 2, 399 393 390 388 385 bytes def f(s): V=S(''.join(s))-S(' |+-^');P={v:[]for v in V} for j,r in E(s): for i,c in E(r): if'+'==c: p,q=a=h(r,i);A=a+P[p][:2]+P[q][:2];V-=S(a);v=j;b='|' while'z'<b:v+=1;b=s[v][i] if'^'==b:w,x=h(s[v],i);P[w]=P[x]=A else:P[b]=A return 1-all((b>'Z')==(c>'Z')or S(P[b])&...


5

Wolfram Language (Mathematica), 28 bytes Array[1+1/(##-2)&,#,1,1##&]& Try it online!


12

APL (Dyalog Classic), 14 bytes ×/1+1÷1+∘,1⊥¨⍳ Try it online! Uses 0 indexing with ⎕IO←0. Explanation: ⍳ ⍝ Cartesian product of the ranges from 0 to n-1 1⊥¨ ⍝ Sum of each element (using base 1) , ⍝ Flattened ∘ ⍝ Composed with 1+1÷1+ ⍝ 1 + 1/(n+1) ×/ ⍝ And ...


1

Python (with numpy), 38 bytes norm(a[:,None,:]-b[None,:,:], axis=2)


1

Mathematica, 149 Characters If[a==0,#[[3]]&&Mod[Abs@b,4]==3,If[b==0,#[[2]]&&Mod[Abs@a,4]==3,#[[1]]]]&[(q=#;Total[Boole@IntegerQ[q/#]&/@Range@q]<3&&q!=0)&/@{a^2+b^2,Abs@a,Abs@b}] The code doesn't use any standard prime number features of mathematica, instead it counts the number of integers in the list {n/1,n/2,...,n/n}...


2

JavaScript (ES6),  73 65  64 bytes (x,y,z)=>(g=n=>!n||g(n-1)/(s=n%z-~(n/z%y)+n/z/y%x|0)*-~s)(x*y*z) Try it online! Commented (x, y, z) => ( // (x, y, z) = input g = n => // g is a recursive function taking a counter n !n || // if n = 0, stop recursion and return 1 g(n - 1) /...


3

K (ngn/k), 17 15 bytes %/*/'2 1+\:+/!: Try it online! last test fails because of an overflow uses a 0-indexed version of the formula: \$PL(x,y,z)=\prod_{i=0}^{x-1}\prod_{j=0}^{y-1}\prod_{k=0}^{z-1}\frac{i+j+k+2}{i+j+k+1}\$


1

Pari/GP, 52 bytes (a,b)->matrix(#a~,#b~,i,j,sqrt(norml2(a[i,]-b[j,]))) Try it online!


8

Perl 6, 38 30 bytes {[*] map 1+1/(*+1),[X+] ^<<@_} Try it online! Based on the formula given in the question Explanation: { } # Anonymous code block ^<<@_ # Map each input to the range 0 to n-1 [X+] # Get the cross product of sums map , ...


3

Wolfram Language (Mathematica), 24 bytes Outer[Norm[#-#2]&,##,1]& Try it online!


4

Jelly, 9 bytes Œp§’÷_ɗ2P Try it online! Based on the closed form expression given in the question. Takes input as a list [x,y,z]. Œp Cartesian product of the list. (Each element, being an integer, is implicitly converted to a range.) § Sum the items of each triplet, ɗ and for each sum (implicitly vectorizing) ...


1

C# .NET, 145 bytes class P{static void Main(string[]a){foreach(var c in a[0]){var d=c%32;System.Console.Write((char)(c>64?d==5?51:d==2?65:d==9?49:d==19?53:c:c));}}} Try Online


0

Python, 87 bytes lambda s:''.join([('8315'*2)['beisBEIS'.find(c)] if c in 'beisBEIS' else c for c in s])


3

J, 12 bytes +/&.:*: .-|: Try it online! How it works +/&.:*: .-|: Left: a, Right: b |: Transpose b to get bT . Customized matrix multiply: - Subtract bT's columns from a's rows &.:*: Square each element +/ Sum &.:*: Sqrt the result


0

C (gcc), 152 143 140 128 bytes a[256];c=256;main(){for(;a[c]=--c;)a[66]=a[98]=56;for(a[69]=a[101]=51;c=~getchar(a[73]=a[105]=49);printf(a+~c))a[83]=a[115]=53;} Requires ASCII. Try it online! -8 bytes using this to transform ASCII characters to their codes and using c+1 rather than c>-1 to check if EOF is reached -3 bytes using toupper rather than ...


2

Batch, 71 bytes @set/ps= @set s=%s:b=8% @set s=%s:e=3% @set s=%s:i=1% @echo(%s:s=5% Takes a line of input on STDIN. Batch's substitute operator is automatically case insensitive.


2

Bash, 66 43 20 19 bytes tr BbEeIiSs 8833115 Try it online! 43 Bytes sed -e"s/b/8/Ig;s/e/3/Ig;s/i/1/Ig;s/s/5/Ig" Try it online! Thnaks to: -@MD XF for saving 23 bytes -@WGroleau for saving 23 bytes -@Jo King for saving 1 byte


Top 50 recent answers are included