29
\$\begingroup\$

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

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>                             0

This question has 58 dots.

askedOct 10, 2024 at 18:25
Jordan's user avatar
\$\endgroup\$
3
  • \$\begingroup\$Sandbox\$\endgroup\$CommentedOct 10, 2024 at 18:26
  • \$\begingroup\$Can we take input as an array of characters?\$\endgroup\$CommentedOct 10, 2024 at 19:13
  • 1
    \$\begingroup\$@ShaggyYes.\$\endgroup\$CommentedOct 10, 2024 at 19:14

38 Answers38

11
\$\begingroup\$

Uiua,18 15 bytes

/+♭⊞="ij.::;!?"

Try it:Uiua pad

Explanation: Sum of the flattened equality table of the input with"ij.::;!?".

answeredOct 10, 2024 at 20:59
noodle person's user avatar
\$\endgroup\$
2
  • \$\begingroup\$/+♭ is equivalent to⧻⊚ for booleans, as demonstrated inmy answer.\$\endgroup\$CommentedOct 15, 2024 at 0:04
  • \$\begingroup\$@janMakoso Clever, upvoted.\$\endgroup\$CommentedOct 15, 2024 at 1:27
8
\$\begingroup\$

Google Sheets, 45 bytes

=len(regexreplace(A1,"(:)|[^ij.;!?]","$1$1"))

Put the text string in cellA1 and the formula in cellB1.

screenshot

(-1 thanks to emanresu A)

answeredOct 10, 2024 at 19:35
doubleunary's user avatar
\$\endgroup\$
2
  • \$\begingroup\$.split`:`.join`::` saves a few bytes on the latter (edit: actually, replacing'::' with10 is better)\$\endgroup\$CommentedOct 10, 2024 at 20:04
  • \$\begingroup\$@emanresuA thanks, but using abetter regex saves many more.\$\endgroup\$CommentedOct 10, 2024 at 20:23
8
\$\begingroup\$

Python 3,42 37 bytes

lambda a:sum(map(a.count,'ij.;!?::'))

Try it online!

answeredOct 11, 2024 at 0:23
Lucenaposition's user avatar
\$\endgroup\$
1
  • \$\begingroup\$You can save some bytes withmap\$\endgroup\$CommentedOct 11, 2024 at 2:16
7
\$\begingroup\$

JavaScript (Node.js), 50 bytes

x=>[...'ij.;!?::'].flatMap(c=>x.split(c)).length-8

Try it online!

answeredOct 10, 2024 at 18:47
l4m2's user avatar
\$\endgroup\$
7
\$\begingroup\$

Perl 5-p0, 20 bytes

$_=y/ij.;!?://+y/://

Try it online!

answeredOct 10, 2024 at 22:02
Xcali's user avatar
\$\endgroup\$
3
  • \$\begingroup\$This doesn't seem to work for inputs with newlines (per TIO at least). Do we care?\$\endgroup\$CommentedOct 11, 2024 at 19:22
  • 1
    \$\begingroup\$@GregMartin It does if you add a-0 on the command line. There's no change needed to the code itself to support it.\$\endgroup\$CommentedOct 11, 2024 at 19:39
  • 2
    \$\begingroup\$@GregMartin Byconsensus, printable ASCII doesn’t include newlines.\$\endgroup\$CommentedOct 11, 2024 at 19:51
4
\$\begingroup\$

JavaScript (V8), 44 bytes

t=>t.replace(/(:)|[^ij.;!?]/g,'$1$1').length

Try it online!

Port of myGoogle Sheets answer.

(-1 thanks to emanresu A)

answeredOct 10, 2024 at 20:21
doubleunary's user avatar
\$\endgroup\$
1
  • \$\begingroup\$44\$\endgroup\$CommentedOct 10, 2024 at 20:55
4
\$\begingroup\$

Vyxal, 14 bytes

`ij.::;!?`fvO∑

Try it Online!

            O  # Count in input          fv   # Each of`ij.::;!?`     # String "ij.::;!?"             ∑ # sum counts
answeredOct 10, 2024 at 21:59
emanresu A's user avatar
\$\endgroup\$
4
\$\begingroup\$

R, 43 bytes

\(s)nchar(gsub("(:)|[^ij.;!?]","\\1\\1",s))

Attempt This Online!

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,`==`))

Attempt This Online!

Takes input as a vector of character codes.

answeredOct 10, 2024 at 19:45
pajonk's user avatar
\$\endgroup\$
4
\$\begingroup\$

Zsh, 28 bytes

<<<${#${1//:/..}//[^ij;.!?]}

Try it online!

Replace: with.., then remove all non-dot characters and print the string length

answeredOct 12, 2024 at 0:43
GammaFunction's user avatar
\$\endgroup\$
3
\$\begingroup\$

Jelly, 14  13bytes

ċⱮ“::ij.;!?”S

A monadic Link that accepts a list of characters and yields the number of dots.

Try it online!

How?

ċⱮ“::ij.;!?”S - Link: list of characters, T  “::ij.;!?”  - list of characters -> "::ij.;!?" Ɱ            - map with:ċ             -   {T} count {char}            S - sum
answeredOct 10, 2024 at 19:21
Jonathan Allan's user avatar
\$\endgroup\$
3
\$\begingroup\$

Arturo, 41 bytes

$=>[replace&":"{..}|match"[ij.;!?]"|size]

Try it!

answeredOct 10, 2024 at 23:39
chunes's user avatar
\$\endgroup\$
3
\$\begingroup\$

Vyxal 3.3.0d, 11 bytes

ᵒ="ij.::;!?

Try it Online!

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.

answeredOct 10, 2024 at 21:23
noodle person's user avatar
\$\endgroup\$
1
  • 1
    \$\begingroup\$Who removed their upvote when I made my solution shorter lol\$\endgroup\$CommentedOct 11, 2024 at 20:36
3
\$\begingroup\$

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 Ê

Try it

"..."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 array
answeredOct 10, 2024 at 19:04
Shaggy's user avatar
\$\endgroup\$
3
\$\begingroup\$

Uiua, 14 bytes

⧻⊚⊞="ij.;!?::"

Try it online!

Explanation

  • ⊞=: The outer product of equality between the literal"ij.;!?::", and the input
  • ⧻⊚: count where elements equal one (true)
answeredOct 14, 2024 at 23:59
janMakoso's user avatar
\$\endgroup\$
3
\$\begingroup\$

K (ngn/k), 19 bytes

+//"ij.;!?::"=\:

Try it online!

answeredOct 29, 2024 at 11:45
gurditsbedi's user avatar
\$\endgroup\$
3
\$\begingroup\$

iogii, 13 bytes

rq__"ij.;!?::

run it here!!

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.

answeredOct 31, 2024 at 1:27
Darren Smith's user avatar
\$\endgroup\$
2
\$\begingroup\$

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 ":"))))

Try it online!

answeredOct 13, 2024 at 17:14
mehbark's user avatar
\$\endgroup\$
2
\$\begingroup\$

MATL, 15 bytes

0h'ij.;!?::'!=z

Try 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 display
answeredOct 10, 2024 at 19:08
Luis Mendo's user avatar
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 49 bytes

Expects an array of characters.

a=>a.map(c=>t+=c==":"?2:/[ij.;!?]/.test(c),t=0)|t

Try it online!

answeredOct 10, 2024 at 19:27
Arnauld's user avatar
\$\endgroup\$
2
\$\begingroup\$

APL+WIN, 29 bytes

Prompts for string:

(+/s∊'ij.;!?.')+2×+/(s←⎕)∊':'

Try it online! Thanks to Dyalog Classic

answeredOct 10, 2024 at 19:30
Graham's user avatar
\$\endgroup\$
2
\$\begingroup\$

05AB1E, 13bytes

"!.::;?ij"S¢O

Try 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.

answeredOct 11, 2024 at 7:05
Kevin Cruijssen's user avatar
\$\endgroup\$
2
\$\begingroup\$

Red, 69 bytes

func[s][n: 0 foreach c s[n: n + case[find"ij.;!?"c 1 c =#":"2 1 0]]n]

Try it online!

answeredOct 11, 2024 at 7:57
Galen Ivanov's user avatar
\$\endgroup\$
2
\$\begingroup\$

Bash+coreutils, 33 bytes

tr -cd ij.\;!?<<<${1//:/..}|wc -c

Attempt This Online!

Is 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 terminal
answeredOct 11, 2024 at 12:23
Themoonisacheese's user avatar
\$\endgroup\$
2
\$\begingroup\$

Retina 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.

answeredOct 10, 2024 at 21:47
Neil's user avatar
\$\endgroup\$
1
  • \$\begingroup\$If: is replaced with.. instead, then: can be omitted from the last line.\$\endgroup\$CommentedOct 11, 2024 at 15:29
2
\$\begingroup\$

Haskell, 34 bytes

f x=sum[1|c<-x,v<-"ij.;!?::",c==v]

Try it online!

answeredOct 11, 2024 at 21:58
Antonio Ponce's user avatar
\$\endgroup\$
2
\$\begingroup\$

J, 19 bytes

1#.1#.'ij.::;!?'=/]

Works the same as most.

Attempt This Online!

1#.1#.'ij.::;!?'=/]                  ]   NB. input string      'ij.::;!?'      NB. string literal                =/    NB. equality table   1#.                NB. sum rows1#.                   NB. sum resulting list
answeredOct 11, 2024 at 23:14
south's user avatar
\$\endgroup\$
2
\$\begingroup\$

Pyth, 12 bytes

sm/"ij.::;!?

Try it online!

answeredOct 12, 2024 at 21:03
Mr. Xcoder's user avatar
\$\endgroup\$
2
\$\begingroup\$

Javascript -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!

JSFiddle

answeredOct 13, 2024 at 15:28
jdt's user avatar
\$\endgroup\$
9
  • 1
    \$\begingroup\$You're always allowed to do an intentionally suboptimal approach and still golf that approach.\$\endgroup\$CommentedOct 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\$CommentedOct 14, 2024 at 10:07
  • 2
    \$\begingroup\$Forgot to include this above:40px can be40Q\$\endgroup\$CommentedOct 14, 2024 at 16:16
  • 1
    \$\begingroup\$Doesn't work fine here, get 0 onij.\$\endgroup\$CommentedOct 15, 2024 at 0:31
  • 1
    \$\begingroup\$<30 works fine\$\endgroup\$CommentedOct 15, 2024 at 1:04
1
\$\begingroup\$

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 print
answeredOct 10, 2024 at 21:45
Neil's user avatar
\$\endgroup\$
1
\$\begingroup\$

Dart, 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);}

Try it online!

Only takes one string at a time.

answeredOct 11, 2024 at 1:02
Redz's user avatar
\$\endgroup\$
1
  • \$\begingroup\$85 bytes\$\endgroup\$CommentedOct 14, 2024 at 18:09

Your Answer

More generally…

  • …Please make sure to answer the question and provide sufficient detail.

  • …Avoid asking for help, clarification or responding to other answers (use comments instead).

Draft saved
Draft discarded

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.