## combinatorics – Climbing/Descending the Integer Ladder

A fun combinatoric puzzle that’s popped up in my work that I think would be cute to have a Mathematica solution to, if anyone wants to give it a go. It’s basically a ladder climbing/descending problem so probably has a nice `Graph` solution.

Starting at $$0$$, over $$k$$ steps of $$pm1$$, what are the paths that will land on the integer $$n$$, assuming of course that $$k ge n$$.

I don’t mind if this question gets closed for lack of effort on my part (I’m currently working out an analytic solution) and would actually be very happy if this were closed as a duplicate/if someone could point me to the proper name for this problem. But I thought Mathematica.SE might enjoy a quick, easy problem to break the “solve my integro-differential equation for me” drudgery.

## c++ – LeetCode 126: Word Ladder II

I’m posting my code for a LeetCode problem copied here. If you would like to review, please do so. Thank you for your time!

### Problem

Given two words (`begin` and `end`), and a dictionary’s word list,
find all shortest transformation sequence(s) from `begin` to `end`,
such that:

Only one letter can be changed at a time.

Each transformed word must exist in the word list. Note that `begin`
is not a transformed word. Note:

• Return an empty list if there is no such transformation sequence.
• All words have the same length.
• All words contain only lowercase alphabetic characters.
• You may assume no duplicates in the word list.
• You may assume `begin` and `end` are non-empty and are not the same.

### Inputs

``````"hit"
"cog"
("hot","dot","dog","lot","log","cog")
"hit"
"cog"
("hot","dot","dog","lot","log")
``````

### Outputs

``````(("hit","hot","dot","dog","cog"),("hit","hot","lot","log","cog"))
()
``````

### Code

``````#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

struct Solution {
const std::string begin,
const std::string end,
const std::vector<std::string> &words
) {
std::unordered_set<std::string> dict_words(words.begin(), words.end());

if (dict_words.find(end) == dict_words.end()) {
return {};
}

graph graph;
std::vector<std::vector<std::string>> paths;
std::vector<std::string> path = {begin};

if (make_graph(graph, begin, end, dict_words)) {
find_paths(graph, begin, end, path, paths);
}

return paths;
}

private:

typedef unordered_map<std::string, std::vector<std::string>> graph;

const inline bool make_graph(
graph &graph,
const std::string begin,
const std::string end,
std::unordered_set<std::string> &dict_words
) {
std::unordered_set<std::string> candidate_words;
candidate_words.insert(begin);

while (!candidate_words.empty()) {
if (candidate_words.find(end) != candidate_words.end()) {
return true;
}

for (std::string word : candidate_words) {
dict_words.erase(word);
}

std::unordered_set<std::string> curr_word;

for (std::string word : candidate_words) {
std::string parent = word;

for (int chari = 0; chari < word.size(); chari++) {
char character = word(chari);

for (int letter = 0; letter < 26; letter++) {
word(chari) = 'a' + letter;

if (dict_words.find(word) != dict_words.end()) {
curr_word.insert(word);
graph(parent).push_back(word);
}
}

word(chari) = character;
}
}

std::swap(candidate_words, curr_word);
}

return false;
}

static const inline void find_paths(
graph &graph,
const std::string begin,
const std::string end,
std::vector<std::string> &path,
std::vector<std::vector<std::string>> &paths
) {
if (begin == end) {
paths.push_back(path);

} else {
for (std::string child : graph(begin)) {
path.push_back(child);
find_paths(graph, child, end, path, paths);
path.pop_back();
}
}
}
};

``````

## unity – Unity3D: Create scripts to climb a ladder

I’m inexperienced and I’m trying to understand the mechanism for using a ladder with my character or climbing over small walls.
To move I use a rigidbody not kinematic, but with AddForce. I tried to create an object to simulate a ladder to climb on.
To get my caracter into contact with the ladder I inserted a collider trigger on the ladder and called the OnTriggerStay function.
After working a bit, my character now with a bool when he’s close enough, he can go up or down the ladder but I don’t understand something things.
First of all, the script is better to put it on the character or create one on the scale?
The second thing is once you get to the top how to insert a function correctly and make my character complete the climb, making it arrive above the object where the staircase is located.
Do I have to get to the top, destroy the game object and respawn at a point just above the ladder? … what is the best way in these cases?

``````private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}

void Update()
{
directionRot = new Vector3(0, 0, 0);  //direction of rotation
movement = new Vector3(0, Input.GetAxisRaw("Vertical"), 0).normalized; //object movement
rb.useGravity = false;}
else rb.useGravity = true;
}

void OnTriggerStay(Collider collider){

void OnTriggerExit(Collider collider){
``````

## dnd 5e – Can undead creatures (created by a necromancy spell) climb a rope, climb a ladder, or swim?

Would undead from that Animate the undead Spells (or any necromancer spells), e.g. Skeletons or zombies, be able to climb a rope, climb a ladder or swim?

I feel like they could climb a ladder, the rope is a little doubtful and swimming would be a no.

Nevertheless, I have not found any restrictions or parameters in the PHB or DMG that mention these rules.

Any help would be appreciated, thanks!

## real numbers – does anyone have a ladder in the form of learning material that I can use?

I want to learn math this year
I can do simple multiplications, additions, subtractions, and divisions, but I struggle with larger numbers.

But generally I have no math skills, all I know is that I want to start with the basics and work my way up. I am already an adult and I feel like someone who loves programming and is interested in electronics. I really need a strong foundation and understanding of math.

Can someone help me with some learning books to learn? I am not really embarrassed to start over as long as there is a ladder that I can climb on with the learning material.

I started with a book called "The Joy of X: A Tour of Mathematics" and although it is interesting, I assume that I already understand certain things.

I am excited to see that there is a 1000-page book that includes lessons and exercises, and good material that can be used to introduce and produce an expert from the perspective of an individual who has never done math before.

Thank you for any help.

## Performance – Word Ladder Solver in Python 3

Follow up to the Python program to find a word processor that converts "four" to "five"

I'm trying to write a program to solve a word ladder puzzle that I can use to refresh Python. For those who do not know:

A word leader puzzle begins with two words, and to solve the puzzle, a chain of other words must be found to connect the two. Two adjacent words (ie words in consecutive steps) are differentiated by one letter. – Wikipedia

I have implemented Width first search in contrast to Depth first search for a big performance boost since my last question, as suggested in the answers.
I've also added a new mode where letters can be added and removed and easily exchanged.
In addition, the program now accepts user input and may require more than two words to join (specified) `a b c`, it runs `a b`and then run `b c`).

The program now needs ~ 6 seconds on my computer to run with input from `five four` and `1`, I'm still interested in making this faster, and I also want to know how to make it more pythonic.

``````# -------- Data Structures --------
Queue ():
FIFO queue
def __init __ (self, parent = None):
self.list = []
self.parent = parent
def append (self, value):
self.list.append (value)
def pop (self):
return self.list.pop (0)

Class node ():
Node of a tree
def __init __ (self, value, parent = None):
self.value = value
self.parent = parent

# -------- Distance Functions --------
def Hamming (S1, S2):
Return sum (ch1! = Ch2 for ch1, ch2 in zip (s1, s2))

Def levenshtein (s1, s2):
if len (s1) <len (s2):
Return levenshtein (s2, s1)
if len (s2) == 0:
return len (s1)
previous_row = range (len (s2) + 1)
for i, c1 in list (s1):
current_row = [i + 1]
for j, c2 in enumerate (s2):
Inserts = previous_line[j + 1] + 1
deletions = current_row[j] + 1
Substitutions = previous_line[j] + (c1! = c2)
current_row.append (min (insertions, deletions, substitutions))
Previous_line = Current_line
return previous_row[-1]

# -------- IO --------

# Print the sequence from the root to the node
def print_words (node):
Values ​​= []
while isinstance (node, node):
values.append (node.value)
node = node.parent
print (list (vice versa (values)))

# Get all inputs
all_words = open ("/ usr / share / dict / words", "r"). read (). lower (). splitlines ()
input_words = input ("Enter a space-separated word list:") .split ()
input_mode = int (input ("Enter 1 for swap-only mode or 2 for swap-add-rem mode:"))

# Validate user input
if not 1 <= input_mode <= 2:
raise ValueError("Invalid mode: " + input_mode)

for word in input_words:
if word not in all_words:
raise ValueError("Invalid word: " + word)

distance = [hamming, levenshtein][input_mode - 1]
if input_mode == 1:
all_words = [word for word in all_words if len(word) == len(input_words[0])]

# -------- Breadth First Search --------
def fill(node, to_check, checked):
for word in all_words:
if 1 >len (word) len (node.value)> = -1 and distance (word, node.value) == 1:
to_check.append (node ​​(word, node))

for i in range (len (input_words) - 1):
root = Node (input_words[i])
checked = set ()
to_check = queue ()

fill (root, to_check, checked)
during to_check.list:
node = to_check.pop ()
if node.value == input words[i + 1]:
print_words (nodes)
break
If node.value is not enabled:
fill (node, to_check, checked)
``````

## python – Shortest Path on a Snake and Ladder Tablet (Update)

Previously, I had published a rather inefficient recursive solution to the problem of getting the fewest number of moves through a snake and ladder panel.

I have found a much faster solution with the Dijkstra algorithm and believe that it is correct.

Each box on the board is linked to a box between 1 and 6 that is larger than the box with a weight of 1 (equal to a roll of 1 to 6 on a die). All snakes and ladders connect squares weighing 1. The goal was to get the lowest total cost of the path between 1 and 100 (here 0 and 99, since I used list indexes).

This is the first time I implement the Dijkstra algorithm and the first time I use it `namedtuples`, I'm not sure if using namedtuples was appropriate, but it made it clearer in my mind.

I think I have massively overly complicated code parts, especially within the `to the` Loop under the condition `if edge.start == next_item:`, I seem to use much too much list comprehension, and I know the solution will be slower than it could be. Could someone help me find better ways to access the variables in my queue of named tuples?

``````"" Calculate the shortest way across a snake and ladder tableau with Dijkstra's shortest path. ""
from collections import namedtuple

Edge = namedtuple ("Edge", ("Start", "End", "Cost"))
Stack = namedtuple ("stack", ("start", "pathcost", "totalcost")

Class graph:
Class generates graph and calculates shortest path
def __init __ (self, edges):
"" Generate edges in the graph ""
self.edges = [Edge(*edge) for edge in edges]

def dijkstra_path (self, start, end):
Function that calculates the shortest path
if start> = end or start < 0 or end > 99:
Return -1
Queue = sorted (
(
Stack (edge.end, edge.cost, edge.cost)
for edge in self.edges
if edge.start == start
)
Key = lambda x: x[2].
)
during the queue:
next_item, _, current_total = queue.pop (0)
if next_item == end:
Return current_total
for edge in self.edges:
if edge.start == next_item:
if edge.end in [item.start for item in queue]:
current_cost = [
item.totalcost for item in queue if item.start == edge.end
][0]

if not current_cost <edge.cost + current_total:
Queue = [item for item in queue if item.start != edge.end]
queue.append (
Stack (edge.end, edge.cost, edge.cost + current_total)
)
otherwise:
queue.append (
Stack (edge.end, edge.cost, edge.cost + current_total)
)
Queue = sorted (queue, key = lambda x: x[2])

def build_graph ():
chessboard
list_board = [[i, i + j, 1] for i in the range (100) for j in the range (1, 7)]# Ladders
list_board.append ([1, 37, 1])
list_board.append ([19, 59, 1])
list_board.append ([28, 63, 1])
list_board.append ([55, 99, 1])
# Snakes
list_board.append ([91, 13, 1])
list_board.append ([86, 11, 1])
list_board.append ([53, 2, 1])
list_board.append ([41, 13, 1])
return list_board

if __name__ == "__main__":
GRAPH = graph (build_graph ())
FROM = 0
TO = 100
NUMBER_STEPS = GRAPH.dijkstra_path (FROM, TO)
if not NUMBER_STEPS == -1:
print (f "Can finish the game in at least {NUMBER_STEPS} dice")
otherwise:
print ("Error, make sure the starting point is between 0 and 99 and less than the endpoint",
"what must be the same or equal to 99")

``````

## Python program for finding a word ladder that converts "four" to "five"

I've seen this puzzle problem and thought I was trying to write a Python program to solve it. The task is to convert "four" to "five" and form a new four-letter word with each step, replacing one letter in as few steps as possible with each step.

However, it turns out that I do not know how to optimize the recursion. That's why I'm going to ask for help here. I'm mostly just confused why the code is changing that `past` must be at the forefront of the function, but I also like advice on how this can be accelerated in general. At the moment it takes about 10x as long for each step `maximum depth` goes to my computer

There will be no matches until you change `maximum depth` – I did not want someone to copy and stay behind. According to Puzzling, there should be a solution in depth 5. However, mine is mine `words` File does not have the `Loud` or the word `Fous`that uses this answer. Toasting `maximum depth` My computer lasts six minutes ~ 10 minutes, which I do not 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_tiefe = 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 = []):
# For some reason, be the first to be fast
Past = past[:]
past.append (current_word)

if len (past)> max_depth:
sequence.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 when end_word in sequence]if len (sequence) == 0:
print ("No matches")
otherwise:
print (min (sequences, key = len))

``````

## When does the ladder of an elliptic modular curve correspond to its level?

Let's assume the usual modular curve $$E = X_0 (N)$$ over $$mathbb {Q}$$ has the genus 1 (e.g. $$N = 15$$). Define the conductor of $$E / mathbb {Q}$$ as ideal / integer:

$$M = prod_ {p} p ^ {f (E / mathbb {Q} _p)},$$

from where

$$f (E / mathbb {Q} _p) = begin {cases} 0 & E text {has a good reduction mode} p \ 1 & E text {has a multiplicative reduction mode} p \ 2 & E text {has an additive reduction mode} p end {cases}$$

is the "exponent of the conductor of $$E / mathbb {Q} _p$$"(See, for example, Silverman's Advanced Topics in the Arithmetic of Elliptic Curves, Chapter IV, Section 10) $$p = 2.3$$ the exponent $$f (E / mathbb {Q} _p)$$ Depending on the wild branch, additional conditions may exist.

How do you prove that? $$N = M$$?

If $$E$$ If one had a Weierstrass equation, the proof would be straightforward since then $$f (E, mathbb {Q} _p)$$ is easy to calculate. You can also use the Ogg-Saito formula if you can calculate the Neron model from $$E / mathbb {Q} _p$$But this also requires a Weierstrass equation.

I know that the functional field of $$E / mathbb {C}$$ corresponds to $$mathbb {C} (j, j_N)$$ and that an algebraic relationship between $$j$$ and $$j_N$$ gives an equation for $$E$$but this polynomial is extremely impractical for calculations.

Is there a way to calculate a simple equation for? $$E / mathbb {Q}$$?