add bigger wordlist

This commit is contained in:
Jonas 2023-06-13 21:29:33 +02:00
parent bc5227a212
commit 5d095cff1f
2 changed files with 1908855 additions and 32 deletions

72
main.jl
View File

@ -10,20 +10,28 @@ function readInput()
words = Vector{String}()
for line in eachline("./dwdswb-headwords.json")
if line == "{" || line == "}" || line == ""
continue
continue
end
line = strip(line)
line = split(line,"\"")
if occursin(r"^[a-zA-Z]+$",line[2])
push!(words,line[2])
line = split(line, "\"")
if occursin(r"^[a-zA-Z]+$", line[2])
push!(words, line[2])
end
end
return sort(words)
end
function readInput2()
words = Vector{String}()
for line in eachline("wordlist-german.txt")
push!(words, line)
end
return sort(words)
end
function longest()
words = readInput()
maxLength = maximum(length,words)
words = readInput2()
maxLength = maximum(length, words)
for w in words
if length(w) == maxLength
return w
@ -34,16 +42,16 @@ end
function createGraph(words::Vector{String})
graph = Vector{node}()
for w in words
_, me = binarySearch(w,words)
_, me = binarySearch(w, words)
neighbours = Vector{Int}()
for x in HammingNeighbours(w)
exists, index = binarySearch(x,words)
exists, index = binarySearch(x, words)
if exists && index != me
push!(neighbours,index)
push!(neighbours, index)
end
end
n = node(w,neighbours,false)
push!(graph,n)
n = node(w, neighbours, false)
push!(graph, n)
end
return graph
end
@ -51,8 +59,8 @@ end
function binarySearch(word::String, words::Vector{String})
left = 1
right = length(words)
while right-left > 1
middle = ceil(Int,(right+left)/2)
while right - left > 1
middle = ceil(Int, (right + left) / 2)
if words[middle] == word
return true, middle
elseif words[middle] < word
@ -61,12 +69,12 @@ function binarySearch(word::String, words::Vector{String})
right = middle
end
end
middle = (right+left)/2
if words[ceil(Int,middle)] == word
return true, ceil(Int,middle)
middle = (right + left) / 2
if words[ceil(Int, middle)] == word
return true, ceil(Int, middle)
end
if words[floor(Int,middle)] == word
return true, floor(Int,middle)
if words[floor(Int, middle)] == word
return true, floor(Int, middle)
end
return false, 0
end
@ -78,32 +86,32 @@ function HammingNeighbours(InputWord::String)
for c in 'a':'z'
wordCopy = copy(word)
wordCopy[i] = c
push!(neighbours,String(wordCopy))
push!(neighbours, String(wordCopy))
wordCopy = copy(word)
wordCopy = insert!(wordCopy,i,c)
push!(neighbours,String(wordCopy))
wordCopy = insert!(wordCopy, i, c)
push!(neighbours, String(wordCopy))
end
for c in 'A':'Z'
wordCopy = copy(word)
wordCopy[i] = c
push!(neighbours,String(wordCopy))
push!(neighbours, String(wordCopy))
wordCopy = copy(word)
wordCopy = insert!(wordCopy,i,c)
push!(neighbours,String(wordCopy))
wordCopy = insert!(wordCopy, i, c)
push!(neighbours, String(wordCopy))
end
wordCopy = copy(word)
wordCopy = deleteat!(wordCopy,i)
push!(neighbours,String(wordCopy))
wordCopy = deleteat!(wordCopy, i)
push!(neighbours, String(wordCopy))
end
for c in 'a':'z'
wordCopy = copy(word)
push!(wordCopy,c)
push!(neighbours,String(wordCopy))
push!(wordCopy, c)
push!(neighbours, String(wordCopy))
end
for c in 'A':'Z'
wordCopy = copy(word)
push!(wordCopy,c)
push!(neighbours,String(wordCopy))
push!(wordCopy, c)
push!(neighbours, String(wordCopy))
end
return neighbours
end
@ -117,14 +125,14 @@ function BFS(graph::Vector{node})
if graph[i].colored == false
components += 1
currComponent = 1
enqueue!(q,graph[i])
enqueue!(q, graph[i])
graph[i].colored = true
while !isempty(q)
n = dequeue!(q)
for m in n.neighbours
if graph[m].colored == false
currComponent += 1
enqueue!(q,graph[m])
enqueue!(q, graph[m])
graph[m].colored = true
end
end

1908815
wordlist-german.txt Normal file

File diff suppressed because it is too large Load Diff