mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement day 4 part 2.
This commit is contained in:
@@ -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
33
2017/day-04/solution2.awk
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user