Skip to content

Instantly share code, notes, and snippets.

@jexp
Last active February 8, 2022 15:27
Show Gist options
  • Select an option

  • Save jexp/b1882301adb95a8015d6c29d3e24e341 to your computer and use it in GitHub Desktop.

Select an option

Save jexp/b1882301adb95a8015d6c29d3e24e341 to your computer and use it in GitHub Desktop.

Revisions

  1. jexp revised this gist Feb 2, 2022. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion _wordle.cypher
    Original file line number Diff line number Diff line change
    @@ -47,4 +47,17 @@ return w.name;
    ├────────┤
    "crash"
    └────────┘
    */
    */

    // more detailed with exclusions etc.

    match (c1:CharAtPos {idx:0, char:'c'}), // correct
    (c2:CharAtPos {idx:1, char:'a'}), // wrong pos
    (c3:CharAtPos {char:'l'}), // incorrect
    (c4:CharAtPos {char:'i'}), // incorrect
    (c5:CharAtPos {idx:4, char:'h'}), // correct
    (c:CharAtPos {char:'a'})
    match (w:Word)-[h1:HAS]->(c1),
    (w)-[h2:HAS]->(c5), (w)-[h3:HAS]->(c)
    WHERE not exists { (w)-[:HAS]->(c2) } and not exists { (w)-[:HAS]->(c3) } and not exists { (w)-[:HAS]->(c4) }
    return *;
  2. jexp revised this gist Feb 2, 2022. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions readme.adoc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    * explain two models
    * loading
    * post-processing
    * look at char frequencies
    * recommend starting words (based on top frequencies)
    * rarest words
    * solve word
    * visualize solver
    * implement wordle -> split input + match
  3. jexp revised this gist Feb 1, 2022. 1 changed file with 34 additions and 0 deletions.
    34 changes: 34 additions & 0 deletions _wordle2.cypher
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    // Alternative model
    // index in rel-type

    MATCH (w:Word)
    WITH w, split(w.name,"") AS chars
    MERGE (c0:Char {char:chars[0]})
    MERGE (w)-[:POS0]->(c0)
    MERGE (c1:Char {char:chars[1]})
    MERGE (w)-[:POS1]->(c1)
    MERGE (c2:Char {char:chars[2]})
    MERGE (w)-[:POS2]->(c2)
    MERGE (c3:Char {char:chars[3]})
    MERGE (w)-[:POS3]->(c3)
    MERGE (c4:Char {char:chars[4]})
    MERGE (w)-[:POS4]->(c4);


    MATCH p=(n:Word {name:"crash"})--(:Char) RETURN p LIMIT 25;

    MATCH (c:Char {char:'c'}),
    (h:Char {char:'h'}),
    (a:Char {char:'a'})
    MATCH (wordle:Word)-[:POS0]->(c),
    (wordle)-[:POS4]->(h),
    (wordle)-->(a)
    RETURN wordle.name;

    MATCH (c:Char {char:'c'}),
    (h:Char {char:'h'}),
    (a:Char {char:'a'})
    MATCH (wordle:Word)-[p0:POS0]->(c),
    (wordle)-[p4:POS4]->(h),
    (wordle)-[px]->(a)
    RETURN *;
  4. jexp revised this gist Feb 1, 2022. 1 changed file with 24 additions and 21 deletions.
    45 changes: 24 additions & 21 deletions _wordle.cypher
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,34 @@
    create constraint on (w:Word) assert w.name is unique;
    CREATE CONSTRAINT word_name IF NOT EXISTS ON (w:Word) ASSERT w.name IS UNIQUE;

    // create constraint on (c:CharAtPos) assert node key (idx, char);
    CREATE CONSTRAINT cap_idx_char IF NOT EXISTS FOR (cap:CharAtPos) REQUIRE (cap.idx, cap.char) IS NODE KEY;

    load csv from
    LOAD CSV FROM
    "https://gist.githubusercontent.com/jexp/b1882301adb95a8015d6c29d3e24e341/raw/6fe6ac31b9ed46900451e17b5215e9088ec09a6e/wordle.csv" as row
    merge (w:Word {name:row[0]});
    MERGE (w:Word {name:row[0]});

    match (w:Word)
    call { with w
    with w, split(w.name,"") as chars
    merge (start:CharAtPos {idx:0, char:chars[0]})
    merge (w)-[:STARTS]->(start)
    merge (w)-[:HAS]->(start)
    with *
    unwind range(1,size(chars)-1) as idx
    merge (next:CharAtPos {idx:idx, char:chars[idx]})
    merge (w)-[:HAS]->(next)
    with *
    match (prev:CharAtPos {idx:idx-1, char:chars[idx-1]})
    merge (prev)-[:NEXT]->(next)
    } in transactions of 1000 rows;
    :auto MATCH (w:Word)
    CALL { WITH w
    WITH w, split(w.name,"") AS chars
    MERGE (start:CharAtPos {idx:0, char:chars[0]})
    MERGE (w)-[:STARTS]->(start)
    MERGE (w)-[:HAS]->(start)
    WITH *
    UNWIND range(1,size(chars)-1) AS idx
    MERGE (next:CharAtPos {idx:idx, char:chars[idx]})
    MERGE (w)-[:HAS]->(next)
    WITH *
    MATCH (prev:CharAtPos {idx:idx-1, char:chars[idx-1]})
    MERGE (prev)-[:NEXT]->(next)
    } IN TRANSACTIONS OF 1000 ROWS;

    MATCH p=(n:Word {name:"crash"})--() RETURN p LIMIT 25;

    match (c1:CharAtPos {idx:0, char:'c'}), (c5:CharAtPos {idx:4, char:'h'})
    match (c:CharAtPos {char:'a'})
    match (w:Word)-[:HAS]->(c1),(w)-[:HAS]->(c5),(w)-[:HAS]->(c)
    MATCH (c1:CharAtPos {idx:0, char:'c'}),
    (c5:CharAtPos {idx:4, char:'h'}),
    (c:CharAtPos {char:'a'})
    match (w:Word)-[:HAS]->(c1),
    (w)-[:HAS]->(c5),
    (w)-[:HAS]->(c)
    return w.name;

    /*
  5. jexp revised this gist Feb 1, 2022. 1 changed file with 19 additions and 1 deletion.
    20 changes: 19 additions & 1 deletion _wordle.cypher
    Original file line number Diff line number Diff line change
    @@ -26,4 +26,22 @@ MATCH p=(n:Word {name:"crash"})--() RETURN p LIMIT 25;
    match (c1:CharAtPos {idx:0, char:'c'}), (c5:CharAtPos {idx:4, char:'h'})
    match (c:CharAtPos {char:'a'})
    match (w:Word)-[:HAS]->(c1),(w)-[:HAS]->(c5),(w)-[:HAS]->(c)
    return w.name
    return w.name;

    /*
    ╒════════╕
    "w.name"
    ╞════════╡
    "clach"
    ├────────┤
    "clash"
    ├────────┤
    "caneh"
    ├────────┤
    "coach"
    ├────────┤
    "catch"
    ├────────┤
    "crash"
    └────────┘
    */
  6. jexp revised this gist Feb 1, 2022. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion _wordle.cypher
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,9 @@ match (prev:CharAtPos {idx:idx-1, char:chars[idx-1]})
    merge (prev)-[:NEXT]->(next)
    } in transactions of 1000 rows;

    MATCH p=(n:Word {name:"crash"})--() RETURN p LIMIT 25;
    MATCH p=(n:Word {name:"crash"})--() RETURN p LIMIT 25;

    match (c1:CharAtPos {idx:0, char:'c'}), (c5:CharAtPos {idx:4, char:'h'})
    match (c:CharAtPos {char:'a'})
    match (w:Word)-[:HAS]->(c1),(w)-[:HAS]->(c5),(w)-[:HAS]->(c)
    return w.name
  7. jexp revised this gist Feb 1, 2022. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions _wordle.cypher
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    create constraint on (w:Word) assert w.name is unique;

    // create constraint on (c:CharAtPos) assert node key (idx, char);

    load csv from
    "https://gist.githubusercontent.com/jexp/b1882301adb95a8015d6c29d3e24e341/raw/6fe6ac31b9ed46900451e17b5215e9088ec09a6e/wordle.csv" as row
    merge (w:Word {name:row[0]});

    match (w:Word)
    call { with w
    with w, split(w.name,"") as chars
    merge (start:CharAtPos {idx:0, char:chars[0]})
    merge (w)-[:STARTS]->(start)
    merge (w)-[:HAS]->(start)
    with *
    unwind range(1,size(chars)-1) as idx
    merge (next:CharAtPos {idx:idx, char:chars[idx]})
    merge (w)-[:HAS]->(next)
    with *
    match (prev:CharAtPos {idx:idx-1, char:chars[idx-1]})
    merge (prev)-[:NEXT]->(next)
    } in transactions of 1000 rows;

    MATCH p=(n:Word {name:"crash"})--() RETURN p LIMIT 25;
  8. jexp created this gist Feb 1, 2022.
    12,972 changes: 12,972 additions & 0 deletions wordle.csv
    12,972 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.