J-63 자
프로그램은 숫자를 읽은 다음 문장을 읽습니다.
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
폭발로 설명 :
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
1!:1]1 NB. read sentence
e.&'0123456789' NB. is digit? bool vector
i=. NB. save to i
2 /\ NB. between adjacent chars:
~: NB. true if not equal
1, NB. pad to sentence length
( ;.1~ ) NB. cut the sentence
^:(0{i) NB. if cut is digits:
*&.". NB. multiply as number
&(1!:1]1) NB. with user input
; NB. rejoin sentence
J의 PCRE 라이브러리를 사용하여 문장을 먼저 만들면 이것을 54 자로 줄일 수 있습니다 .
;_2(,*&.".&(1!:1]1)&.>)/\'\d+'(rxmatches rxcut])1!:1]1
폭발로 설명 :
1!:1]1 NB. read in sentence
'\d+'(rxmatches ) NB. all /\d+/ matches
( rxcut]) NB. cut by those matches
_2 \ NB. on each nonmatch-match pair:
( &.>)/ NB. take the match
*&.". NB. multiply as number
&(1!:1]1) NB. by user input
(, ) NB. prepend nonmatch
; NB. rejoin sentence
J는 이것에 좋지 않습니다. J가 비관적이기 때문에 불편합니다.
몇 가지 예 :
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
3
This 1 is22a 3352sentence 50
This 3 is66a 10056sentence 150
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
100
N0 R3GUL4R 3XPR35510N5 1N J M4K35 M3 54D ALS0
N0 R300GUL400R 300XPR3551000N500 100N J M400K3500 M300 5400D ALS0
0!:0 <'system\main\regex.ijs' NB. this is usually preloaded by J on startup anyway
;_2(,*&.".&(1!:1]1)&.>)/\'\d+'(rxmatches rxcut])1!:1]1
TH4T'5 M4RG1N411Y B3TT3R
0
TH0T'0 M0RG0N0Y B0TT0R