## How to ‘memoize’ this recursive solution?

I was doing this problem:

A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).  Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of moves exists to transform the point (sx, sy) to (tx, ty). Otherwise, return False.      Examples:     Input: sx = 1, sy = 1, tx = 3, ty = 5     Output: True     Explanation:     One series of moves that transforms the starting point to the target is:     (1, 1) -> (1, 2)     (1, 2) -> (3, 2)     (3, 2) -> (3, 5)      Input: sx = 1, sy = 1, tx = 2, ty = 2     Output: False      Input: sx = 1, sy = 1, tx = 1, ty = 1     Output: True      Note:      sx, sy, tx, ty will all be integers in the range [1, 10^9]. 

I know the solution where you split it up into the ty-tx case, or tx-ty case, and solve it recursively, but I was wondering if there is a DP solution to this. Here is my recursive solution:

public boolean reachingPoints(int sx, int sy, int tx, int ty) {     return help(sx,sy,tx,ty); }  public boolean help(int sx, int sy, int tx, int ty){     if(sx==tx && sy == ty){         return true;     }     if(sx>tx || sy>ty){         return false;     }     if(sx==tx){         if(ty-sy%sx==0){             return true;         }     }     if(ty==sy){         if(tx-sx%sy==0){             return true;         }     }     return(help(sx, sy, tx%ty, ty) || help(sx, sy+sx, tx, ty)); } 

How would I put this into an array? I have trouble in the memoization part of DP, and I cannot figure this one out.

Any help would greatly be appreciated.

Thank you!

## Can I execute code in this situation?

There is a code snippet like that in a php based web application.

<form action="home.php?parameter=<?php echo $_GET['parameter'] ?>" method="post">  Can I execute arbitrary code using get “parameter”? ## What is the run time of this algorithm, written in pseudocode? count = 0 for i = 1 to n: for j = 1 to i: count += 1  So from my understanding, we can break this up into 2 summations, by nesting the $$j$$ loop as a summation into the $$i$$ loop as a summation as follows: $$\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{i}$$1 Since incrementing count is 1 operation O(1). Then, we can manipulate the above summation to: = $$\sum\limits_{i=1}^{n} (i – 1 + 1)$$ using property of summations = $$\sum\limits_{i=1}^{n} i$$ = $$\frac{n(n+1)}{2}$$ = $$O(n^2)$$ Is this the correct approach? ## Why is my algorithm version so slow with this input? I’ve written my F# code to solve Advent of Code Day 18 Part 1. While it seems to work fine with other simple demo inputs, it stuck with the following input ################# #i.G..c...e..H.p# ########.######## #j.A..b...f..D.o# ########@######## #k.E..a...g..B.n# ########.######## #l.F..d...h..C.m# #################  Tehre is reference solution in Python which is correct and quick, but I fail to see where is the fundamental difference between the two algorithms, behind the other minor code differences (also because the languages are different). I’ve tried with concurrency vs a queue, with a tree vs a grid/map (see my github history) but with no luck until now. The principal part of the code is described below. It should fall under a breadth first search (BFS) algorithm. Here is how the single step by which I elaborate the solution. let next (step:Step) (i:int) (solution: Solution) (fullGrid: Map<char,Map<char,Grid>>) : Solution = let branches = solution.tree.branches let distance = solution.tree.distance + branches.[i].distance let area = branches.[i].area //let newbranches, back, keys = match step with | SpaceStep -> failwith "not expected with smart grid" | KeyStep -> let keys = area :: solution.keys let grid = fullGrid.[area] let tree = grid2tree area distance keys grid {keys=keys; tree=tree}  The fullGrid is supposed to contain the matrix of distances. The wrapping solver is simply a recursion or queue based version of the BFS. let findSolution (keynum:int) (solution: Solution) (fullGrid: Map<char,Map<char,Grid>>) : Solution option = let mutable solution_queue : queue<Solution> = MyQueue.empty solution_queue <- enqueue solution_queue solution let mutable mindistance : int option = None let mutable alternatives : Solution list = List.empty while (MyQueue.length solution_queue > 0) do let solution = dequeue &solution_queue let solution = {solution with tree = grid2tree solution.tree.area solution.tree.distance solution.keys fullGrid.[solution.tree.area]} let branches = solution.tree.branches if (branches = [||] ) then if solution.keys.Length = keynum then updateMin &mindistance &alternatives solution else match mindistance with | Some d when d < solution.tree.distance + (solution.tree.branches |> Array.map (fun t -> t.distance) |> Array.min) -> () | _ -> let indexes = [|0..branches.Length-1|] |> Array.sortBy(fun idx -> ((if isKey branches.[idx].area then 0 else 1) , branches.[idx].distance)) for i in indexes do if branches.[i].area = '#' then failwith "not expected with smart grid" else if branches.[i].area = Space then failwith "not expected with smart grid" else if (Char.IsLower branches.[i].area) then let solutionNext = next KeyStep i solution fullGrid if solutionNext.keys.Length = keynum then updateMin &mindistance &alternatives solutionNext else solution_queue <- enqueue solution_queue solutionNext else if (Char.IsUpper branches.[i].area) then failwith "not expected with smart grid" match alternatives with | [] -> None | alternatives -> alternatives |> List.minBy(fun a -> a.tree.distance) |> Some  ## Is this a misleading or undesirable implementation of a hash map? I read a C++ implementation of a hash map here. https://www.geeksforgeeks.org/implementing-hash-table-open-addressing-linear-probing-cpp/ Let’s say key k1 has a hash index of h. Suppose there’s a collision with key k2 such that hash(k1) == hash(k2). Then won’t the new hash index of k2 become h+1?  Key: k1 Index: h Key: k2 Index: h+1  Suppose we introduce a third key k3 such that hash(k3) == h+1. Then when we insert k3 into the hash map, its hash index will become h+2.  Key: k1 Hash value: h Hash table index: h Key: k2 Hash value: h Hash table index: h+1 Key: k3 Hash value: h+1 Hash table index: h+2  This can cause the hash indexes for keys to be shifted over 1 in the case of collisions (as seen above), and if collisions happen frequently then they could be shifted over more than once. Is this a bad implementation of a hash map? From an aesthetic point of view I prefer the linked approach, where each hash node has a pointer to a next node, such that if multiple nodes have the same hash index, they are all part of the same linked list starting at that hash index. In the linked approach, at least we have the assurance that a key will logically correspond to its hash index in the hash table, even if it’s part of a linked list (in which case it doesn’t physically correspond, but logically still does, since the head of the linked list is stored there). Is the implementation of the hash map in GeeksForGeeks bad? Is the linked approach more logical and intuitive? What are your thoughts? Note: The linked approach I refer to is simply to store a linked list at each hash index in the hash table, such that if multiple keys are hashed to that index, they are stored in this linked list. ## Is this jwt access and refresh tokens logic/structure secure? 1. User logs in 1. User gets a refresh_token assigned and stored in the database (long lived 7d) 2. Client receives an accestoken (Short lived, 2h), and stores it as a cookie. Client also receives the userId AES encrypted, and stores it as a cookie. 3. As far as the access token is not expired, the user keeps using the token to navigate the website 4. The token expires 5. The expired access token gets send to a refresh endpoint, so is the userID (Aes encrypted) both currently stored in out cookies. 6. The server decrypts the userId and retrieves the refreshtoken that corresponds to the user by selecting the refresh token from the database using out userId. 7. Now we have in the server our refreshtoken and accestoken, so we refresh the token, and send back the new accesstoken. We also generate a new refreshtoken and overwrite our old refreshtoken in the database with the new one. (I guess I need to somehow blacklist my old refreshtoken at this point) ## Can you help me crack this hash? i need help with this: for an exercise i need to crack this hash $ apr1$cy5UgTjB$ 1D.TuLHrP.Q5ZN7evMbRS1 I found with hash-identifier that it’s a MD5(APR) hash, -m 1600 in hashcat. So i runned:

hashcat -a 0 -m 1600 $apr1$  cy5UgTjB\$  1D.TuLHrP.Q5ZN7evMbRS1 /usr/share/wordlists/rockyou.txt --force 

But i get this error

Hash 'D.TuLHrP.Q5ZN7evMbRS1:asltey': Separator unmatched No hashes loaded. 

Do you know why? Thank you.

## Combining Game Effects and Combining Magical Effects, and how does this relate to damage types?

Combining Game Effects and Combining Magical Effects, and how does this relate to damage types?

Fire Bolts and Fireballs!

I have a question about how to interpret the sections on Combining Game Effects and Combining Magical Effects. I have used fire damage and piercing damage as examples.

Combining Game Effects:

Different game features can affect a target at the same time. But when two or more game features have the same name, only the effects of one of them —the most potent one— apply while the durations of the effects overlap. For example, if a target is ignited by a fire elemental’s Fire Form trait, the ongoing fire damage doesn’t increase if the burning target is subjected to that trait again. Game features include spells, class features, feats, racial traits, monster abilities, and magic items. (DMG p. 252)

Combining Magical Effects:

The effects of different spells add together while the durations of those spells overlap. The effects of the same spell cast multiple times don’t combine, however. Instead, the most potent effect—such as the highest bonus from those castings applies while their durations overlap. For example, if two clerics cast bless on the same target, that character gains the spell’s benefit only once; he or she doesn’t get to roll two bonus dice. (PHB p. 204)

To set the scene: Two Wizards, Pyro and Scorchee, enter a tavern, and they bump ito their arch-enemies, Rangers Legolad and Sir Pokealot – a fight ensues! They roll for initiative. L5 characters.

I’ve had to split it into two scenarios because each presents a nuance as to how to interpret “Combining Game Effects” and “Combining Magical Effects”.

Scenario 1: Both Wizards end up with the same initiative. When it comes to choose their actions: both of them cast Fire Bolt at Legolad and are successful in their ranged spell attacks. Does this mean that Legolad takes: two separate sets of damage of 2d10, or only one, because it is the same spell name?

Scenario 2: Both Wizards end up with the same initiative. One casts Fire Bolt at Sir Pokealot and hits; and the other casts Fireball (to the tavern keeper’s discontent), and he fails his saving throw. Does this mean that Sir Pokealot takes: 2d10 from the Fire Bolt and 8d6 from the Fireball; or only the damage from the spell that caused more damage, because it is the same damage type?

## Combining Game Effects and Combining Magical Effects – how does this relate to spells with multiple effects?

Combining Game Effects and Combining Magical Effects – how does this relate to spells with multiple effects?

Here is the information from the Dungeon Master’s Guide and the Player’s Handbook that relates to my question.

Combining Game Effects:

Different game features can affect a target at the same time. But when two or more game features have the same name, only the effects of one of them —the most potent one— apply while the durations of the effects overlap. For example, if a target is ignited by a fire elemental’s Fire Form trait, the ongoing fire damage doesn’t increase if the burning target is subjected to that trait again. Game features include spells, class features, feats, racial traits, monster abilities, and magic items. (DMG p. 252)

Combining Magical Effects:

The effects of different spells add together while the durations of those spells overlap. The effects of the same spell cast multiple times don’t combine, however. Instead, the most potent effect—such as the highest bonus—from those castings applies while their durations overlap. For example, if two clerics cast bless on the same target, that character gains the spell’s benefit only once; he or she doesn’t get to roll two bonus dice. (PHB p. 204)

How does the information above interact with spells that have multiple effects? I have used three spells as examples because each of them represents a nuance, but they could all combine to provide an answer: Blindness/Deafness (PHB p. 219), Bestow Curse (p. 218) and Contagion (p. 227).

For Blindness/Deafness (separate conditions): If this is cast twice, once to cause Blindness and once to cause Deafness, does this mean that the creature is both blind and deaf? Or, because it’s part of the same spell, only one of the effects is present – if so, which one?

For Bestow Curse (various curses): If two separate casters bestow separate curses on the same creature, do both curses remain in place? If so, how does we decide which one is active?

For Contagion (natural diseases): If you cast Contagion multiple times, to cause different natural diseases, would the creature have multiple diseases active, or only one of them?

I appreciate your thoughts on this.

## How is this sqlmap query is correct?

I am practicing on some vulnerable application, and I am asked to find an injection vulnerability with a payload. it states there is a common and simple filter in place. Then I need to extract the flag value from the chlns table. So I use SQLmap to find it.

Please read below and correct me if I am wrong in any stage:

sqlmap -u 'http://www.site.com/game.php?name=sarah’ --dbs 

When I run it, it asks that it is being redirected to facebook, and I press n to not do that. Then it continious and load 3 databases as such:

-- information_schema -- chlns -- people 

on I run the following query:

sqlmap -u 'http://www.site.com/game.php?name=sarah’ -D chlns --tables 

to get all the tables. After it starts running it gives the below error:

[ERROR] unable to retrieve the table names for any database do you want to use common table existence check? [y/N/q] y 

Then it asks for a file or use the default wordlist. Which I used the default option. At the end it came up with a list of tables (13 overall) which then I used the below code for one of the sample table names:

sqlmap -u 'http://www.site.com/game.php?name=sarah’ -D chlns T- table --dump 

this code asks for the same thing when i run it and want to run it through a worklist. each process takes a long time around 10/15 mins and each time it come up with an error like below:

HTTP error code: 414 (Request-URI Too Large) [*N times... 

And i get nowhere. Am I doing anything wrong here? or is there any easier way? the excercise mentiones there is a table called chlns but it seems chlns is a database instead. This could be the case as in another excercise chlns was the database and one was the name of the table that flag existed.

Is there any suggestions to make this process easier or any pro advice?