Ubuntu only boots correctly one out of four times

I have a Lenovo W530 Thinkpad (with an nVidia k2000 GPU). I recently dual booted Windows 10 and Ubuntu 18.04.

Every time I restart I see the GRUB menu as expected. However, I am only able to boot into Ubuntu one out of about four times. The other 3/4 of the time it just freezes (very annoying).

After pressing enter on Ubuntu one of the following will happen:

  • It freezes on a purple screen (see picture) (this lasts indefinitely) enter image description here

  • It freezes with a cursor blinking very fast in the upper left corner (this lasts indefinitely, happens the most often and sometimes the screen backlight turns off and the cursor still blinks): enter image description here

  • Gibberish about a kernel panic is printed to the screen (this lasts indefinitely, happens least often): enter image description here

In all of these situations pressing ctl + alt + (f1-f12) does nothing.

Because I know nVidia drivers sometimes cause this, here is my graphics drivers setup: enter image description here

I have tried using boot-repair (this makes no difference) and I have tried reinstalling Ubuntu twice (this makes no difference).

Please help this is so annoying.

Thank you

Could I reapply UK visit visa after four times refusal?

I have been refused UK visit visa 4 times. First time is 2015 Jan, they refuse visa because I applied wrong visa type and second time is 2015 Dec they refused again due to my bank statement.

Third time May 2019, I am planning to go UK to attend my graduation but they refused again bank statement and economic social ties. And then I reapply again after 5days later, they refused again due to bank statement n they want to know originated fund as per photo.

Please advise me should I reapply again?

Thanks enter image description here

Why are four context sensitive grammar (CSG) rules needed to represent AB -> CD?

In Wikipedia of Kuroda normal form, it says

A straightforward technique attributed to György Révész transforms a grammar in Kuroda’s form to Chomsky’s CSG: AB → CD is replaced by four context-sensitive rules AB → AZ, AZ → WZ, WZ → WD and WD → CD.

Why are four rules needed here? Aren’t three rules: AB → AZ, AZ → BZ, BZ → BA enough?

A Connect Four evaluation function in Java is not smart enough

I have a couple of projects:

  1. GameAI
  2. ConnectFour

GameAI implements a couple of algorithms: Minimax, Alpha-beta pruning and Alpha-beta pruning with state ordering.

The actual game tree search algorithms seems to be in order, yet when I play against the bot connected to such an algorithm, it acts rather dumb. My best guess is that the problem lies in the evalutation function. Here is my code:´

net.coderodde.zerosum.ai.impl.AlphaBetaPruningGameEngine

package net.coderodde.zerosum.ai.impl;  import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import net.coderodde.zerosum.ai.EvaluatorFunction; import net.coderodde.zerosum.ai.GameEngine; import net.coderodde.zerosum.ai.State;  /**  * This class implements the   * <a href="https://en.wikipedia.org/wiki/Minimax">Minimax</a> algorithm for   * zero-sum two-player games.  *   * @param <S> the game state type.  * @param <P> the player color type.  * @author Rodion "rodde" Efremov  * @version 1.6 (May 26, 2019)  */ public final class AlphaBetaPruningGameEngine<S extends State<S>, P extends Enum<P>>          extends GameEngine<S, P> {      /**      * Stores the terminal node or a node at the depth zero with the best value      * so far, which belongs to the maximizing player moves.      */     private S bestTerminalMaximizingState;      /**      * Stores the value of {@code bestTerminalMaximizingState}.      */     private double bestTerminalMaximizingStateValue;      /**      * Stores the terminal node or a node at the depth zero with the best value      * so far, which belongs to the minimizing player moves.      */     private S bestTerminalMinimizingState;      /**      * Stores the value of {@code bestTerminalMinimizingState}.      */     private double bestTerminalMinimizingStateValue;      /**      * Indicates whether we are computing a next ply for the minimizing player       * or not. If not, we are computing a next ply for the maximizing player.      */     private boolean makingPlyForMinimizingPlayer;      /**      * Maps each visited state to its parent state.      */     private final Map<S, S> parents = new HashMap<>();      /**      * Constructs this minimax game engine.      * @param evaluatorFunction the evaluator function.      * @param depth the search depth.      */     public AlphaBetaPruningGameEngine(EvaluatorFunction<S> evaluatorFunction,                                       int depth) {         super(evaluatorFunction, depth, Integer.MAX_VALUE);     }      /**      * {@inheritDoc }      */     @Override     public S makePly(S state,                       P minimizingPlayer,                      P maximizingPlayer,                      P initialPlayer) {         // Reset the best known values:         bestTerminalMaximizingStateValue = Double.NEGATIVE_INFINITY;         bestTerminalMinimizingStateValue = Double.POSITIVE_INFINITY;         makingPlyForMinimizingPlayer = initialPlayer != minimizingPlayer;          // Do the game tree search:         makePlyImpl(state,                     depth,                     Double.NEGATIVE_INFINITY, // intial alpha                     Double.POSITIVE_INFINITY, // intial beta                     minimizingPlayer,                     maximizingPlayer,                     initialPlayer);          // Find the next game state starting from 'state':         S returnState =                 inferBestState(                         initialPlayer == minimizingPlayer ?                                  bestTerminalMinimizingState :                                  bestTerminalMaximizingState);          // Release the resources:         parents.clear();         bestTerminalMaximizingState = null;         bestTerminalMinimizingState = null;         // We are done with a single move:         return returnState;     }      private S inferBestState(S bestTerminalState) {         List<S> statePath = new ArrayList<>();         S state = bestTerminalState;          while (state != null) {             statePath.add(state);             state = parents.get(state);         }          if (statePath.size() == 1) {             // The root node is terminal. Return null:             return null;         }          // Return the second upmost state:         Collections.<S>reverse(statePath);         return statePath.get(1);     }      /**      * Performs a single step down the game tree branch.      *       * @param state the starting state.      * @param depth the maximum depth of the game tree.      * @param minimizingPlayer the minimizing player.      * @param maximizingPlayer the maximizing player.      * @param currentPlayer the current player.      * @return the value of the best ply.      */     private double makePlyImpl(S state,                                int depth,                                double alpha,                                double beta,                                P minimizingPlayer,                                P maximizingPlayer,                                P currentPlayer) {         if (depth == 0 || state.isTerminal()) {             double value = evaluatorFunction.evaluate(state);              if (!makingPlyForMinimizingPlayer) {                 if (bestTerminalMinimizingStateValue > value) {                     bestTerminalMinimizingStateValue = value;                     bestTerminalMinimizingState = state;                 }             } else {                 if (bestTerminalMaximizingStateValue < value) {                     bestTerminalMaximizingStateValue = value;                     bestTerminalMaximizingState = state;                 }             }              return value;         }          if (currentPlayer == maximizingPlayer) {             double value = Double.NEGATIVE_INFINITY;              for (S child : state.children()) {                 value = Math.max(                         value,                          makePlyImpl(child,                                      depth - 1,                                      alpha,                                     beta,                                     minimizingPlayer,                                      maximizingPlayer,                                      minimizingPlayer));                  parents.put(child, state);                 alpha = Math.max(alpha, value);                  if (alpha >= beta) {                     break;                 }             }              return value;         } else {             // Here, 'initialPlayer == minimizingPlayer'.             double value = Double.POSITIVE_INFINITY;              for (S child : state.children()) {                 value = Math.min(                         value,                         makePlyImpl(child,                                      depth - 1,                                     alpha,                                     beta,                                     minimizingPlayer,                                      maximizingPlayer,                                      maximizingPlayer));                  parents.put(child, state);                 beta = Math.min(beta, value);                  if (alpha >= beta) {                     break;                 }             }              return value;         }     } } 

net.coderodde.games.connect.four.impl.BruteForceConnectFourStateEvaluatorFunction

package net.coderodde.games.connect.four.impl;  import net.coderodde.games.connect.four.ConnectFourState; import net.coderodde.games.connect.four.PlayerColor; import net.coderodde.zerosum.ai.EvaluatorFunction;  /**  * This class implements the default Connect Four state evaluator. The white   * player wants to maximize, the red player wants to minimize.  *   * @author Rodion "rodde" Efremov  * @version 1.6 (May 24, 2019)  */ public final class BruteForceConnectFourStateEvaluatorFunction         implements EvaluatorFunction<ConnectFourState> {      private static final double NEGATIVE_WIN_VALUE = -1e6;     private static final double POSITIVE_WIN_VALUE = 1e6;     private static final double BASE_VALUE = 1e1;      /**      * The weight matrix. Maps each position to its weight. We need this in       * order to       */     private final double[][] weightMatrix;      /**      * The winning length.      */     private final int winningLength;      /**      * Constructs the default heuristic function for Connect Four game states.      *       * @param width the game board width.      * @param height the game board height.      * @param maxWeight the maximum weight in the weight matrix.      * @param winningPatternLength the winning pattern length.      */     public BruteForceConnectFourStateEvaluatorFunction(final int width,                                              final int height,                                              final double maxWeight,                                              final int winningPatternLength) {         this.weightMatrix = getWeightMatrix(width, height, maxWeight);         this.winningLength = winningPatternLength;     }      /**      * Evaluates the given input {@code state} and returns the estimate.      * @param state the state to estimate.      * @return the estimate.      */     @Override     public double evaluate(ConnectFourState state) {         // 'minimizingPatternCounts[i]' gives the number of patterns of          // length 'i':         int[] minnimizingPatternCounts = new int[state.getWinningLength() + 1];         int[] maximizingPatternCounts = new int[minnimizingPatternCounts.length];          // Do not consider patterns of length one!         for (int targetLength = 2;                  targetLength <= winningLength;                  targetLength++) {             int count = findRedPatternCount(state, targetLength);              if (count == 0) {                 // Once here, it is not possible to find patterns of larger                  // length than targetLength:                 break;             }              minnimizingPatternCounts[targetLength] = count;         }          for (int targetLength = 2;                 targetLength <= state.getWinningLength();                 targetLength++) {             int count = findWhitePatternCount(state, targetLength);              if (count == 0) {                 // Once here, it is not possible to find patterns of larger                 // length than targetLength:                 break;             }              maximizingPatternCounts[targetLength] = count;         }          double score = computeBaseScore(minnimizingPatternCounts,                                          maximizingPatternCounts);          return score + getWeights(weightMatrix, state);     }      /**      * Finds the number of red patterns of length {@code targetLength}.      * @param state the target state.      * @param targetLength the length of the pattern to find.      * @return the number of red patterns of length {@code targetLength}.      */     private static final int findRedPatternCount(ConnectFourState state,                                                  int targetLength) {         return findPatternCount(state,                                  targetLength,                                  PlayerColor.MINIMIZING_PLAYER);     }      /**      * Finds the number of white patterns of length {@code targetLength}.       * @param state the target state.      * @param targetLength the length of the pattern to find.      * @return the number of white patterns of length {@code targetLength}.      */     private static final int findWhitePatternCount(ConnectFourState state,                                                    int targetLength) {         return findPatternCount(state,                                 targetLength,                                  PlayerColor.MAXIMIZING_PLAYER);     }      /**      * Implements the target pattern counting function for both the player       * colors.      * @param state the state to search.      * @param targetLength the length of the patterns to count.      * @param playerColor the target player color.      * @return the number of patterns of length {@code targetLength} and color      * {@code playerColor}.      */     private static final int findPatternCount(ConnectFourState state,                                               int targetLength,                                               PlayerColor playerColor) {         int count = 0;          count += findHorizontalPatternCount(state,                                              targetLength,                                              playerColor);          count += findVerticalPatternCount(state,                                            targetLength,                                            playerColor);          count += findAscendingDiagonalPatternCount(state,                                                     targetLength,                                                    playerColor);          count += findDescendingDiagonalPatternCount(state,                                                      targetLength,                                                     playerColor);         return count;     }      /**      * Scans the input state for diagonal <b>descending</b> patterns and       * returns the number of such patterns.      * @param state the target state.      * @param patternLength the target pattern length.      * @param playerColor the target player color.      * @return the number of patterns.      */     private static final int          findDescendingDiagonalPatternCount(ConnectFourState state,                                            int patternLength,                                            PlayerColor playerColor) {         int patternCount = 0;          for (int y = 0; y < state.getWinningLength() - 1; y++) {             inner:             for (int x = 0;                     x <= state.getWidth() - state.getWinningLength();                      x++) {                 for (int i = 0; i < patternLength; i++) {                     if (state.readCell(x + i, y + i) != playerColor) {                         continue inner;                     }                 }                  patternCount++;             }         }          return patternCount;     }      /**      * Scans the input state for diagonal <b>ascending</b> patterns and returns      * the number of such patterns.      * @param state the target state.      * @param patternLength the target pattern length.      * @param playerColor the target player color.      * @return the number of patterns.      */     private static final int          findAscendingDiagonalPatternCount(ConnectFourState state,                                           int patternLength,                                           PlayerColor playerColor) {         int patternCount = 0;          for (int y = state.getHeight() - 1;                 y > state.getHeight() - state.getWinningLength();                 y--) {              inner:             for (int x = 0;                      x <= state.getWidth() - state.getWinningLength();                     x++) {                 for (int i = 0; i < patternLength; i++) {                     if (state.readCell(x + i, y - i) != playerColor) {                         continue inner;                     }                 }                  patternCount++;             }         }          return patternCount;     }       /**      * Scans the input state for diagonal <b>horizontal</b> patterns and returns      * the number of such patterns.      * @param state the target state.      * @param patternLength the target pattern length.      * @param playerColor the target player color.      * @return the number of patterns.      */     private static final int findHorizontalPatternCount(             ConnectFourState state,             int patternLength,             PlayerColor playerColor) {         int patternCount = 0;          for (int y = state.getHeight() - 1; y >= 0; y--) {              inner:             for (int x = 0; x <= state.getWidth() - patternLength; x++) {                 if (state.readCell(x, y) == null) {                     continue inner;                 }                  for (int i = 0; i < patternLength; i++) {                     if (state.readCell(x + i, y) != playerColor) {                         continue inner;                     }                 }                  patternCount++;             }         }          return patternCount;     }      /**      * Scans the input state for diagonal <b>vertical</b> patterns and returns      * the number of such patterns.      * @param state the target state.      * @param patternLength the target pattern length.      * @param playerColor the target player color.      * @return the number of patterns.      */     private static final int findVerticalPatternCount(ConnectFourState state,                                                       int patternLength,                                                       PlayerColor playerColor) {         int patternCount = 0;          outer:         for (int x = 0; x < state.getWidth(); x++) {             inner:             for (int y = state.getHeight() - 1;                     y > state.getHeight() - state.getWinningLength();                      y--) {                 if (state.readCell(x, y) == null) {                     continue outer;                 }                  for (int i = 0; i < patternLength; i++) {                     if (state.readCell(x, y - i) != playerColor) {                         continue inner;                     }                 }                  patternCount++;             }         }          return patternCount;     }      /**      * Gets the state weight. We use this in order to discourage the positions      * that are close to borders/far away from the center of the game board.      * @param weightMatrix the weighting matrix.      * @param state the state to weight.      * @return the state weight.      */     private static final double getWeights(final double[][] weightMatrix,                                            final ConnectFourState state) {         double score = 0.0;          outer:         for (int x = 0; x < state.getWidth(); x++) {             for (int y = state.getHeight() - 1; y >= 0; y--) {                 PlayerColor playerColor = state.readCell(x, y);                  if (playerColor == null) {                     continue outer;                 }                  if (playerColor == PlayerColor.MINIMIZING_PLAYER) {                     score -= weightMatrix[y][x];                 } else {                     score += weightMatrix[y][x];                 }             }         }          return score;     }      /**      * Computes the base scorer that relies on number of patterns. For example,      * {@code redPatternCounts[i]} will denote the number of patterns of length       * [@code i}.      * @param minimizingPatternCounts the pattern count map for red patterns.      * @param maximizingPatternCounts the pattern count map for white patterns.      * @return the base estimate.      */     private static final double computeBaseScore(             int[] minimizingPatternCounts,             int[] maximizingPatternCounts) {         final int winningLength = minimizingPatternCounts.length - 1;          double value = 0.0;          if (minimizingPatternCounts[winningLength] != 0) {             value = NEGATIVE_WIN_VALUE;         }          if (maximizingPatternCounts[winningLength] != 0) {             value = POSITIVE_WIN_VALUE;         }          for (int length = 2; length < minimizingPatternCounts.length; length++) {             int minimizingCount = minimizingPatternCounts[length];             value -= minimizingCount * Math.pow(BASE_VALUE, length);              int maximizingCount = maximizingPatternCounts[length];             value += maximizingCount * Math.pow(BASE_VALUE, length);         }          return value;     }      /**      * Computes the weight matrix. The closer the entry in the board is to the      * center of the board, the closer the weight of that position will be to      * {@code maxWeight}.      *       * @param width the width of the matrix.      * @param height the height of the matrix.      * @param maxWeight the maximum weight. The minimum weight will be always      * 1.0.      * @return the weight matrix.       */     private static final double[][] getWeightMatrix(final int width,                                                     final int height,                                                     final double maxWeight) {         final double[][] weightMatrix = new double[height][width];          for (int y = 0; y < weightMatrix.length; y++) {             for (int x = 0; x < weightMatrix[0].length; x++) {                 int left = x;                 int right = weightMatrix[0].length - x - 1;                 int top = y;                 int bottom = weightMatrix.length - y - 1;                 int horizontalDifference = Math.abs(left - right);                 int verticalDifference = Math.abs(top - bottom);                 weightMatrix[y][x] =                         1.0 + (maxWeight - 1.0) /                                (horizontalDifference + verticalDifference);             }         }          return weightMatrix;     } } 

Critique request

Any comments on my code?

Determining Sample Spaces for Sylvester’s Four Point Problem

I don’t have any background in geometric probability, so may I ask for forgiveness if the following is wrong or doesn’t make sense:

Assumptions:

  • no three sampled points are collinear
  • the (naive) geometric probability in euclidean space is equal to the ratio of lengths or areas
  • the probabilites do not change under isometric transformations and/or uniform scaling
  • the probability of a set $ P4:=\lbrace p_1,\ p_2,\ p_3,\ p_4\rbrace$ of four points being in convex configuration in the euclidean plane is independent of the order in which the elements are drawn by the sampling process; that in turn means that we assume that
  • $ \lbrace p_1,\ p_2,\ p_3\rbrace$ resembles the corners of $ T_{max}$ , the triangle of largest area
  • $ \lbrace p_1,\ p_2,\ p_3\rbrace$ have been drawn uniformly from the boundary of their circumcircle, which has implications on the probability of encountering $ T_{max}$ with specific values for the pair of smallest central angles.
  • the smallest circle enclosing $ P4$ is the unit circle centered at the origin
  • the longest side of $ T_{max}$ is bisected by the non-negative part of the x-axis

Under the above assumptions the probability of encountering a convex quadrilateral equals the blue area divided by the blue plus red area in the images below:

probability of 4 four points in convex configuration if the largest triangle is acute

the sampling area in case of acute $ T_{max}$ equals the entire unit disk

probability of four points in convex configuration if the largest triangle is obtuse

the sampling area in case of acute $ T_{max}$ equals the unit disk with a notch

The notch in the case of obtuse $ T_{max}$ is owed to the assumption that the first three points resemble $ T_{max}$ which implies that points outside $ T_{max}$ that generate a deltoid configuration would contradict the maximality of the area of $ T_{max}$

If the above makes sense, then the probability of four points being in convex configuration could be calculated by integrating over the ratios of the blue areas over the entire sampling area as defined by the $ T_{max}$ multiplied with the probability of $ T_{max}$ as a consequence of uniform sampling on the boundary of the unit circle.

Questions:

  • have similar ways of defining the sample spaces for Sylvester’s Four Point Problem already been described or investigated?
  • what are objections against the proposed against the proposed definition of the available sample space on basis of $ T_{max}$ ?

Remark:

in case of obtuse $ T_{max}$ the area of the sample space can be calculated on basis of angles $ \alpha$ and $ \beta$ that are adjacent to the longest side of $ T_{max}$ as follows, keeping in mind that that longest edge is the diameter of the unit circle:

  • the area of the lower blue half-disk equals $ \ \frac{\pi}{2}\ $
  • the area $ \ A_{\alpha}\ $ of the union of $ \ T_{max}\ $ with the blue region opposite to angle $ \ \alpha$ equals $ \ \alpha+\sin(\alpha)cos(\alpha)\ $ and analogous $ \ A_{\beta}\ $ for angle $ \ \beta\ $
  • the area of $ \ A_{T_{max}}\ $ of $ \ T_{max}\ $ equals $ \ \frac{1}{\cot(\alpha)+\cot(\beta)}\ $

The area of the sampling area for obtuse $ \ T_{max}\ $ then equals $ \ \frac{\pi}{2}+A_{\alpha}+A_{\beta}-A_{T_{max}}$

How can I make my js app run using one “on click event” instead of four?

I’m a few weeks into javascript and had to make a simple “crystals collector” app. The app works as intended, but the code is obtuse and repetitive.

I’d like to make the app work using just one on click event, rather than using four for each crystal. I can’t make an array of each color crystal and loop through them since the num variables change as well.

Sorry for such a rudimentary question, thanks for any advice.

Here is my code below:

$  (document).ready(function () {      // Global variables          var targetNumber;     var num1;     var num2;     var num3;     var num4;     var userTotal = 0;     var wins = 0;     var losses = 0      // Functions      function reset() {         num1 = Math.floor(Math.random() * 11 + 1);         num2 = Math.floor(Math.random() * 11 + 1);         num3 = Math.floor(Math.random() * 11 + 1);         num4 = Math.floor(Math.random() * 11 + 1);         targetNumber = Math.floor(Math.random() * 101 + 19);         userTotal = 0;         $  ("#total-score").text(userTotal);         $  ("#target-score").text(targetNumber);     }      function initialize() {         num1 = Math.floor(Math.random() * 11 + 1);         num2 = Math.floor(Math.random() * 11 + 1);         num3 = Math.floor(Math.random() * 11 + 1);         num4 = Math.floor(Math.random() * 11 + 1);         targetNumber = Math.floor(Math.random() * 101 + 19);         $  ("#target-score").text(targetNumber);         $  ("#wins").text(wins);         $  ("#losses").text(losses);         $  ("#total-score").text(userTotal);     }     function logic() {         if (userTotal === targetNumber) {             alert("You Win!");             reset();             wins++;             $  ("#wins").text(wins);         }         else if (userTotal > targetNumber) {             alert("You lose!");             reset();             losses++;             $  ("#losses").text(losses);         }     }      // Run Game (main)     // something like...     // var array = ["#blue","#green","#red","#yellow"]     // for (var i =0; i < array.length;i++) {     // }      initialize();      $  ("#blue").on("click", function () {         userTotal = userTotal + num1;         $  ("#total-score").text(userTotal);         console.log(userTotal);         logic();     })      $  ("#green").on("click", function () {         userTotal = userTotal + num2;         $  ("#total-score").text(userTotal);         console.log(userTotal);         logic();     })      $  ("#red").on("click", function () {         userTotal = userTotal + num3;         $  ("#total-score").text(userTotal);         console.log(userTotal);         logic();     })      $  ("#yellow").on("click", function () {         userTotal = userTotal + num4;         $  ("#total-score").text(userTotal);         console.log(userTotal);         logic();     })    });
.img {     width: 150px;     height: 150px; }  #crystal-main {     width: 650px;     border: 2px solid gray;     padding: 25px;     background: black;     color: whitesmoke; }
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta http-equiv="X-UA-Compatible" content="ie=edge">     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"         integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">     <link rel="stylesheet" href="assets/css/style.css">     <title>Crystal Game</title>     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>     <script src="assets/javascript/game.js"></script> </head>  <body>     <h1>Crystals Collector!</h1>     <hr>     <div class="container-fluid">         <div class="container" id="crystal-main">             <div class="row">                 <h2>Target Score: <span id="target-score"></span></h2>             </div>             <div class="row">                 <h2>Total Score: <span id="total-score"></span></h2>             </div>             <div class="row">                 <div class="col-3-md crystal">                     <img src="assets/images/blue.png" alt="blue" class="img" id="blue">                 </div>                 <div class="col-3-md crystal">                     <img src="assets/images/green.png" alt="green" class="img" id="green">                 </div>                 <div class="col-3-md crystal">                     <img src="assets/images/red.png" alt="red" class="img" id="red">                 </div>                 <div class="col-3-md crystal">                     <img src="assets/images/yellow.png" alt="yellow" class="img" id="yellow">                 </div>             </div>             <div class="row">                 <h4>Wins: <span id="wins"></span></h4>             </div>             <div class="row">                 <h4>Losses: <span id="losses"></span></h4>             </div>         </div>     </div>  </body> </html>

Python program to find a word ladder transforming “four” to “five”

I saw this Puzzling problem and thought I would try to write a Python program to solve it. The task is to transform “four” to “five”, forming a new four-letter word at each step, replacing one letter at each step, in as few steps as possible.

But turns out I don’t know how to optimize recursion, so I’m posting here for help. I’m mostly just confused on why the code to change the past needs to be at the top of the function, but I would also like advice on how to speed this up in general. Right now it takes about 10x as long for each step up max_depth gets on my computer.

There won’t be any matches until you change max_depth – I didn’t want anyone copy-pasting and lagging out. There should be a solution at depth 5, according to Puzzling. However, my words file doesn’t have the Foud or the word Fous, which that answer uses. Bumping up to max_depth six will take my computer ~10 minutes, which I don’t want to try yet.

def hamming(string1, string2):     assert len(string1) == len(string2)     return sum(char1 != char2 for char1, char2 in zip(string1, string2))  max_depth = 3 start_word = "five" end_word = "four" all_words = open("/usr/share/dict/words", "r").read().lower().splitlines() all_words = list(filter(lambda word: word.isalpha(), all_words)) all_words = list(filter(lambda word: len(word) == len(start_word), all_words))  sequences = []  def search(current_word, past = []):     # Needs to be first to be fast for some reason     past = past[:]     past.append(current_word)      if len(past) > max_depth:         sequences.append(past)         return      for word in all_words:         if hamming(word, current_word) == 1 and word not in past:             search(word, past)  search(start_word)  sequences = [sequence[:sequence.index(end_word) + 1] for sequence in sequences if end_word in sequence]  if len(sequences) == 0:     print("No matches") else:     print(min(sequences, key=len))  

Is there a limit to ki / damage for a Monk of the Four Elements’ Fist of Unbroken Air or Water Whip?

For the Monastic Tradition “Way of the Four Elements” in the D&D 5e Player’s Handbook, some Elemental Disciplines allow casting a spell. For these spell disciplines, additional ki points can be spent to cast the spell at a higher level than its minimum, but there are specified limits to “the maximum number of ki points you can spend to cast a spell in this way”.

But other Elemental Disciplines are not called spells and not implied in any way to be spells. Three of these Disciplines do provide a similar way of increasing the effects by spending more ki points. Fangs of the Fire Snake allows spending just one additional ki for a total of two. Both Fist of Unbroken Air and Water Whip say “plus an extra 1d10 bludgeoning damage for each additional ki point you spend”.

So is there a limit to how many ki points a Monk can spend on Fist of Unbroken Air or Water Whip, or how much extra damage they can do, other than the Monk’s total supply of ki points?

Just from reading my Player’s Handbook (First Printing August 2014 “includes corrections”), it looks like the answer is no, a Monk can always spend any amount of ki points they have available for these disciplines, since the only limits mentioned are for spell casting, and these disciplines are not spells. But this seems surprisingly inconsistent, and a rare potential for doing a huge amount of damage with one action. Has anything changed or clarified this otherwise, in later revisions, errata, or comments from the designers?

Handling dates with mix of two and four digit years in python

I have two DataFrame df:
    A                B
5/4/2018     8/4/2018
24/5/15       26/5/15
21/7/16       22/7/16
3/7/2015     5/7/2015
1/7/2016     1/7/2016

I want to calculate the difference of days for each row.
for example:
    A                B             C
5/4/2018     8/4/2018     3
24/5/15       26/5/15       2

I have tried to convert dataframe into datetime using pd.to_datetime. but, getting error “ValueError: unconverted data remains: 18”

import datetime as dt

df[‘A’] = pd.to_datetime(df[‘A’], format = “%d/%m/%y”).datetime.datetime.strftime(“%Y-%m-%d”) df[‘B’] = pd.to_datetime(df[‘B’], format = “%d/%m/%y”).datetime.datetime.strftime(“%Y-%m-%d”)

df[‘C’] = (df[‘B’] – df[‘A’]).dt.days

note :using python 3.7