about summary refs log tree commit diff stats
path: root/lib/Octans/WordSearch.rakumod
blob: a1ed2c393ba9236875b128ea1eb901a6b8277ded (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-lef
unit module Octans::WordSearch;

use Octans::Neighbors;
use Octans::RangeSearch;

# word-search walks the given grid & tries to find words in the
# dictionary. It walks in Depth-First manner (lookup Depth-First
# search).
sub word-search (
    # @dict holds the dictionary. @puzzle holds the puzzle.
    @dict, @puzzle,

    # $y, $x is the position of the current cell, we have to follow
    # this path. $str is the string we've looked up until now. If it's
    # not passed then assume that we're starting at $y, $x and take
    # @puzzle[$y][$x] as the string.
    #
    # $str should be passed in recursive calls, it's not required when
    # $y, $x is the starting position.
    Int $y, Int $x, $str? = @puzzle[$y][$x],

    # @visited holds the positions that we've already visited.
    @visited? is copy --> List
) is export {
    # If @visited was not passed then mark the given cell as visited
    # because it's the cell we're starting at.
    @visited[$y][$x] = True unless @visited;

    # neighbor block loops over the neighbors of $y, $x.
    neighbor: for neighbors(@puzzle, $y, $x).List -> $pos {
        # Move on to next neighbor if we've already visited this one.
        next neighbor if @visited[$pos[0]][$pos[1]];

        # Mark this cell as visited but only until we search this
        # path. When moving to next neighbor, mark it False.
        @visited[$pos[0]][$pos[1]] = True;

        # $word is the string that we're going to lookup in the
        # dictionary.
        my Str $word = $str ~ @puzzle[$pos[0]][$pos[1]];

        # range-starts-with returns a list of all words in the
        # dictionary that start with $word.
        with range-starts-with(@dict, $word) -> @list {
            if @list.elems > 0 {
                # If $word exist in the dictionary then it should be
                # the first element in the list.
                take @list[0], @visited if @list[0] eq $word;

                # Continue on this path because there are 1 or more
                # elements in @list which means we could find a word.
                word-search(
                    # Don't pass the whole dictionary for next search.
                    # Words that start with "ab" will always be a
                    # subset of words that start with "a", so keeping
                    # this in mind we pass the output of last
                    # range-starts-with (@list).
                    @list, @puzzle, $pos[0], $pos[1], $word, @visited
                );
            }
        }

        # We're done looking up this path, mark this cell as False &
        # move on to another neighbor.
        @visited[$pos[0]][$pos[1]] = False;
    }
}
and shelter. But one day, out of whatever reason you decided to stop supporting that person and remove them from the house back onto the street. You understanded that they will have a hard time finding foot, shelter and clothes. They deceased because of the cold. </p> <p> The poor person was life, and your decision did cause their decession. But is this murder? Man-slaughter? Any kind of statutory offense? No, not really, it's merely termination of voluntary support that you provided for another person. </p> <p> There is a subtle, but eventually significant difference between helping a person down the street and voluntary pregnency. (Involuntary pregnency is basically "alright, here comes a person at your doorstep, you MUST help them and keep them alive", there's not much to discuss there in my opinion.) </p> <p> In the last example, the ethicalness of terminating support would be different if you and the person receiving help signed an explicit contract giving you the responsibility to help them but you terminate the support when the contract is still valid. </p> <p> Indeed, the fetus did not sign a contract with the mother that obligates the mother to carry to term. But similarly, children don't sign contracts with their parents to take care of them, but we consider parents who don't take care of their children and such to be child abuse. But they are different. </p> <p> A scientific definition of life which includes bacteria, fungi, parasites, plants, animals and many other forms of life doesn't seem inherently valuable to us&mdash;almost all of us don't feel bad killing bacteria with an ultraviolet lamp, don't feel bad killing plants for consumption, and don't feel bad stepping on a mosquito. Many of us don't feel bad consuming animals for food. We value human life because it allows us to pursue what we want and live a life. But a fetus cannot do that: though the fetus is biologically a human, it doesn't have the very characteristics that make the life valuable: It doesn't have meaningful brain activity and cannot pursue what it wants. </p> <p> Abortion is just okay before the cerebrum (the part of the brain responsible for thinking) develops, which is usually at the end of the second trimester. Abortion after meaningful cerebrum activity is detected should be considered with care because at that time the fetus's life would be considered valuable. </p> </article> <footer> <ul role="list"> <li><a href="./">Home</a></li> <li>Runxi Yu</li> <li><a rel="license" href="./pubdom.html">Public Domain</a></li> </ul> </footer> </body> </html>