mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Merge awk solutions.
This commit is contained in:
@@ -6,7 +6,7 @@ and using 25 different programming languages.
|
|||||||
|
|
||||||
The current plan, in no particular order:
|
The current plan, in no particular order:
|
||||||
|
|
||||||
- [x] AWK - [Day 04](./day-04) (two separate scripts)
|
- [x] AWK - [Day 04](./day-04/solution.awk)
|
||||||
- [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)
|
||||||
|
|||||||
@@ -10,24 +10,37 @@ function word2key(word, a, i, n, result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
valid=0
|
valid1=0
|
||||||
|
valid2=0
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
duplicates=0
|
duplicates=0
|
||||||
|
anagrams=0
|
||||||
for (i=1;i<=NF;i++) {
|
for (i=1;i<=NF;i++) {
|
||||||
a[word2key($i)]++
|
a[word2key($i)]++
|
||||||
|
b[$i]++
|
||||||
}
|
}
|
||||||
for (x in a)
|
for (x in a)
|
||||||
{
|
{
|
||||||
if(a[x]>1)
|
if (a[x] > 1)
|
||||||
duplicates++
|
anagrams++
|
||||||
}
|
|
||||||
for (x in a)
|
|
||||||
delete a[x]
|
delete a[x]
|
||||||
|
}
|
||||||
|
for (x in b) {
|
||||||
|
if (b[x] > 1)
|
||||||
|
duplicates++
|
||||||
|
|
||||||
if(duplicates==0)
|
delete b[x]
|
||||||
valid++
|
}
|
||||||
|
|
||||||
|
if (duplicates == 0)
|
||||||
|
valid1++
|
||||||
|
|
||||||
|
if (anagrams == 0)
|
||||||
|
valid2++
|
||||||
}
|
}
|
||||||
END {
|
END {
|
||||||
print valid
|
print valid1
|
||||||
|
print valid2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
BEGIN {
|
|
||||||
valid=0
|
|
||||||
}
|
|
||||||
{
|
|
||||||
duplicates=0
|
|
||||||
for (i=1;i<=NF;i++) {
|
|
||||||
a[$i]++
|
|
||||||
}
|
|
||||||
for (x in a)
|
|
||||||
{
|
|
||||||
if(a[x]>1)
|
|
||||||
duplicates++
|
|
||||||
}
|
|
||||||
for (x in a)
|
|
||||||
delete a[x]
|
|
||||||
|
|
||||||
if(duplicates==0)
|
|
||||||
valid++
|
|
||||||
}
|
|
||||||
END {
|
|
||||||
print valid
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user