add bigger wordlist
This commit is contained in:
parent
bc5227a212
commit
5d095cff1f
72
main.jl
72
main.jl
@ -10,20 +10,28 @@ function readInput()
|
|||||||
words = Vector{String}()
|
words = Vector{String}()
|
||||||
for line in eachline("./dwdswb-headwords.json")
|
for line in eachline("./dwdswb-headwords.json")
|
||||||
if line == "{" || line == "}" || line == ""
|
if line == "{" || line == "}" || line == ""
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
line = strip(line)
|
line = strip(line)
|
||||||
line = split(line,"\"")
|
line = split(line, "\"")
|
||||||
if occursin(r"^[a-zA-Z]+$",line[2])
|
if occursin(r"^[a-zA-Z]+$", line[2])
|
||||||
push!(words,line[2])
|
push!(words, line[2])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return sort(words)
|
return sort(words)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function readInput2()
|
||||||
|
words = Vector{String}()
|
||||||
|
for line in eachline("wordlist-german.txt")
|
||||||
|
push!(words, line)
|
||||||
|
end
|
||||||
|
return sort(words)
|
||||||
|
end
|
||||||
|
|
||||||
function longest()
|
function longest()
|
||||||
words = readInput()
|
words = readInput2()
|
||||||
maxLength = maximum(length,words)
|
maxLength = maximum(length, words)
|
||||||
for w in words
|
for w in words
|
||||||
if length(w) == maxLength
|
if length(w) == maxLength
|
||||||
return w
|
return w
|
||||||
@ -34,16 +42,16 @@ end
|
|||||||
function createGraph(words::Vector{String})
|
function createGraph(words::Vector{String})
|
||||||
graph = Vector{node}()
|
graph = Vector{node}()
|
||||||
for w in words
|
for w in words
|
||||||
_, me = binarySearch(w,words)
|
_, me = binarySearch(w, words)
|
||||||
neighbours = Vector{Int}()
|
neighbours = Vector{Int}()
|
||||||
for x in HammingNeighbours(w)
|
for x in HammingNeighbours(w)
|
||||||
exists, index = binarySearch(x,words)
|
exists, index = binarySearch(x, words)
|
||||||
if exists && index != me
|
if exists && index != me
|
||||||
push!(neighbours,index)
|
push!(neighbours, index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
n = node(w,neighbours,false)
|
n = node(w, neighbours, false)
|
||||||
push!(graph,n)
|
push!(graph, n)
|
||||||
end
|
end
|
||||||
return graph
|
return graph
|
||||||
end
|
end
|
||||||
@ -51,8 +59,8 @@ end
|
|||||||
function binarySearch(word::String, words::Vector{String})
|
function binarySearch(word::String, words::Vector{String})
|
||||||
left = 1
|
left = 1
|
||||||
right = length(words)
|
right = length(words)
|
||||||
while right-left > 1
|
while right - left > 1
|
||||||
middle = ceil(Int,(right+left)/2)
|
middle = ceil(Int, (right + left) / 2)
|
||||||
if words[middle] == word
|
if words[middle] == word
|
||||||
return true, middle
|
return true, middle
|
||||||
elseif words[middle] < word
|
elseif words[middle] < word
|
||||||
@ -61,12 +69,12 @@ function binarySearch(word::String, words::Vector{String})
|
|||||||
right = middle
|
right = middle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
middle = (right+left)/2
|
middle = (right + left) / 2
|
||||||
if words[ceil(Int,middle)] == word
|
if words[ceil(Int, middle)] == word
|
||||||
return true, ceil(Int,middle)
|
return true, ceil(Int, middle)
|
||||||
end
|
end
|
||||||
if words[floor(Int,middle)] == word
|
if words[floor(Int, middle)] == word
|
||||||
return true, floor(Int,middle)
|
return true, floor(Int, middle)
|
||||||
end
|
end
|
||||||
return false, 0
|
return false, 0
|
||||||
end
|
end
|
||||||
@ -78,32 +86,32 @@ function HammingNeighbours(InputWord::String)
|
|||||||
for c in 'a':'z'
|
for c in 'a':'z'
|
||||||
wordCopy = copy(word)
|
wordCopy = copy(word)
|
||||||
wordCopy[i] = c
|
wordCopy[i] = c
|
||||||
push!(neighbours,String(wordCopy))
|
push!(neighbours, String(wordCopy))
|
||||||
wordCopy = copy(word)
|
wordCopy = copy(word)
|
||||||
wordCopy = insert!(wordCopy,i,c)
|
wordCopy = insert!(wordCopy, i, c)
|
||||||
push!(neighbours,String(wordCopy))
|
push!(neighbours, String(wordCopy))
|
||||||
end
|
end
|
||||||
for c in 'A':'Z'
|
for c in 'A':'Z'
|
||||||
wordCopy = copy(word)
|
wordCopy = copy(word)
|
||||||
wordCopy[i] = c
|
wordCopy[i] = c
|
||||||
push!(neighbours,String(wordCopy))
|
push!(neighbours, String(wordCopy))
|
||||||
wordCopy = copy(word)
|
wordCopy = copy(word)
|
||||||
wordCopy = insert!(wordCopy,i,c)
|
wordCopy = insert!(wordCopy, i, c)
|
||||||
push!(neighbours,String(wordCopy))
|
push!(neighbours, String(wordCopy))
|
||||||
end
|
end
|
||||||
wordCopy = copy(word)
|
wordCopy = copy(word)
|
||||||
wordCopy = deleteat!(wordCopy,i)
|
wordCopy = deleteat!(wordCopy, i)
|
||||||
push!(neighbours,String(wordCopy))
|
push!(neighbours, String(wordCopy))
|
||||||
end
|
end
|
||||||
for c in 'a':'z'
|
for c in 'a':'z'
|
||||||
wordCopy = copy(word)
|
wordCopy = copy(word)
|
||||||
push!(wordCopy,c)
|
push!(wordCopy, c)
|
||||||
push!(neighbours,String(wordCopy))
|
push!(neighbours, String(wordCopy))
|
||||||
end
|
end
|
||||||
for c in 'A':'Z'
|
for c in 'A':'Z'
|
||||||
wordCopy = copy(word)
|
wordCopy = copy(word)
|
||||||
push!(wordCopy,c)
|
push!(wordCopy, c)
|
||||||
push!(neighbours,String(wordCopy))
|
push!(neighbours, String(wordCopy))
|
||||||
end
|
end
|
||||||
return neighbours
|
return neighbours
|
||||||
end
|
end
|
||||||
@ -117,14 +125,14 @@ function BFS(graph::Vector{node})
|
|||||||
if graph[i].colored == false
|
if graph[i].colored == false
|
||||||
components += 1
|
components += 1
|
||||||
currComponent = 1
|
currComponent = 1
|
||||||
enqueue!(q,graph[i])
|
enqueue!(q, graph[i])
|
||||||
graph[i].colored = true
|
graph[i].colored = true
|
||||||
while !isempty(q)
|
while !isempty(q)
|
||||||
n = dequeue!(q)
|
n = dequeue!(q)
|
||||||
for m in n.neighbours
|
for m in n.neighbours
|
||||||
if graph[m].colored == false
|
if graph[m].colored == false
|
||||||
currComponent += 1
|
currComponent += 1
|
||||||
enqueue!(q,graph[m])
|
enqueue!(q, graph[m])
|
||||||
graph[m].colored = true
|
graph[m].colored = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
1908815
wordlist-german.txt
Normal file
1908815
wordlist-german.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user