If player is not holding the ladder then it should not jump twice

I am using Unity2d and I am stuck with a problem. In my game I gave the player a double jump ability. I want to the player to jump twice only if they hold the ladder.

The problem is that if the player jumps through the ladder without holding the ladder, it jumps twice (as if the user presses jump key twice) I want the player to only double if player holding the ladder and then presses jump. If the player just jumps through the ladder it should not jump twice.

Below is the player script:

[SerializeField]  [SerializeField] float _xSpeed = 1f; [SerializeField] float _ySpeed = 1f; [SerializeField] float _jumpForce = 1f; [SerializeField] float _distance; [SerializeField] LayerMask _ladderLayer; private float _horizontalMovement; private float _verticalMovement; private Rigidbody2D _rb; private bool _isClimbing; private bool _isMovingHorizontal = true;    [SerializeField] Transform _groundPos; [SerializeField] float _checkRadius; [SerializeField] LayerMask _groundLayer; private bool _isGrounded;    // ExtraJump private int _extraJumps; [SerializeField] int _extraJumpValue = 1;   void Start() {     _rb = GetComponent<Rigidbody2D>();     _extraJumps = _extraJumpValue;  }   void Update() {     _horizontalMovement = Input.GetAxis("Horizontal");     _verticalMovement = Input.GetAxis("Vertical");        }   void FixedUpdate() {     if(_isMovingHorizontal)     {         _rb.velocity = new Vector2( _horizontalMovement * _xSpeed,_rb.velocity.y);     }            _isGrounded = Physics2D.OverlapCircle(_groundPos.position,_checkRadius,_groundLayer);       if(_isGrounded == true)     {         _extraJumps = _extraJumpValue;              }     if(Input.GetKeyDown(KeyCode.Space) && _extraJumps > 0)     {         _rb.velocity = new Vector2(_rb.velocity.x,_jumpForce);         _extraJumps --;              }     else if(Input.GetKeyDown(KeyCode.Space) && _extraJumps == 0 && _isGrounded == true)     {                  _rb.velocity = new Vector2(_rb.velocity.x,_jumpForce);     }       RaycastHit2D hitLadder = Physics2D.Raycast(transform.position,Vector2.up,_distance,_ladderLayer);      if(hitLadder.collider == true)      {         if(Input.GetKey(KeyCode.W))         {             _isClimbing = true;             _rb.gravityScale = 0;         }         else         if(Input.GetKey(KeyCode.Space))          {             _isClimbing = false;                              }            }                     if(_isClimbing == true && hitLadder.collider == true)     {                     _rb.velocity = new Vector2(_rb.velocity.x,_verticalMovement *          _ySpeed);              }     else     {         _rb.gravityScale = 1;     }       } 

Can undead creatures (raised by a necromancy spell) climb a rope, climb a ladder, or swim?

I’m thinking about making a Necromancy wizard, but had a few questions about RAW.

Would undead from the animate undead spell (or any necromancer spells), e.g. skeletons or zombies, be able to climb a rope, climb a ladder, or swim?

I feel like they would be able to climb a ladder, the rope is a little iffy, and swimming would be a no.

That said, I haven’t found any restrictions or parameters in the PHB or DMG that mention those rules.

Any help would be appreciated, thanks!

Can I use Two Immovable Rods as an infinite ladder or monkey bars?

There are already several questions concerning immovable rods, but I thought I’d add this to the list.

Consider a stealthy and inventive assassin. She’s on a mission to infiltrate the castle and kill a visiting duke. The assassin has to cross a wide moat and scale the castle wall, but for unspecified reasons she can’t use her normal tools.

Luckily, our intrepid antihero has gotten her hands on not one, but two immovable rods.

Can she fix one rod in place, hang from it one-handed, and fix the other rod ahead of her, repeating this process to create a set of monkey bars in order to cross the moat?

Once across, can she do a similar process, but vertically, in order to create a ladder?

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))  

Questions on Theon’s Ladder

Imagine we want to use Theon’s ladder to approximate $ \sqrt{3}$ . The appropriate expressions are $ $ x_n=x_{n-1}+y_{n-1}$ $

$ $ y_n=x_n+2x_{n-1}$ $

Rungs 6 through 10 in the approximation of $ \sqrt{3}$ are

$ \{\{208, 120\},\{568, 328\}, \{1552, 896\}, \{4240, 2448\}, \{11584, 6688\}\}$

a) Compute the two values in rung 11 of the ladder.

I’m assuming that all I need to do plug into the formula. So:

$ x_{11}=x_{10}+y_{10}$

$ x_{11}=6688+11584=18272$

$ y_{11}=x_{11}+2x_{10}$

$ y_{11}=18272+2(6688)=31648$

Is this correct?Part b is really what I am struggling with.

b) The figure below shows five rectangles whose dimensions correspond to rungs 6 through 10 above. That is, the lower left corner of each is at (0,0), while the upper right corners are at $ (208,120),(568, 328),…,(11584,6688)$ Are any of these rectangles similar to each other? Explain, briefly, your reasoning.

All I can think is that 6688 and 120 have a gcd of 8, and the gcd of 11584 and 208 is 16. Not really sure how to articulate that this helps with the similarity of the rectangles. Thanks for the help

enter image description here

Program for CodeHS 8.3.8: Word Ladder in Python 3

I have written an answer to this question on Stack Overflow. To make it easier for you I have copy-pasted the question below.

Your friend wants to try to make a word ladder! This is a list of words where each word has a one-letter difference from the word before it.

Here’s an example:

cat cot cog log 

Write a program to help your friend. It should do the following:

  • Ask your friend for an initial word.

  • Repeatedly ask them for an index and a letter.

  • You should replace the letter at the index they provided with the letter they enter.

  • You should then print the new word.

  • Stop asking for input when the user enters -1 for the index.

Here’s what should be happening behind the scenes:

  • You should have a function, get_index, that repeatedly asks the user for an index until they enter a valid integer that is within the acceptable range of indices for the initial string. (If they enter a number out of range, you should output invalid index).

  • You should have another function, get_letter, that repeatedly asks the user for a letter until they enter exactly one lowercase letter. (If they enter more than one character, you should output Must be exactly one character!. If they enter a capital letter, you should output Character must be a lowercase letter!).

  • You should store a list version of the current word in a variable. This is what you should update each time the user swaps out a new letter.

  • Each time you have to print the current word, print the string version of the list you are keeping in your variable.

My answer to this is:

import os get_index = 0 word = input("Enter a word: ") for i in range(len(word)):     while True:         try:             get_index = int(input("Enter an index (-1 to quit): "))             if get_index == -1:                 os._exit(0)             elif get_index < -1 or get_index > 2:                 raise ValueError         except ValueError:             print ("Invalid index!")         else:             while True:                 try:                         letter = input("Enter a letter: ")                     for c in letter:                         if c.isupper():                             raise ValueError                 except ValueError:                     print ("Character must be a lowercase letter!")                 else:                     if len(letter) > 1:                         print ("Must be exactly one character!")                     else:                         word = word[:get_index] + letter + word[get_index + 1:]                         print (word)                         break 

NOTE: Here is a link to the program run (output): OUTPUT

I would like to know whether I could make this code shorter and more efficient.

Any help would be highly appreciated.

Word ladder finding class

I have a class that I’m using to find the shortest word ladder between two words. Each “Step” in that ladder is returned as a String element in a LinkedList. If it can’t find one, it returns an empty LinkedList.

A step can only be formed from a word in the HashSet<String> dictionary variable.

I haven’t made anything like this before, and I’m posting here because I’d appreciate help making it run faster and advice regarding how to make the code itself more easily read by other humans.

public class WordLadder {  private HashSet<String> dictionary;  public WordLadder(HashSet<String> dictionary) {     this.dictionary = dictionary; }  /**  * This method finds the shortest word ladder between two words and returns  * it as a LinkedList of Strings.  *  * @return LinkedList of Strings.  */ @SuppressWarnings("unchecked") public LinkedList<String> findLadder(String input) {     // this method relies on deleting entries from a HashSet    HashSet<String> tempDict = (HashSet<String>) this.dictionary.clone();     // create LinkedLists     LinkedList<Integer> distances = new LinkedList<>();    LinkedList<LinkedList<String>> ladders = new LinkedList<>();    LinkedList<String> words = new LinkedList<>();     // split the input line into the starting and ending words    String startWord = input.substring(0, input.indexOf(" "));    String endWord = input.substring(input.indexOf(" ") + 1);     // holds the shortest ladder found    LinkedList<String> shortestLadder = new LinkedList<>();     words.add(startWord);    distances.add(1);     ladders.add(new LinkedList<>(Arrays.asList(startWord)));     while (!words.isEmpty()) {       Integer distance = distances.pop();       LinkedList<String> ladder = ladders.pop();       String word = words.pop();        // has the shortest ladder been found?       if (word.equals(endWord)) {             shortestLadder = ladder;       }        for (int i = 0; i < word.length(); i++) {           char[] currCharArr = word.toCharArray();           for (char c = 'A'; c <= 'Z'; c++) {             currCharArr[i] = c;             LinkedList<String> currentPathQueueTemp = new LinkedList<>(ladder);              String newWord = new String(currCharArr);              if (tempDict.contains(newWord)) {                words.add(newWord);                ladders.add(currentPathQueueTemp);                tempDict.remove(newWord);                distances.add(distance + 1);                currentPathQueueTemp.add(newWord);             }          }       }    }     return shortestLadder; }  } 

Advice on creating an efficient graph data structure for word ladder finding program?

I need to write a program that, given two strings, will find the shortest word ladder between them, or explain that a word ladder between them isn’t possible. It must utilize a graph-type data structure.

I have a text file of over 200,000 words of different lengths that could be used to form word ladders. I am new to graph data structures and I’m not sure how to create an efficient data structure for such a large amount of words of different lengths.

What sort of qualities would I want in the graph data structure I create?

Advice on developing a “word ladder” finding program

I am a college student studying Computer Science. For the final programming assignment of the course I’m enrolled in I have to make a java program that can find the shortest possible word ladder between two words. The assignment is very open-ended and I’m unsure how to tackle it, so I’d like advice on what approach I should take.

I understand that this is a relatively subjective question, but I hope it won’t be considered so subjective that the question should be closed.

It’s hard to explain what a “word ladder” is, so let me use an example. Here is a word ladder from DOG to CAT.

1: DOG

2: COG

3: COT

4: CAT

Each step from one to four is a real word, and only one letter is changed each time. I have been provided a text file that holds all the words that can be used in the program.

How should I approach this problem?