Use function to build solution
This commit is contained in:
parent
037ec7bdfb
commit
eb9c98ae88
|
@ -1,23 +1,28 @@
|
||||||
; https://www.isharkfly.com/t/mumps-character-counting/15224
|
; https://www.isharkfly.com/t/mumps-character-counting/15224
|
||||||
SET array("a")="adsakljasdira"
|
SET ary("1")="abcabc a"
|
||||||
SET array("D")="DDD"
|
SET ary("10")="abcabc aba"
|
||||||
DO countCharsInAry(.array, .countByChar)
|
;SET ary("11")="abcabc aba"
|
||||||
|
|
||||||
|
DO countCharsInAry(.ary, .countByChar)
|
||||||
set name=""
|
set name=""
|
||||||
f s name=$O(countByChar(name)) q:name="" w !,countByChar(name)
|
f s name=$O(countByChar(name)) q:name="" w !,name,">",countByChar(name)
|
||||||
QUIT
|
QUIT
|
||||||
countCharsInAry(ary,countByChar)
|
countCharsInAry(ary,countByChar)
|
||||||
SET name=""
|
S name=""
|
||||||
FOR SET name=$O(ary(name)) QUIT:name="" DO SET countByChar(name)=$$getCount(ary(name),name)
|
FOR SET name=$O(ary(name)) QUIT:name="" D
|
||||||
QUIT
|
. W !,ary(name)
|
||||||
getCount(str,subStr)
|
. S countByChar=$$getCount(ary(name))
|
||||||
SET count=0
|
Q
|
||||||
SET position=0
|
getCount(str)
|
||||||
|
S countByChar=""
|
||||||
FOR {
|
SET totalChars = 0
|
||||||
SET position=$FIND(str, subStr, position)
|
FOR charIndex = 1:1:$LENGTH(str) DO
|
||||||
QUIT:position=0
|
. S currentChar=""
|
||||||
SET count=count+1
|
. S currentChar = $EXTRACT(str, charIndex)
|
||||||
SET position=position
|
. W !,$DATA(countByChar(currentChar))
|
||||||
}
|
. IF $DATA(countByChar(currentChar))'=1 DO
|
||||||
|
. . SET countByChar(currentChar) = 1
|
||||||
QUIT count
|
. ELSE DO
|
||||||
|
. . SET countByChar(currentChar) = countByChar(currentChar) + 1
|
||||||
|
. SET totalChars = totalChars + 1
|
||||||
|
q countByChar
|
||||||
|
|
Loading…
Reference in New Issue