From 3418a5a3ce2c041c77786e23588857ae33a92dce Mon Sep 17 00:00:00 2001 From: ralph kemp Date: Tue, 15 Jan 2019 02:37:13 +0000 Subject: [PATCH 1/4] starting off writing some logic, too late my brain cant figure it out right now. --- src/components/Results.js | 11 ++- src/data/words.js | 136 ++++++++++-------------------------- src/helpers/puzzleSolver.js | 42 +++++++++++ 3 files changed, 81 insertions(+), 108 deletions(-) create mode 100644 src/helpers/puzzleSolver.js diff --git a/src/components/Results.js b/src/components/Results.js index a69ec33..7713855 100644 --- a/src/components/Results.js +++ b/src/components/Results.js @@ -2,6 +2,7 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import styled from "styled-components"; import { data } from '../data/words'; +import { puzzleSolver } from '../helpers/puzzleSolver'; // import uuidv1 from "uuid/v1"; const MainResultsDiv = styled.div` @@ -18,11 +19,6 @@ const WordsContainer = styled.div` `; class Results extends Component { - - componentDidMount() { - console.log(data) - } - renderWords(x, y) { return ( @@ -37,9 +33,10 @@ class Results extends Component { {this.props.words ? (
- {this.renderWords( + {puzzleSolver( this.props.words.firstWord, - this.props.words.secondWord + this.props.words.secondWord, + data )}
) : null} diff --git a/src/data/words.js b/src/data/words.js index 9733658..e1512dc 100644 --- a/src/data/words.js +++ b/src/data/words.js @@ -1,8 +1,4 @@ -export const data = - - - -{ +export const data = { "results": [ { @@ -97,8 +93,7 @@ export const data = { "word": "achy" }, - { - }, + { "word": "aclu" }, @@ -288,12 +283,7 @@ export const data = { "word": "ahum" }, - { - }, - { - }, - { - }, + { "word": "aiga" }, @@ -375,8 +365,7 @@ export const data = { "word": "algo" }, - { - }, + { "word": "alif" }, @@ -449,8 +438,7 @@ export const data = { "word": "amex" }, - { - }, + { "word": "amir" }, @@ -613,8 +601,7 @@ export const data = { "word": "aria" }, - { - }, + { "word": "aril" }, @@ -764,8 +751,7 @@ export const data = { "word": "aves" }, - { - }, + { "word": "avon" }, @@ -1130,10 +1116,7 @@ export const data = { "word": "bice" }, - { - }, - { - }, + { "word": "bier" }, @@ -2537,8 +2520,7 @@ export const data = { "word": "degu" }, - { - }, + { "word": "deil" }, @@ -2632,8 +2614,7 @@ export const data = { "word": "dfab" }, - { - }, + { "word": "dhol" }, @@ -2661,10 +2642,7 @@ export const data = { "word": "dick" }, - { - }, - { - }, + { "word": "diel" }, @@ -3646,8 +3624,7 @@ export const data = { "word": "-fic" }, - { - }, + { "word": "fief" }, @@ -4518,8 +4495,7 @@ export const data = { "word": "grey" }, - { - }, + { "word": "grig" }, @@ -4583,8 +4559,7 @@ export const data = { "word": "guff" }, - { - }, + { "word": "gulf" }, @@ -4877,8 +4852,7 @@ export const data = { "word": "hick" }, - { - }, + { "word": "high" }, @@ -6157,8 +6131,7 @@ export const data = { "word": "laic" }, - { - }, + { "word": "lain" }, @@ -6398,8 +6371,7 @@ export const data = { "word": "lick" }, - { - }, + { "word": "lied" }, @@ -7141,8 +7113,7 @@ export const data = { "word": "mego" }, - { - }, + { "word": "meil" }, @@ -7273,12 +7244,7 @@ export const data = { "word": "micr" }, - { - }, - { - }, - { - }, + { "word": "miee" }, @@ -7751,8 +7717,7 @@ export const data = { "word": "mugo" }, - { - }, + { "word": "muka" }, @@ -7917,8 +7882,7 @@ export const data = { "word": "naib" }, - { - }, + { "word": "naik" }, @@ -8145,10 +8109,6 @@ export const data = { "word": "nicu" }, - { - }, - { - }, { "word": "nife" }, @@ -8577,8 +8537,7 @@ export const data = { "word": "ohms" }, - { - }, + { "word": "oieo" }, @@ -8624,8 +8583,7 @@ export const data = { "word": "oleh" }, - { - }, + { "word": "olim" }, @@ -8717,8 +8675,7 @@ export const data = { "word": "oofy" }, - { - }, + { "word": "ooky" }, @@ -8927,8 +8884,7 @@ export const data = { "word": "ovi-" }, - { - }, + { "word": "ovra" }, @@ -9016,8 +8972,7 @@ export const data = { "word": "pahu" }, - { - }, + { "word": "paik" }, @@ -9406,8 +9361,7 @@ export const data = { "word": "pict" }, - { - }, + { "word": "pied" }, @@ -10101,8 +10055,7 @@ export const data = { "word": "quib" }, - { - }, + { "word": "quim" }, @@ -10181,8 +10134,7 @@ export const data = { "word": "ragu" }, - { - }, + { "word": "raik" }, @@ -10484,8 +10436,7 @@ export const data = { "word": "rfds" }, - { - }, + { "word": "rflp" }, @@ -10531,8 +10482,7 @@ export const data = { "word": "rics" }, - { - }, + { "word": "riel" }, @@ -10950,8 +10900,7 @@ export const data = { "word": "sahm" }, - { - }, + { "word": "sail" }, @@ -11090,8 +11039,7 @@ export const data = { "word": "sch." }, - { - }, + { "word": "scio" }, @@ -11475,8 +11423,7 @@ export const data = { "word": "skew" }, - { - }, + { "word": "skim" }, @@ -12460,10 +12407,7 @@ export const data = { "word": "tick" }, - { - }, - { - }, + { "word": "tied" }, @@ -12951,7 +12895,6 @@ export const data = { "word": "umbo" }, - { "word": "umma" }, @@ -13204,8 +13147,6 @@ export const data = { "word": "vice" }, - { - }, { "word": "view" }, @@ -13269,8 +13210,6 @@ export const data = { "word": "vlsi" }, - { - }, { "word": "voip" }, @@ -13442,7 +13381,6 @@ export const data = { "word": "wazz" }, - { "word": "weak" }, @@ -13593,8 +13531,6 @@ export const data = { "word": "wick" }, - { - }, { "word": "wien" }, @@ -13932,8 +13868,6 @@ export const data = { "word": "ylem" }, - { - }, { "word": "ymca" }, diff --git a/src/helpers/puzzleSolver.js b/src/helpers/puzzleSolver.js new file mode 100644 index 0000000..8d19c09 --- /dev/null +++ b/src/helpers/puzzleSolver.js @@ -0,0 +1,42 @@ +export const puzzleSolver = (x, y, d) => { + // so we have the first word, the second word, and all the data. + console.log(x, y); + // first we have x. we need to split, and replace one of the letters and join to + // form a new word (b) and make sure that data.includes(b). + + // our array of words which are split. + const data = d.results.map(x => x.word.split('')); + + + // swapLetter(x, data); + +}; + +// function swapLetter(x, data) {} + + + + +// // our argument is 'head', and we want to recognize 'hear'. + +// const data = [['a','r','e','s'], ['h','e','a','r'], ['x','x','v','v']]; + +// function hasThreeOf(w, i) { +// return w.filter(x => x !== i).length === 3 ? true : false; +// } + +// function swapLetter(x) { +// const word = x.split(''); +// const pool = data.filter(arr => { +// return arr.some(z => hasThreeOf(word, z)); +// }) +// return pool +// // now we have a pool of words that contain atleast some of the letters of word. +// // we need to find the words that have at least 3 of word letters. +// } +// swapLetter('head'); + + + + + From 676095d060fb2d2481f096bef4d024d4694f25fb Mon Sep 17 00:00:00 2001 From: ralph kemp Date: Fri, 18 Jan 2019 22:50:27 +0000 Subject: [PATCH 2/4] added in possible solution i guess --- src/helpers/puzzleSolver.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/helpers/puzzleSolver.js b/src/helpers/puzzleSolver.js index 8d19c09..2d6583a 100644 --- a/src/helpers/puzzleSolver.js +++ b/src/helpers/puzzleSolver.js @@ -40,3 +40,17 @@ export const puzzleSolver = (x, y, d) => { + + +// our argument is 'head', and we want to recognize 'hear'. + +// const data = [['a','r','e','s'], ['h','e','a','r'], ['x','x','v','v'], ['h','x','v','v']]; + +// function swapLetter(x) { +// const word = x.split(''); +// const pool = data.filter(arr => { +// console.log(arr.filter(z => word.filter(l => l !== z).length === 3)); +// }) +// return pool +// } +// swapLetter('head'); From be1dc5fe97e3f399f1607f13416e7d3c3c29599f Mon Sep 17 00:00:00 2001 From: ralph kemp Date: Sat, 2 Feb 2019 14:47:22 +0000 Subject: [PATCH 3/4] got first step of basic logic working, we now have a pool of words that contain at least 3 of the same letters. created compareArrs function to do this. --- src/helpers/puzzleSolver.js | 55 ++++++++++--------------------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/src/helpers/puzzleSolver.js b/src/helpers/puzzleSolver.js index 2d6583a..4a7a8ad 100644 --- a/src/helpers/puzzleSolver.js +++ b/src/helpers/puzzleSolver.js @@ -1,56 +1,29 @@ export const puzzleSolver = (x, y, d) => { // so we have the first word, the second word, and all the data. - console.log(x, y); // first we have x. we need to split, and replace one of the letters and join to // form a new word (b) and make sure that data.includes(b). - // our array of words which are split. const data = d.results.map(x => x.word.split('')); - - // swapLetter(x, data); - + return swapLetter(x, data); }; -// function swapLetter(x, data) {} - - - - -// // our argument is 'head', and we want to recognize 'hear'. - -// const data = [['a','r','e','s'], ['h','e','a','r'], ['x','x','v','v']]; - -// function hasThreeOf(w, i) { -// return w.filter(x => x !== i).length === 3 ? true : false; -// } - -// function swapLetter(x) { -// const word = x.split(''); -// const pool = data.filter(arr => { -// return arr.some(z => hasThreeOf(word, z)); -// }) -// return pool -// // now we have a pool of words that contain atleast some of the letters of word. -// // we need to find the words that have at least 3 of word letters. -// } -// swapLetter('head'); - - - +function swapLetter(firstWord, data) { + const word = firstWord.split(''); + const pool = data.filter(wordArr => { + return wordArr === compareArrs(word, wordArr); + }) + const finalPool = pool.map(arr => arr.join('')); + console.log(finalPool); +} +// does word have 3 letters that appear in data word? if so, return dataword. +function compareArrs(x, y) { + const arr = x.filter(letter => y.includes(letter)); + return arr.length === 3 ? y : null +} -// our argument is 'head', and we want to recognize 'hear'. -// const data = [['a','r','e','s'], ['h','e','a','r'], ['x','x','v','v'], ['h','x','v','v']]; -// function swapLetter(x) { -// const word = x.split(''); -// const pool = data.filter(arr => { -// console.log(arr.filter(z => word.filter(l => l !== z).length === 3)); -// }) -// return pool -// } -// swapLetter('head'); From 3455b27bfb268f550b237274e3d402a34d5d2008 Mon Sep 17 00:00:00 2001 From: ralph kemp Date: Sat, 2 Feb 2019 15:21:41 +0000 Subject: [PATCH 4/4] made a few changes, written out what i need to do next. --- src/components/Homepage.js | 2 +- src/components/Inputs.js | 8 ++++---- src/components/Results.js | 12 +++++++----- src/helpers/puzzleSolver.js | 22 +++++++++++----------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/components/Homepage.js b/src/components/Homepage.js index 412b8c0..865fe02 100644 --- a/src/components/Homepage.js +++ b/src/components/Homepage.js @@ -14,7 +14,7 @@ const MainDiv = styled.div` const Homepage = () => { return ( - + diff --git a/src/components/Inputs.js b/src/components/Inputs.js index 46635d1..7b38604 100644 --- a/src/components/Inputs.js +++ b/src/components/Inputs.js @@ -1,6 +1,6 @@ -import React from 'react'; -import Search from './Search'; -import styled from 'styled-components'; +import React from "react"; +import Search from "./Search"; +import styled from "styled-components"; const MainInputsDiv = styled.div` height: 100vh; @@ -23,6 +23,6 @@ const Inputs = () => { ); -} +}; export default Inputs; diff --git a/src/components/Results.js b/src/components/Results.js index 7713855..a7d6bfa 100644 --- a/src/components/Results.js +++ b/src/components/Results.js @@ -1,12 +1,11 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import styled from "styled-components"; -import { data } from '../data/words'; -import { puzzleSolver } from '../helpers/puzzleSolver'; -// import uuidv1 from "uuid/v1"; +import { data } from "../data/words"; +import { puzzleSolver } from "../helpers/puzzleSolver"; const MainResultsDiv = styled.div` - height: 100vh; + min-height: 100vh; width: 50vw; background-color: blue; color: white; @@ -31,13 +30,16 @@ class Results extends Component { render() { return ( + currently we're trying to go from COSY to RINK. {this.props.words ? (
{puzzleSolver( this.props.words.firstWord, this.props.words.secondWord, data - )} + ).map(x => { + return
{x}
; + })}
) : null}
diff --git a/src/helpers/puzzleSolver.js b/src/helpers/puzzleSolver.js index 4a7a8ad..7f9a55a 100644 --- a/src/helpers/puzzleSolver.js +++ b/src/helpers/puzzleSolver.js @@ -3,27 +3,27 @@ export const puzzleSolver = (x, y, d) => { // first we have x. we need to split, and replace one of the letters and join to // form a new word (b) and make sure that data.includes(b). // our array of words which are split. - const data = d.results.map(x => x.word.split('')); + const data = d.results.map(x => x.word.split("")); return swapLetter(x, data); }; - function swapLetter(firstWord, data) { - const word = firstWord.split(''); + const word = firstWord.split(""); const pool = data.filter(wordArr => { return wordArr === compareArrs(word, wordArr); - }) - const finalPool = pool.map(arr => arr.join('')); - console.log(finalPool); + }); + const firstPool = pool.map(arr => arr.join("")); + + // getting a pool of words that contain at least 3 letters of the word that's been inputted (x); + console.log(firstPool); + return firstPool; + // now from this pool we need to check that the position of three letters that DO appear in + // that word are in the same place. } // does word have 3 letters that appear in data word? if so, return dataword. - function compareArrs(x, y) { const arr = x.filter(letter => y.includes(letter)); - return arr.length === 3 ? y : null + return arr.length === 3 ? y : null; } - - -