Given a string of printable ASCII, count the dots.
The following characters have one dot each:ij.;!?. This character has two dots::. No other characters have dots.
Rules
Default I/O rules andstandard rules apply.Standard loopholes are forbidden.
This iscode-golf; shortest solution in bytes wins.
Test cases
Input OutputSphinx of black quartz, judge my vow! 3Lorem ipsum: dolor sit amet? 5Programming Puzzles & Code Golf 1ij.;!?: 8pericardiomediastinitis 6formaldehydesulphoxylate 0<empty string> 0This question has 58 dots.
- \$\begingroup\$Can we take input as an array of characters?\$\endgroup\$Shaggy– Shaggy2024-10-10 19:13:35 +00:00CommentedOct 10, 2024 at 19:13
- 1
38 Answers38
Uiua,18 15 bytes
/+♭⊞="ij.::;!?"Try it:Uiua pad
Explanation: Sum of the flattened equality table of the input with"ij.::;!?".
- \$\begingroup\$@janMakoso Clever, upvoted.\$\endgroup\$noodle person– noodle person2024-10-15 01:27:04 +00:00CommentedOct 15, 2024 at 1:27
Google Sheets, 45 bytes
=len(regexreplace(A1,"(:)|[^ij.;!?]","$1$1"))Put the text string in cellA1 and the formula in cellB1.

(-1 thanks to emanresu A)
- \$\begingroup\$
.split`:`.join`::`saves a few bytes on the latter (edit: actually, replacing'::'with10is better)\$\endgroup\$emanresu A– emanresu A2024-10-10 20:04:03 +00:00CommentedOct 10, 2024 at 20:04 - \$\begingroup\$@emanresuA thanks, but using abetter regex saves many more.\$\endgroup\$doubleunary– doubleunary2024-10-10 20:23:12 +00:00CommentedOct 10, 2024 at 20:23
- \$\begingroup\$You can save some bytes with
map\$\endgroup\$xnor– xnor2024-10-11 02:16:26 +00:00CommentedOct 11, 2024 at 2:16
- \$\begingroup\$This doesn't seem to work for inputs with newlines (per TIO at least). Do we care?\$\endgroup\$Greg Martin– Greg Martin2024-10-11 19:22:00 +00:00CommentedOct 11, 2024 at 19:22
- 1\$\begingroup\$@GregMartin It does if you add a
-0on the command line. There's no change needed to the code itself to support it.\$\endgroup\$Xcali– Xcali2024-10-11 19:39:34 +00:00CommentedOct 11, 2024 at 19:39 - 2
JavaScript (V8), 44 bytes
t=>t.replace(/(:)|[^ij.;!?]/g,'$1$1').lengthPort of myGoogle Sheets answer.
(-1 thanks to emanresu A)
- \$\begingroup\$44\$\endgroup\$emanresu A– emanresu A2024-10-10 20:55:50 +00:00CommentedOct 10, 2024 at 20:55
Vyxal, 14 bytes
`ij.::;!?`fvO∑ O # Count in input fv # Each of`ij.::;!?` # String "ij.::;!?" ∑ # sum countsR, 43 bytes
\(s)nchar(gsub("(:)|[^ij.;!?]","\\1\\1",s))Port of@doubleunary's Google Sheets answer.
R,48 44 bytes
Edit: -4 bytes porting@Luis Mendo's MATL answer.
\(s)sum(outer(utf8ToInt("ij.;!?::"),s,`==`))Takes input as a vector of character codes.
Zsh, 28 bytes
<<<${#${1//:/..}//[^ij;.!?]}Replace: with.., then remove all non-dot characters and print the string length
Vyxal 3.3.0d, 11 bytes
ᵒ="ij.::;!?I downgraded to Vyxal 3.3.0 because that's the most recent version which still supportsNilad moving, a feature which was removed because it makes debugging super annoying but makes this program a byte shorter because it lets me move the string to the end of the line instead of having it at the front, saving a byte on the closing quotation mark.
The logic is super simple: Take the outer product of equality with the stringij.::;!?, andd deeply sums the result.
- 1\$\begingroup\$Who removed their upvote when I made my solution shorter lol\$\endgroup\$noodle person– noodle person2024-10-11 20:36:54 +00:00CommentedOct 11, 2024 at 20:36
Japt-mx,171615 14bytes
This could be12 bytes in v2 but there seems to be a bug withS.è(x) that only counts a maximum of 1 occurrence ofx.
Takes input as an array of characters.
"!.::;?ij"oU Ê"..."oU Ê :Implicit map of each U in the input array"..." :The necessary characters, with : duplicated oU :Keep only those characters that appear in U Ê :Length :Implicit output of sum of resulting arrayUiua, 14 bytes
⧻⊚⊞="ij.;!?::"Explanation
⊞=: The outer product of equality between the literal"ij.;!?::", and the input⧻⊚: count where elements equal one (true)
iogii, 13 bytes
rq__"ij.;!?::Repeat the input so that the following eQual check is essentially a cartesian product instead of element by element, then sum and sum again.
The string of dot characters is placed at the end so it can be unterminated, it becomes the left arg to equal using iogii's rotation trick.
Racket, 60 bytes
(λ(s'(curryr regexp-match* s)`length)(+`'"[ij.;!?:]"`'":"))Takes a string and runs a regexp twice, nothing fancy, but I'm pleased with the garble of symbols. Heavily relies on default arguments, whichwrite and some formatting elucidates:
(λ (s [quote (curryr regexp-match* s)] [quasiquote length]) (+ (quasiquote (quote "[ij.;!?:]")) (quasiquote (quote ":"))))MATL, 15 bytes
0h'ij.;!?::'!=zTry it online! Orverify all test cases.
How it works
0h % Implicit input. Attach character 0. This is needed to avoid empty string'ij.;!?::' % Push this string. Note that ':' appears twice! % Transpose into a column vector= % Matrix of all pair-wise comparisonsz % Number of non-zeros. Implicit displayJavaScript (ES6), 49 bytes
Expects an array of characters.
a=>a.map(c=>t+=c==":"?2:/[ij.;!?]/.test(c),t=0)|tAPL+WIN, 29 bytes
Prompts for string:
(+/s∊'ij.;!?.')+2×+/(s←⎕)∊':'05AB1E, 13bytes
"!.::;?ij"S¢OTry it online orverify all test cases.
Explanation:
"!.::;?ij" # Push this string (note the "::") S # Convert it to a list of characters ¢ # Count each of those characters in the (implicit) input-string O # Sum the counts together # (after which the result is output implicitly)Unfortunately, the shortest compressed version of this character-list I could find is 1 byte longer:•м€2Q¸Ü•žQÅв¢O. Also, there are some minor variations possible for the same byte-count:":!.;?ij"Ć€¢O or"!.;?ij:"¤ª¢O.
Bash+coreutils, 33 bytes
tr -cd ij.\;!?<<<${1//:/..}|wc -cIs also optimal for zsh, I think.
explanation:
${1//:/..} #replace all : with .. in first argument <<< #and pass it to standard input of...tr -cd ij.\;!? # from stdin, output only characters specified to stdout |wc -c # pass stdout to stdin of: count chars in stdin#implicit output stdout to terminalRetina 0.8.2,14 13 bytes
:..[!.;?ij]Try it online! Link includes test cases. Explanation::s are "rotated", then the relevant characters are counted which produces the desired result. Edit: Saved 1 byte thanks to @m90.
- \$\begingroup\$If
:is replaced with..instead, then:can be omitted from the last line.\$\endgroup\$m90– m902024-10-11 15:29:15 +00:00CommentedOct 11, 2024 at 15:29
J, 19 bytes
1#.1#.'ij.::;!?'=/]Works the same as most.
1#.1#.'ij.::;!?'=/] ] NB. input string 'ij.::;!?' NB. string literal =/ NB. equality table 1#. NB. sum rows1#. NB. sum resulting listJavascript -290242 240 bytes
Counting the dots on a canvas.
s=>[...s].map(a=>{for(x=document.createElement`canvas`.getContext`2d`,x.font="40Q A",x.fillText(a,10,50),d=x.getImageData(i=0,0,99,99).data;++i<1e4;)t+=d[j=i*4+3]>9&&g(j,p=0)<25},t=0,g=i=>d[i]?g(i+4,p++,d[i]=0,g(i-4),g(i+396),g(i-396)):p)|t-45-46 bytes thanks to @Shaggy!
- 1\$\begingroup\$You're always allowed to do an intentionally suboptimal approach and still golf that approach.\$\endgroup\$Unrelated String– Unrelated String2024-10-13 15:31:59 +00:00CommentedOct 13, 2024 at 15:31
- 1\$\begingroup\$Some very quick savings to get you down to 245, but there's a lot more room for improvement.\$\endgroup\$Shaggy– Shaggy2024-10-14 10:07:26 +00:00CommentedOct 14, 2024 at 10:07
- 2\$\begingroup\$Forgot to include this above:
40pxcan be40Q\$\endgroup\$Shaggy– Shaggy2024-10-14 16:16:38 +00:00CommentedOct 14, 2024 at 16:16 - 1\$\begingroup\$Doesn't work fine here, get 0 on
ij.\$\endgroup\$l4m2– l4m22024-10-15 00:31:05 +00:00CommentedOct 15, 2024 at 0:31 - 1\$\begingroup\$
<30works fine\$\endgroup\$l4m2– l4m22024-10-15 01:04:24 +00:00CommentedOct 15, 2024 at 1:04
Charcoal, 14 bytes
IΣE!.::;?ij№θιTry it online! Link is to verbose version of code. Explanation:
!.::;?ij Literal string `!.::;?ij` E Map over characters № Count of ι Current character θ In input string Σ Take the sumI Cast to string Implicitly printDart, 120 bytes
main(List<String>y,{i=0,j=0,x}){x=y[0];for(;i<x.length;i++){if('ij.;!?'.contains(x[i]))j++;if(x[i]==':')j+=2;}print(j);}Only takes one string at a time.
Explore related questions
See similar questions with these tags.















