Skip to main content
added 496 characters in body
Source Link
njpipeorgan
  • 3.1k
  • 14
  • 15

Mathematica, 46 bytes

Count[Characters@#,c_/;RemoveDiacritics@c!=c]&

ToExplanations:

Chatacters extract every characters in the string. Note that there is a difference between two Zoë even if they look the same:

Characters["Zoë"]
(* {"Z", "o", "ë"} *)

Characters["Zoë"]
(* {"Z", "o", "e", "̈ ̈"} *)

Here, the pattern c_/;RemoveDiacritics@c!=c will be honestmatched with those characters that change with diacritics removed. For the first case, I do not really understandonly ë will match since ë becomes e. While for the descriptionsecond case, only :P ̈ will match since it becomes nothing. Whatever case the string is, but the function just workscounting will be correct.

Test cases:Test cases:

f=%; (* assign the function to f. *)

f["Zoë reads the encyclopædia in a café"]
(* 3 *)
f["Zoe reads the encyclopaedia in a cafe"]
(* 0 *)
f["Zoë"]
(* 1 *)
f["Zoë"]
(* 1 *)
f["déjà vu"]
(* 2 *)

Mathematica, 46 bytes

Count[Characters@#,c_/;RemoveDiacritics@c!=c]&

To be honest, I do not really understand the description :P, but the function just works.

Test cases:

f=%; (* assign the function to f. *)

f["Zoë reads the encyclopædia in a café"]
(* 3 *)
f["Zoe reads the encyclopaedia in a cafe"]
(* 0 *)
f["Zoë"]
(* 1 *)
f["Zoë"]
(* 1 *)
f["déjà vu"]
(* 2 *)

Mathematica, 46 bytes

Count[Characters@#,c_/;RemoveDiacritics@c!=c]&

Explanations:

Chatacters extract every characters in the string. Note that there is a difference between two Zoë even if they look the same:

Characters["Zoë"]
(* {"Z", "o", "ë"} *)

Characters["Zoë"]
(* {"Z", "o", "e", "̈ ̈"} *)

Here, the pattern c_/;RemoveDiacritics@c!=c will be matched with those characters that change with diacritics removed. For the first case, only ë will match since ë becomes e. While for the second case, only ̈ will match since it becomes nothing. Whatever case the string is, the counting will be correct.

Test cases:

f=%; (* assign the function to f. *)

f["Zoë reads the encyclopædia in a café"]
(* 3 *)
f["Zoe reads the encyclopaedia in a cafe"]
(* 0 *)
f["Zoë"]
(* 1 *)
f["Zoë"]
(* 1 *)
f["déjà vu"]
(* 2 *)
Source Link
njpipeorgan
  • 3.1k
  • 14
  • 15

Mathematica, 46 bytes

Count[Characters@#,c_/;RemoveDiacritics@c!=c]&

To be honest, I do not really understand the description :P, but the function just works.

Test cases:

f=%; (* assign the function to f. *)

f["Zoë reads the encyclopædia in a café"]
(* 3 *)
f["Zoe reads the encyclopaedia in a cafe"]
(* 0 *)
f["Zoë"]
(* 1 *)
f["Zoë"]
(* 1 *)
f["déjà vu"]
(* 2 *)