Skip to content

Commit a0d8c8b

Browse files
committed
addup wordle
1 parent 985ce58 commit a0d8c8b

File tree

3 files changed

+187
-38
lines changed

3 files changed

+187
-38
lines changed

preview_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,16 @@ func Test_Extract(t *testing.T) {
389389
input: preview.Input{
390390
PlanJSONPath: "",
391391
ParameterValues: map[string]string{
392-
"first": "curs",
392+
"one": "curse",
393+
"two": "snake",
393394
},
394395
Owner: types.WorkspaceOwner{},
395396
},
396397
unknownTags: []string{},
397398
params: map[string]assertParam{
398-
"first": ap().value("curs"),
399+
"one": ap().value("curse"),
400+
"two": ap().value("snake"),
401+
"three": ap(),
399402
},
400403
},
401404
{

testdata/wordle/checker/main.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// the correct word the player is trying to guess
2+
variable "correct" {
3+
type = string
4+
}
5+
6+
// The previous word
7+
variable "previous" {
8+
type = string
9+
}
10+
11+
locals {
12+
// unmatchedLetters are letters that are not exact matches from the
13+
// previous input.
14+
unmatchedLetters = [
15+
for i in range(0, length(var.correct)) : (
16+
substr(var.previous, i, 1)
17+
) if substr(var.previous, i, 1) != substr(var.correct, i, 1)
18+
]
19+
20+
// remainingLetters are letters in the correct word that still exist to be
21+
// guessed.
22+
remainingLetters = [
23+
for i in range(0, length(var.correct)) : (
24+
substr(var.correct, i, 1)
25+
) if substr(var.previous, i, 1) != substr(var.correct, i, 1)
26+
]
27+
28+
// letterExists are misplaced letters that exist in the correct word.
29+
letterExists = [
30+
for l in local.unmatchedLetters : (
31+
l
32+
) if contains(local.remainingLetters, l)
33+
]
34+
35+
matching = join("", [
36+
for i in range(0, length(var.correct)) : (
37+
substr(var.previous, i, 1) == substr(var.correct, i, 1) ?
38+
upper(substr(var.correct, i, 1)) :
39+
contains(local.letterExists, substr(var.previous, i, 1)) ?
40+
lower(substr(var.previous, i, 1)) :
41+
"_"
42+
)
43+
])
44+
}
45+
46+
output "matching" {
47+
value = local.matching
48+
}
49+
50+
output "debug" {
51+
value = {
52+
"correct" = var.correct
53+
"previous" = var.previous
54+
"unmatchedLetters" = local.unmatchedLetters
55+
"remainingLetters" = local.remainingLetters
56+
"letterExists" = local.letterExists
57+
"matching" = local.matching
58+
}
59+
}

testdata/wordle/main.tf

Lines changed: 123 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,145 @@ terraform {
99
locals {
1010
correct = "lasso" // March 17, 2025
1111
validation = {
12-
regex = "^[a-zA-Z]{5}$"
12+
regex = "^[\\sa-zA-Z]{5}$"
1313
error = "You must enter a 5 letter word."
1414
}
15+
16+
description = "Capital letters are an exact match, lowercase are letters that are out of place."
17+
}
18+
19+
data "coder_parameter" "one" {
20+
name = "one"
21+
display_name = "Take a guess what the 5 letter word might be!"
22+
description = "Additional guesses will appear once you input a valid 5 letter word."
23+
type = "string"
24+
order = 11
25+
default = " "
26+
27+
validation {
28+
regex = local.validation.regex
29+
error = local.validation.error
30+
}
1531
}
1632

17-
module "one" {
18-
source = "./word"
19-
index = 0
33+
module "check_one" {
34+
source = "./checker"
2035
correct = local.correct
21-
previous = " "
36+
previous = data.coder_parameter.one.value
2237
}
2338

24-
module "two" {
25-
source = "./word"
26-
index = 1
39+
data "coder_parameter" "two" {
40+
# count = length(data.coder_parameter.one.value) == 5 ? 1 : 0
41+
count = 1
42+
name = "two"
43+
display_name = module.check_one.matching
44+
description = local.description
45+
type = "string"
46+
order = 12
47+
default = " "
48+
49+
validation {
50+
regex = local.validation.regex
51+
error = local.validation.error
52+
}
53+
}
54+
55+
module "check_two" {
56+
source = "./checker"
2757
correct = local.correct
28-
previous = module.one.value
58+
previous = data.coder_parameter.two[0].value
59+
}
60+
61+
output "debug" {
62+
value = {
63+
"two": length(try(data.coder_parameter.two[0].value, ""))
64+
"two_d": module.check_two.debug
65+
}
66+
}
67+
68+
data "coder_parameter" "three" {
69+
# count = length(try(data.coder_parameter.two[0].value, "")) == 5 ? 1 : 0
70+
count = 1
71+
name = "three"
72+
display_name = module.check_two.matching
73+
description = local.description
74+
type = "string"
75+
order = 13
76+
default = " "
77+
78+
validation {
79+
regex = local.validation.regex
80+
error = local.validation.error
81+
}
2982
}
3083

31-
module "three" {
32-
source = "./word"
33-
index = 2
84+
module "check_three" {
85+
source = "./checker"
3486
correct = local.correct
35-
previous = module.two.value
87+
previous = data.coder_parameter.three[0].value
3688
}
37-
#
38-
# module "four" {
39-
# source = "./word"
40-
# index = 3
41-
# correct = local.correct
42-
# previous = module.three.value
43-
# }
44-
#
45-
# module "five" {
46-
# source = "./word"
47-
# index = 4
48-
# correct = local.correct
49-
# previous = module.four.value
50-
# }
51-
#
52-
# module "six" {
53-
# source = "./word"
54-
# index = 5
55-
# correct = local.correct
56-
# previous = module.five.value
57-
# }
5889

90+
data "coder_parameter" "four" {
91+
# count = length(try(data.coder_parameter.three[0].value, "")) == 5 ? 1 : 0
92+
count = 1
93+
name = "four"
94+
display_name = module.check_three.matching
95+
description = local.description
96+
type = "string"
97+
order = 14
98+
default = " "
5999

60-
output "debug" {
61-
value = module.two.debug
100+
validation {
101+
regex = local.validation.regex
102+
error = local.validation.error
103+
}
62104
}
63105

106+
module "check_four" {
107+
source = "./checker"
108+
correct = local.correct
109+
previous = data.coder_parameter.four[0].value
110+
}
111+
112+
data "coder_parameter" "five" {
113+
# count = length(try(data.coder_parameter.four[0].value, "")) == 5 ? 1 : 0
114+
count = 1
115+
name = "five"
116+
display_name = module.check_four.matching
117+
description = local.description
118+
type = "string"
119+
order = 15
120+
default = " "
121+
122+
validation {
123+
regex = local.validation.regex
124+
error = local.validation.error
125+
}
126+
}
127+
128+
module "check_five" {
129+
source = "./checker"
130+
correct = local.correct
131+
previous = data.coder_parameter.five[0].value
132+
}
133+
134+
data "coder_parameter" "six" {
135+
# count = length(try(data.coder_parameter.five[0].value, "")) == 5 ? 1 : 0
136+
count = 1
137+
name = "six"
138+
display_name = module.check_five.matching
139+
description = local.description
140+
type = "string"
141+
order = 16
142+
default = " "
143+
144+
validation {
145+
regex = local.validation.regex
146+
error = local.validation.error
147+
}
148+
}
149+
150+
64151
#
65152
# module "word_one" {
66153
# source = "./checker"

0 commit comments

Comments
 (0)