Skip to content

Commit fee2d1c

Browse files
committed
add remaining letters
1 parent a0d8c8b commit fee2d1c

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

testdata/wordle/checker/main.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ locals {
1313
// previous input.
1414
unmatchedLetters = [
1515
for i in range(0, length(var.correct)) : (
16-
substr(var.previous, i, 1)
16+
substr(var.previous, i, 1)
1717
) if substr(var.previous, i, 1) != substr(var.correct, i, 1)
1818
]
1919

@@ -32,6 +32,12 @@ locals {
3232
) if contains(local.remainingLetters, l)
3333
]
3434

35+
letterNotExists = [
36+
for l in local.unmatchedLetters : (
37+
l
38+
) if !contains(local.remainingLetters, l)
39+
]
40+
3541
matching = join("", [
3642
for i in range(0, length(var.correct)) : (
3743
substr(var.previous, i, 1) == substr(var.correct, i, 1) ?
@@ -47,6 +53,10 @@ output "matching" {
4753
value = local.matching
4854
}
4955

56+
output "unmatching" {
57+
value = local.letterNotExists
58+
}
59+
5060
output "debug" {
5161
value = {
5262
"correct" = var.correct

testdata/wordle/main.tf

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,28 @@ terraform {
99
locals {
1010
correct = "lasso" // March 17, 2025
1111
validation = {
12-
regex = "^[\\sa-zA-Z]{5}$"
12+
regex = "^(?:[A-Za-z]{5})?$"
1313
error = "You must enter a 5 letter word."
1414
}
1515

1616
description = "Capital letters are an exact match, lowercase are letters that are out of place."
17+
alphabet = split("", "abcdefghijklmnopqrstuvwxyz")
18+
remaining = setsubtract(toset(local.alphabet), toset(module.check_one.unmatching))
19+
}
20+
21+
output "unmatched" {
22+
value = toset(module.check_one.unmatching)
23+
}
24+
25+
data "coder_parameter" "letter_bank" {
26+
name = "letter_bank"
27+
display_name = "Letter bank"
28+
description = "Remaining available letters."
29+
type = "string"
30+
order = 9
31+
default = join("", local.remaining)
32+
form_type = "input"
33+
# count = 0
1734
}
1835

1936
data "coder_parameter" "one" {
@@ -22,7 +39,7 @@ data "coder_parameter" "one" {
2239
description = "Additional guesses will appear once you input a valid 5 letter word."
2340
type = "string"
2441
order = 11
25-
default = " "
42+
default = ""
2643

2744
validation {
2845
regex = local.validation.regex
@@ -44,7 +61,7 @@ data "coder_parameter" "two" {
4461
description = local.description
4562
type = "string"
4663
order = 12
47-
default = " "
64+
default = ""
4865

4966
validation {
5067
regex = local.validation.regex
@@ -73,7 +90,7 @@ data "coder_parameter" "three" {
7390
description = local.description
7491
type = "string"
7592
order = 13
76-
default = " "
93+
default = ""
7794

7895
validation {
7996
regex = local.validation.regex
@@ -95,7 +112,7 @@ data "coder_parameter" "four" {
95112
description = local.description
96113
type = "string"
97114
order = 14
98-
default = " "
115+
default = ""
99116

100117
validation {
101118
regex = local.validation.regex
@@ -117,7 +134,7 @@ data "coder_parameter" "five" {
117134
description = local.description
118135
type = "string"
119136
order = 15
120-
default = " "
137+
default = ""
121138

122139
validation {
123140
regex = local.validation.regex
@@ -139,7 +156,7 @@ data "coder_parameter" "six" {
139156
description = local.description
140157
type = "string"
141158
order = 16
142-
default = " "
159+
default = ""
143160

144161
validation {
145162
regex = local.validation.regex

0 commit comments

Comments
 (0)