-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.coffee
43 lines (36 loc) · 1001 Bytes
/
4.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{_log,test,expect,testAndRun} = require './util'
is_valid = ( p, sorted )->
words = {}
for w in p.split ' '
w = w.split('').sort().join '' if sorted
if words[w]?
return no
words[w]=yes
yes
count_valid = ( inp, sorted )->
valid = 0
phrases = inp.split '\n'
for p in phrases when is_valid p, sorted
valid++
valid
test.valid1 = ->
expect yes, is_valid 'aa bb cc dd ee'
expect no, is_valid 'aa bb cc dd aa'
expect yes, is_valid 'aa bb cc dd aaa'
return
test.valid2 = ->
expect yes, is_valid 'abcde fghij', yes
expect no, is_valid 'abcde xyz ecdab', yes
expect yes, is_valid 'a ab abc abd abf abj', yes
expect yes, is_valid 'iiii oiii ooii oooi oooo', yes
expect no, is_valid 'oiii ioii iioi iiio', yes
return
test.count_valid = ->
expect 1, count_valid 'asdf fasd\nasdf asdf'
expect 0, count_valid 'asdf fasd\nasdf asdf', yes
return
testAndRun ->
input = require './input/4.txt'
_log.yellow '1:', count_valid input
_log.yellow '2:', count_valid input, yes
return