Skip to main content
deleted 221 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 7777 75 bytes

Edit: -2 bytes thanks to Giuseppe

f <-function(c)sum(unlistc==unlist(gregexprstrsplit(c,capture.output(dump("f","")),f=T""))>0)/7775

Try it online!Try it online!

Uses R dump(,"") function to output own source code*, capturing output (normally to the console) using capture.output(). Then finds the indicesnumber of all matching characters with gregexpr(,fixed=TRUE) ('fixed' option [abbreviated in golf codematches to 'f'] prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positionsfunction argument >0c (non-matching positions are output as -1), divided by the source code length (7775 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).


R (without reading own source code), 106 bytes

'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53

Try it online!

SameSame Similar approach asto above, but including quoted string instead of reading the source code itself.

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 [abbreviated in golf code to 'f'] prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positions >0 (non-matching positions are output as -1), divided by the source code length (77 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).


R (without reading own source code), 106 bytes

'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53

Try it online!

Same approach as above, but including quoted string instead of reading the source code itself.

R, 77 75 bytes

Edit: -2 bytes thanks to Giuseppe

f <-function(c)sum(c==unlist(strsplit(capture.output(dump("f","")),"")))/75

Try it online!

Uses R dump(,"") function to output own source code*, capturing output (normally to the console) using capture.output(). Then finds the number of matches to the function argument c, divided by the source code length (75 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).


R (without reading own source code), 106 bytes

'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53

Try it online!

Same Similar approach to above, but including quoted string instead of reading the source code itself.

added 583 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

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 [abbreviated in golf code to 'f'] prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positions >0 (non-matching positions are output as -1), divided by the source code length (77 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).


R (without reading own source code), 106 bytes

'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53

Try it online!

Same approach as above, but including quoted string instead of reading the source code itself.

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 [abbreviated in golf code to 'f'] prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positions >0 (non-matching positions are output as -1), divided by the source code length (77 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).

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 [abbreviated in golf code to 'f'] prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positions >0 (non-matching positions are output as -1), divided by the source code length (77 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).


R (without reading own source code), 106 bytes

'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53'->p;sum(gregexpr(scan(,""),sQuote(p),f=T)[[1]]>0)/53

Try it online!

Same approach as above, but including quoted string instead of reading the source code itself.

added 38 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

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 findfinds the indices of all matching characters with gregexpr(,fixed=TRUE) ('fixed' option [abbreviated in golf code to 'f'] prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positions >0 (non-matching positions are output as -1), divided by the source code length (77 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).

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 find the indices of all matching characters with gregexpr(,fixed=TRUE) ('fixed' option prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positions >0 (non-matching positions are output as -1), divided by the source code length (77 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).

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 [abbreviated in golf code to 'f'] prevents characters such as '(' from being interpreted as part of a regular-expression), and report the sum() of matching positions >0 (non-matching positions are output as -1), divided by the source code length (77 bytes).

*Note that the TIO interface gives slightly differently-formatted output from the dump() function to running directly in R, so counts of whitespace characters are inaccurate in TIO (but correct in R).

Post Undeleted by Dominic van Essen
added 73 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61
Loading
Post Deleted by Dominic van Essen
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61
Loading