graphics3d – Scaling the edge length of a graph to be equal to edge weight (again)

This is a follow up to my previous question posted here

The following is an excerpt of the solution has been provided here to set the edge length of a graph equal to the edge weights

edges = {1 <-> 2, 1 <-> 3, 1 <-> 4, 2 <-> 5, 2 <-> 6, 5 <-> 6, 
   3 <-> 4, 3 <-> 7, 6 <-> 7, 7 <-> 8, 2 <-> 9};

vd = {{75., 25., 0}, {115., 45., 0}, {10., 5., 0}, {45., 0, 0}, 
  {90., 60., 0}, {45., 55., 0}, {0, 25., 0}, {10., 50., 0}, {115.,  25.,0}};

vl = Range(Length@vd);

vcoords = MapIndexed(#2((1)) -> # &, vd);
ew = {1 (UndirectedEdge) 2 -> 49.6, 1 (UndirectedEdge) 3 -> 74.4, 
 1 (UndirectedEdge) 4 -> 49.6, 2 (UndirectedEdge) 5 -> 37.2, 
 2 (UndirectedEdge) 6 -> 74.4, 5 (UndirectedEdge) 6 -> 49.6, 
 3 (UndirectedEdge) 4 -> 37.2, 3 (UndirectedEdge) 7 -> 24.8, 
 6 (UndirectedEdge) 7 -> 62, 7 (UndirectedEdge) 8 -> 37.2, 
 2 (UndirectedEdge) 9 -> 24.8}

g3d = Graph3D(vl, edges, VertexCoordinates -> vcoords, 
  EdgeWeight -> ew, VertexLabels -> Placed("Name", Center), 
  EdgeLabels -> {e_ :> Placed("EdgeWeight", Center)}, 
  VertexSize -> .3, VertexStyle -> Red)
vars3d = Array(Through({x, y, z}@#) &, Length @ vd);

λ = 1/100.;

obj3d = Total((Norm(vars3d((First@#)) - vars3d((Last@#))) - # /. ew)^2 & /@ 
  EdgeList(g3d)) +  λ Total(Norm /@ (vars3d - vd));

lbnd = 0;
ubnd = 500;

solution3d = Last@Minimize({obj3d, And @@ Thread(lbnd <= Join @@ vars3d <= ubnd)}, 
    Join @@ vars3d);

edgeLengths3d = # -> Norm(vars3d((First@#)) - vars3d((Last@#))) /. 
     solution3d & /@ EdgeList(g3d);

Grid(Prepend({#, # /. ew, # /. edgeLengths3d} & /@ 
   EdgeList(g3d), {"edge", "EdgeWeight", "Edge Length"}), 
 Dividers -> All)

I would like to know how to modify the above when the nodes of the graph aren’t numbered consecutively.

I tried the following,

edges = {1 <-> 2, 1 <-> 3, 1 <-> 4, 2 <-> 11, 2 <-> 6, 11 <-> 6, 
   3 <-> 4, 3 <-> 7, 6 <-> 7, 7 <-> 8, 2 <-> 10};
vd = {{75., 25., 0}, {115., 45., 0}, {10., 5., 0}, {45., 0, 0}, {90., 
    60., 0}, {45., 55., 0}, {0, 25., 0}, {10., 50., 0}, {115., 25., 
    0}};

vl = {1, 2, 3, 4, 11, 6, 7, 8, 10};

vcoords = Thread(vl -> vd);

ew = {1 (UndirectedEdge) 2 -> 49.6`, 1 (UndirectedEdge) 3 -> 74.4`, 
  1 (UndirectedEdge) 4 -> 49.6`, 2 (UndirectedEdge) 11 -> 37.2`, 
  2 (UndirectedEdge) 6 -> 74.4`, 11 (UndirectedEdge) 6 -> 49.6`, 
  3 (UndirectedEdge) 4 -> 37.2`, 3 (UndirectedEdge) 7 -> 24.8`, 
  6 (UndirectedEdge) 7 -> 62, 7 (UndirectedEdge) 8 -> 37.2`, 
  2 (UndirectedEdge) 10 -> 24.8`};

g3d = Graph3D(vl, edges, VertexCoordinates -> vcoords, 
  EdgeWeight -> ew, VertexLabels -> Placed("Name", Center), 
  EdgeLabels -> {e_ :> Placed("EdgeWeight", Center)}, 
  VertexSize -> .3, VertexStyle -> Red)

vars3d = Array(Through@{x, y, z}@vl((#)) &, Length@vl);

λ = 1/100.;

obj3d = Total((Norm(vars3d((First@#)) - vars3d((Last@#))) - # /. 
         ew)^2 & /@ EdgeList(g3d)) + (Lambda) Total(
     Norm /@ (vars3d - vd));

I couldn’t execute obj3d successfully, the following is displayed

Part::partw: Part 11 of {{x(1),y(1),z(1)},{x(2),y(2),z(2)},{x(3),y(3),z(3)},{x(4),y(4),z(4)},{x(11),y(11),z(11)},{x(6),y(6),z(6)},{x(7),y(7),z(7)},{x(8),y(8),z(8)},{x(10),y(10),z(10)}} does not exist.

Suggestions on how to modify the expression for obj3d and the lines below it to successfully use the
solution provided in the previous post for the new input will be highly appreciated.

music – What is a good length for loop soundtrack?

We know that the soundtrack is important and expensive for indie budget. Now I requested a loop soundtrack for for my TD game. where zombie/monsters attacking player. So, entire a level player will keep hearing this music. In this kind of games, are 30 sec good for a loop soundtrack or I need to increase it?

focal length and sensor width of a phone

I am trying some 3D scene reconstruction in blender using my phone camera but in order for the program to do its math it needs to know the sensor width and focal length of my camera in millimeters but I have no idea of where I can get those values, all I know is that its a “f2.2 1.25-micron” camera but I have no idea of what that means.

Some estimations using another software tell me that it’s between 23mm and 27mm focal length if it was a 32mm sensor but I need a more accurate range.

My phone is a Redmi-6A.

algorithms – Find number of ways to create sequence $A$ of length $n$ satisfying $m$ conditions

Find number of ways to create sequence $A$ of length $n$ satisfying $m$ conditions. This sequence $A$ should consist of only non negative numbers. Each condition is described by three integers $i,j,k$ signifying $max$($A_{i}$,$A_{j}$)=$k$.
It is guaranteed that each index of the sequence will be there in at least one condition i.e. there will be finite number of such sequences.
The maximum value of $n$ will not exceed $18$ and maximum value of $k$ will not exceed $10^6$.

I tried it using dynamic programming but the time complexity came out to be exponential. Can you suggest me any better approach which will reduce the time complexity?

memory – Format string exploit length

i’m new to Software security and i’m studying it now at university.
I had some doubts about the Format String exploit, in particular how to count the length (in number of bytes) of a format string exploit.

Suppose that i have the following vulnerable code:

04 int guess(char *user) {
05     struct {
06          int n;
08          char usr(16);
09          char buf(16);
10      } s;
11
12      snprintf (s.usr, 16, "%s", user);
13
14      do {
15          scanf ("%s", s.buf);
16          if ( strncmp (s.buf, "DEBUG", 5) == 0) {
17              scanf ("%d", &s.n);
18              for ( int i = 0; i < s.n; i++) {
19                  printf ("%x", s.buf(i));
20              }
21          } else {
22              if ( strncmp (s.buf, "pass", 4) == 0 && s.usr(0) == '_') {
23                  return 1;
24          } else {
25              printf ("Sorry User: ");
26              printf (s.usr);
27              printf ("nThe secret is wrong! n");
28              abort ();
29          }
30          }
31      } while ( strncmp (s.buf, "DEBUG", 5) == 0);
32  }
33
34 int main(int argc, char** argv) {
35      guess(argv(1));
36 }

And the code is compiled in a IA-32 architecture (32 bit) with cdecl calling convenction and there’s no attack mitigation implemented (no stack canary, no ALSR ecc…, i’m in a complete vulnerable machine)

At line 26 there’s a format string vulnerability since the placeholder is missing ( printf (s.usr); ).

I’d like to overwrite the EIP with the address of an environmental variable that contains my shellcode.

I’m supposing (this is a theoretical exercise, i’m aware that in practice there are many other implications) that the address of my envirormental variable is 0x44674234, the address of the EIP is 0x42414515 and the displacement on the stack of my format string is 7.

So my format string exploit will be x15x45x41x42x17x45x41x42%16940c%7$hn%563c%8$hn, i’ll place it into user and then it will be copied into s.usr and executed by printf (s.usr);

Now what i noticed is that only 16 char are copied into s.usr from user.

Is my format string not exploitable? I counted 30 characters in my exploit, therefore the strcpy will copy only half of my exploit.

Is the number of char i counted correct? How should i count them?

list manipulation – Thread::tdlen: Objects of unequal length in {{a,b,e},{c,d,f}} {x,y,z} cannot be combined

When I do the Times operation among list like this {{a, b, e}, {c, d, f}}*{x, y, z}, the error message is given as Thread::tdlen: Objects of unequal length in {{a,b,e},{c,d,f}} {x,y,z} cannot be combined. Actually, the desired result should be {{a x, b y, e z}, {c x, d y, f z}}. Are there any bugs?

What are the minimum and maximum length of a Mainnet Bitcoin address?

The wiki says that

A Bitcoin address is an identifier of 26-35 alphanumeric characters.

Is this information up-to-date? Even the Bech32 address bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq given as an example on the same page has 42 characters.

Some other Bitcoin mainnet address examples:

Before you say that this is duplicate, I know that What are the minimum and maximum lengths of a Mainnet Bitcoin address? asks the same question. However, I do not have enough reputation to add a comment there.

python – Optimize function that returns length of a subarray

I did an exercise today on where the task is to write a function that returns the length of the longest subarray where the difference between the smallest and biggest value in the subarray is no more than 1. I had a solution that works but it’s too slow to pass the tests that have big arrays. What is it about my solution that makes it very slow with huge arrays?

def longestSubarray(arr):
    longest = 0
    arr_len = len(arr)
    for i in range(arr_len):
        for j in range(i, arr_len):
            sub = arr(i: j+1)
            if max(sub) - min(sub) > 1:
                continue
            length = len(sub)
            if length > longest:
                longest = length
    return longest

What is the time complexity of sorting n words length wise and then alphabetically? Should we consider the length of the strings in the complexity?

Let’s assume I have a list of some words found in the English dictionary:
(“hat”, “assume”, “prepare”, “cat”, “ball”, “brave”, “help” …. )

I want to sort these words (which are n in number) in a way, such that they are ordered based on their length, but if 2 words have the same length, they are ordered alphabetically.

What is the time complexity of this sorting operation?

Would it be fair to say that the complexity is just O(nlogn) and not take into consideration the length of the strings? If the largest length is S, can the complexity also involve a factor of S?

Finding paths of length $n$ on a directed graph

Suppose I have the following directed graph

g = Graph[{DirectedEdge[v1, v1, a], DirectedEdge[v1, v1, OverBar[a]], 
   DirectedEdge[v1, v2, b], DirectedEdge[v2, v2, c], 
   DirectedEdge[v1, v3, OverBar[b]], 
   DirectedEdge[v3, v3, OverBar[c]]}, VertexLabels -> "Name", 
  EdgeLabels -> "Index"]

First of all, I would prefer to label the edges with the tag of the directed edge, but I’m not sure how to do this.

The main question is, can Mathematica give me all possible paths of length $n$ on this graph starting from, say, $v1$?