[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
count char in string [The Emacs Challenge Competition - round 2, with fa
From: |
Emanuel Berg |
Subject: |
count char in string [The Emacs Challenge Competition - round 2, with fallout] |
Date: |
Wed, 28 Oct 2020 01:42:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
round 1:
https://lists.gnu.org/archive/html/help-gnu-emacs/2020-10/msg00524.html
fallout:
1. Daniel Martín (1 point)
2. Emanuel Berg (-2)
Yes, your read it right, incorrect answers are "awarded" -2 points.
This is like the Russian or Cuban Olympic/Amateur boxing program -
only gold counts!
But: doesn't that mean that people will be afraid to post? Again, in
the Russian and Cuban Olympic/Amateur boxing programs, we are not
concerned with people who are afraid...
round 2:
Very simple: we are looking for a function that returns the number of
occurrences of a char in a string.
Emanuel Berg's solution:
(require 'cl-lib)
(defun count-char-in-string (the-char str)
(let ((c (if (characterp the-char) the-char (string-to-char the-char)))
(cs (string-to-list str)) )
(cl-count c cs) ))
;; (count-char-in-string ?a "Emacs skills kills") ; 1
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
- count char in string [The Emacs Challenge Competition - round 2, with fallout],
Emanuel Berg <=
- Re: count char in string [The Emacs Challenge Competition - round 2, with fallout], Corwin Brust, 2020/10/28
- Re: count char in string [The Emacs Challenge Competition - round 2, with fallout], Benjamín Buccianti, 2020/10/28
- Re: count char in string [The Emacs Challenge Competition - round 2, with fallout], Stephen Berman, 2020/10/29
- Re: count char in string [The Emacs Challenge Competition - round 2, with fallout], Patrick McAllister, 2020/10/29