# Tag Info

19

Retina 0.8.2, 1 byte 1 Try it online! Link includes... test cases? But there's not much to test really. The program counts the number of 1s in the input, so if the input is 1, then this is 100% of the program's code, and the program outputs 1 accordingly, otherwise the input character is not in the program's code, and therefore the output is 0.

18

JavaScript (ES6), 40 bytes All used characters appear exactly twice. Therefore, this returns either 0 or 2/40 = 0.05. F=_=>(F+'+./02>cdeilnsu').includes(_)/20 Try it online!

10

Python 2, 52 bytes s="print('s=%r;exec s'%s).count(input())/52.";exec s Try it online! Python 3.8 (pre-release), 53 bytes exec(s:="print(('exec(s:=%r)'%s).count(input())/53)") Try it online! Python 3, 55 bytes s="print(('s=%r;exec(s)'%s).count(input())/55)";exec(s) Try it online!

9

05AB1E, 5 4 bytes Thanks a lot to OP! Now I can save a byte ŸSΘO Try it online! Explanation Ÿ Inclusive range S Split the string into individual chars Θ (Vectorizes) Does this character == "1"? O Sum the resulting list

8

Python 2, 40 39 bytes -1 byte thanks to @JonathanAllan! lambda s,l,n:~sum(x<s for x in l)/n*-20 Try it online!

7

Charcoal, 37 36 34 bytes Ｉ⌊ＥＥＸ²⁻Ｌθ²↨⁺Ｘ²⊖Ｌθ⊗ι²ΣＥθ∧§ιμΣΦλ¬§ιξ Try it online! Link is to verbose version of code. Explanation: Ｅ…Ｘ²⁻Ｌθ²Ｘ²⊖Ｌθ Loop over all cuts... Ｅ ↨⊗ι² ... converted to base 2 ΣＥθ∧§ιμ Sum rows in source cut ΣΦλ¬§ιξ Sum columns in sink ...

7

Rust+itertools, 42 bytes |a,b|(a..=b).join("").matches('1').count() Try it in the Rust Playground!

6

APL (Dyalog Extended), 9 bytes +/'1'=⍕⍤… Try it online! +/ sum '1'= where the character is equal to ⍕ the string representation ⍤ of … the range

6

Python 2, 39 36 bytes -3 bytes thanks to @SurculoseSputum lambda a,b:range(a,b+1).count('1') Try it online! Python 3, 42 40 bytes -2 bytes thanks to @JoKing lambda a,b:f"{*range(a,b),b}".count('1') Try it online!

6

Octave, 29 28 27 bytes @(x,y)sum(mat2str(x:y)==49) Try it online!

6

Jelly, 9 bytes Ż+⁵ṚDḅ¥@/ A monadic Link accepting a non-negative integer which yields a non-negative integer. Try it online! Or see the test-suite. How? Ż+⁵ṚDḅ¥@/ e.g. 5 Ż - zero-range [0,1,2,3,4,5] ⁵ - ten 10 + - add [10,11,12,13,14,15] Ṛ - reverse [15,14,...

6

JavaScript (ES6),  44  40 bytes (s,a,n)=>-~(a.map(S=>k+=s>S,k=0),k/n)*20 Try it online!

6

JavaScript (Node.js),  61  34 bytes -16 bytes thanks to MatthewJensen -11 bytes thanks to Arnauld f=c=>--('f='+f).split(c).length/34 Try it online!

5

JavaScript (ES6), 96 bytes f=(m,k=1,b)=>k*2>>m.length?b:f(m,k+2,m.map((r,y)=>r.map((v,x)=>t+=k>>y&~k>>x&1&&v),t=0)|t>b?b:t) Try it online! Commented f = ( // f is a recursive function taking: m, // m[] = adjacency matrix k = 1, // k = counter, ...

5

R, 43 bytes function(x,y)sum(unlist(gregexpr(1,x:y))>0) Try it online!

5

Java 8, 71 67 66 bytes a->b->{var s="";for(;b>=a;)s+=b--;return~-s.split("1",-1).length;} -4 bytes thanks to @OlivierGrégoire. Try it online. Explanation: a->b->{ // Method with two integer inputs and integer return-type var s=""; // String s, starting empty for(;b>=a;) ...

5

39 38 bytes with(location)protocol='https'+href How it works If location.href starts with http:, this assigns location.protocol = 'https:'. If location.href starts with https:, this assigns location.protocol = 'httpss'. According to the specification, this should have no effect because httpss is neither http nor https. Firefox obeys this ...

5

05AB1E, 10 9 bytes -1 byte inspired by Jonathan Allans Jelly answer. €aγOʒĀ}.M Try it online! Commented: €a0¡OʒĀ} implicit input "ab, cd e." €a map is_alpha [1, 1, 0, 0, 1, 1, 0, 1, 0] γ split into chunks of equal elements [[1, 1], [0, 0], [1, 1], , , ] O sum the lists ...

5

Actually, 5 bytes 5○Qc/ Try it online! Explanation ○ Push the byte of input Qc Count how many times it's in the source code 5 / And divide by five

5

R, 77 bytes f <-function(c)sum(unlist(gregexpr(c,capture.output(dump("f","")),f=T))>0)/77 Try it online! Uses R dump(,"") function to output own source code*, capturing output (normally to the console) using capture.output(). Then finds the indices of all matching characters with gregexpr(,fixed=TRUE) ('fixed' option [...

5

APL (Dyalog Unicode), inspecting its own source code, 20 bytes f←{(+/÷≢)⍵=,⎕CR'f'} Try it online! Note the leading space in the code. When a function is defined in APL, the interpreter converts the source code to its own whitespace formatting (strips most spaces but inserts some at certain places, including the start of each line). The system functions ...

4

Alice, Cat + Quine = Hello World, 51 bytes Cat: (With trailing newline) \ > "!dlroW olleH"d&O@ ^/ v # < i Try it online. Uses # to skip the redirect west and instead hit the redirect south into the i, which pushes the input as a string to the top of the stack. The instruction pointer then reflects off the top and bottom boundaries ...

4

Hello World + Quine = Cat, C (GCC), 149 (81 + 68) Hello World a;main(s){a?read(0,&s,1)&&main(putchar(s)):puts("Hello World!");} #define main m Try it online! Quine a=1;main(s){printf(s="a=1;main(s){printf(s=%c%s%1$c,34,s);}",34,s);} Try it online! Cat (Hello World + Quine) a;main(s){a?read(0,&s,1)&&main(putchar(s)... 4 ><>, Quine + Cat = Hello World!, 48 bytes Quine "r00gol?!;40. The classic ><> quine Cat "]v"i:0(?;o >l?!;o ^"Hello World!"< A simple cat program, loaded with some other code that isn't being run. Hello World! "r00gol?!;40."]v"i:0(?;o >l?!;o ^"Hello World!"< The quine part makes ... 4 APL (Dyalog Unicode), 72 bytes {⍵=1:⍳2⋄(2*⌈⍵÷2)(⌷⌹⍉⍤↑)⍉L↑⍉↑,¨+.×\(L←2*⍵)⍴⊂∘.((0∊+)⍱1∊2|×≢¨⍤⊆⊣)⍨⍸1⍴⍨⍵⍴2} Try it online! (uses a polyfill for ⍤ since TIO is not updated to 18.0 yet) Requires ⎕pp←2 (implicit rounding of output) and ⎕IO←0 (0-indexing). We compute a transition matrix, then use the approach listed in S. Białas and M.Białas to find the minimum ... 4 JavaScript (ES7), 198 185 179 178 bytes Expects a matrix of integers with -1 for a wall and 0 for an empty cell. Returns a matrix of Boolean values. m=>(g=(Y,w,n,X)=>w>=W&&w>W|n>N?0:m[Y+1]||1/m[Y][X+1]?m.map((r,y)=>r.map((v,x)=>v>0?1:(X-x)**2+(Y-y)**2^1?0:r[r[x]=1,g(y,w-v,-~n,x),x]=v)):o=g(-1,W=w,N=n))(0,0,W=++m/0,0)&... 4 Ruby, 62 46 28 bytes ->c,d{[*c..d].join.count ?1} -18 bytes, courtesy of Dingus. Try it online! 4 Retina 0.8.2, 36 32 bytes \d+$*_ (?<=(_+) _*)(?=\1) $.' 1 Try it online! Link includes test cases. Explanation: \d+$*_ Convert a and b to unary, but use _ instead of 1 to avoid confusion. (In Retina 1 this would just be *, saving 2 bytes.) (?<=(_+) _*)(?=\1) \$.' At each boundary in b up to and including a from the end, insert the distance to the ...

4

JavaScript (ES6), 44 bytes Expects (a)(b). a=>g=b=>b<a?0:(b+g).split(1).length-3+g(b-1) Try it online! How? We use a recursive function g to count how many 1's we have in b and decrement b until it's lower than a. In order to count the 1's, we have to coerce b to a string. We could do b+'' but it's shorter to use b+g. Because the source code of g ...

4

Google Sheets, 68 =SUM(ArrayFormula(LEN(REGEXREPLACE(""&SEQUENCE(A2-A1+1,1,A1),"[^1]", Sheets auto-closes parens. This is super slow at large ranges, but as this is Code Golf, we're here to optimize character count. My first attempt was to use JOIN(SEQUENCE(...)) to make one long string then count the 1's, but as it turns out, Sheets ...

Only top voted, non community-wiki answers of a minimum length are eligible