Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import os
- import time
- import math
- import runtime
- fn main() {
- println('Started...')
- sw := time.new_stopwatch()
- possible_answers := json.decode([]string, os.read_file('./wordle_min.json')!)!
- mut score_index := []int{len: possible_answers.len, init: 0}
- thread_count := runtime.nr_cpus()
- chunk_size := int(math.ceil(f64(possible_answers.len) / f64(thread_count)))
- ch := chan []int{}
- for chunk in 0 .. thread_count {
- from := chunk_size * chunk
- to := if (from + chunk_size) > possible_answers.len {
- possible_answers.len
- } else {
- from + chunk_size
- }
- spawn add_scores(possible_answers, from, to, ch)
- }
- for _ in 0 .. thread_count {
- result := <-ch
- for i, v in result {
- score_index[i] += v
- }
- }
- ch.close()
- mut sorted_scores := score_index.clone()
- sorted_scores.sort(a > b)
- mut res := 'Best Words:\n > '
- for i in 0 .. 5 {
- score := sorted_scores[i]
- res += '${possible_answers[score_index.index(score)]}: ${score} | '
- }
- println(res)
- println('Process took ${sw.elapsed().milliseconds()} ms')
- }
- fn add_scores(possible_answers []string, from int, to int, ch chan []int) {
- mut res := []int{len: possible_answers.len, init: 0}
- for x in from .. to {
- for y in 0 .. possible_answers.len {
- for x_char_index in 0 .. 5 {
- x_char := possible_answers[x][x_char_index]
- if x_char == possible_answers[y][x_char_index] {
- res[y] += 5
- } else if possible_answers[y].contains(x_char.ascii_str()) {
- res[y] += 4
- }
- }
- }
- }
- ch <- res
- }
Advertisement
Add Comment
Please, Sign In to add comment