Implement day 4 part 2.

This commit is contained in:
2017-12-04 10:20:06 +01:00
parent 108ded3ca5
commit cd2acfd143
3 changed files with 36 additions and 2 deletions

View File

@@ -6,11 +6,12 @@ and using 25 different programming languages.
The current plan, in no particular order: The current plan, in no particular order:
- [ ] AWK (note, not included in shell script) - [x] AWK - [Day 04](./day-04) (two separate scripts)
- [x] Bash/shell script - [Day 02](./day-02/solution.sh) - [x] Bash/shell script - [Day 02](./day-02/solution.sh)
- [ ] C - [ ] C
- [x] C++ - [Day 01](./day-01/solution.cpp) - [x] C++ - [Day 01](./day-01/solution.cpp)
- [ ] C# - [ ] C#
- [ ] Clojure - [Day 03](./day-03/solution.clj) (need to finish part 2)
- [ ] Coffeescript - [ ] Coffeescript
- [ ] Haskell - [ ] Haskell
- [ ] Java - [ ] Java
@@ -27,4 +28,4 @@ The current plan, in no particular order:
- [ ] Scheme - [ ] Scheme
- [ ] SQL - [ ] SQL
… and then I will need 5 more. But that will come in time. … and then I will need some more. But that will come in time.

33
2017/day-04/solution2.awk Normal file
View File

@@ -0,0 +1,33 @@
function word2key(word, a, i, n, result)
{
n = split(word, a, "")
asort(a)
for (i = 1; i <= n; i++)
result = result a[i]
return result
}
BEGIN {
valid=0
}
{
duplicates=0
for (i=1;i<=NF;i++) {
a[word2key($i)]++
}
for (x in a)
{
if(a[x]>1)
duplicates++
}
for (x in a)
delete a[x]
if(duplicates==0)
valid++
}
END {
print valid
}