Cannot assign raw object 2

My objective is to build a function using modules that runs the bisection method. I have a working bisection method but when I try to implement it as a module I keep getting this error and I can’t figure out why.

F[z_]:=3 + z + z^2 * Cos[z]   bisectionMethod[f_, a_, b_, n_] := Module[   {},   For[i = 0, i < n, i++,    Print[StringForm["Loop #: ``", i + 1]];    c = (a + b)/2;    y = f[c];    If[y < 0, a = c];    If[y > 0, b = c];    Print[StringForm["a = ``", N[a]]];    Print[StringForm["b  = ``", N[b]]];    c = (a + b)/2;    Print[StringForm["c = ``", N[c]]];    Print[N[f[c]]];    ]      ] bisectionMethod[F, -4 , 2 , 10]  

After being run

  Loop #: 1  Set::setraw: Cannot assign to raw object 2.  a = -4.  b  = 2.`  c = -1.  2.5403  Loop #: 2  Set::setraw: Cannot assign to raw object 2.  a = -4.  b  = 2.`  c = -1.  2.5403 

The issue appears to be specifically variable b but I have no idea how b is any different from the others and how to tackle this.

I did a little bit of experimentation and it seems like the line If[y > 0, b = c]; is problematic

Randomly assign n elements to n agents such that each agent only knows its own element


I’m working on an app that involves shuffling and distributing playing cards to players. As a challenge, I tried to solve this problem in a way that doesn’t require a trusted intermediary.

In other terms, the task is to find a distributed algorithm that

  • uniquely assigns $ n$ agents numbers $ 1..n$
  • allows each agent to know nothing about the assignment but its own
  • when revealing the assignment, allows other players to verify the assignment

We also assume that knowing other’s assignment is an advantage for each agent, and revealing its own prematurely a disadvantage. Agents are also assumed to be able to talk with each other in a way hidden from all other agents.

Partial solution

The solution I came up with works only under the assumption that adversaries do not collaborate.

The idea is to create a set of $ n$ nonces, and assign each agent exactly one nonce. The set is then passed from agent to agent in an agreed upon order, hidden from all others, until each agent received the set exactly once. Each time an agent receives the set, it swaps its nonce with a new one, memorizes the new nonce, and confirms receival of the set to the others. This entire procedure is done twice, at which point, all agents have received the set at least once after all other agents swapped their nonces, making it impossible to recognize and hence map the nonces to the other agents.

When the last agent receives the set the second time, it shares it with everyone, and all agents confirm to the others that their nonce is contained in the set. The agents then assign a number to each nonce in the set based on an agreed upon random seed, giving us the required unique assignment.

To allow ownership verification, instead of the nonces, agents put the hash value of their nonce on the set, revealing the actual nonce only when verification is required.

The problem with this solution is that if adversaries are allowed to collaborate, each time an adversary receives the set, they can compare their versions, identify changes and potentially derive which nonce belongs to other agents, allowing them to know what number got assigned to them.

All ideas are appreciated!

I am looking for a way to assign numerical values to colors (then interpolate a color scale) and then assign numerical values to comparative colors

Hello may name is Chris

I am completely new to programming (but I love it!! I am learning Swift).

I am currently looking for a solution to the mentioned problem. I’m not sure if it is a ML task or if it is better to do it in the traditional way – maybe by comparing and interpolating RGB values. How I imagine that might be easier to understand in the video.

VIDEO (is there a better way to provide a video?)

The color values ​​below were taken before the adjustment and assigned to the assigned values ​​0, 2, 5, 10, 25, 50 and 100. The round section is taken from a photo (by light and shadow you can see that not every color value brings a perfect match. But that shouldn’t be a problem (I hope so) by comparing the pixels and evaluating the color value with the most matching colour at the end). My spontaneous manual evaluation gives a value that should be around 19-20.

I have already thought back and forth whether it is possible to do the whole thing using color values ​​(e.g. R G and B) but that is not so easy since there should also be many different results depending on the color format I am working with.

On the other hand, I don’t know how to solve it using ML. It would be easy to recognize the exact color values ​​0, 2, 5, 10, 25, 50 and 100 – but how can I have intermediate values ​​determined? What do you think? Which approach is the better one? If you have a tip for me, that I know in which direction I have to think further would be great! And if you have an idea how I can work on my problem I would be so grateful!!! … otherwise I think I will need the coming days to find some solution.

Thank you in advance! Chris

construct a sql , assign it to a variable and execute inside shell script

I am trying to execute a mysql query inside my shell script, which is not executing . Here is what i am trying to do

query="\"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';\"" 

echo $ query

"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';" 

Inside my shell script , i am executing below which is not working. It is not giving any error but simply not considering -e option and listing down all the valid options for mysql client.

mysql -u$  username -p$  password -e$  query 

I even validated below in my shell prompt

echo "mysql -uroot -p -e$  query" mysql -uroot -p -e"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';" 

which is perfectly fine and executes without any issues. I am not sure what to do now. please help.Thanks

Is there some mechanisms in PHP to assign “less trust” to scripts in a given dir? (not a duplicate) [closed]

Kindly stop redirecting my questions to that unrelated one which doesn’t answer my question whatsoever. I’ve already read every answer there and it doesn’t help at all. If it did, why would I ask this much more specific question?

This has been a continuous worry and problem for me for ages:

For practical and logical reasons, I am forced to trust some third-party PHP libraries. These are installed, updated and managed with Composer, and live in C:\PHP-untrusted-external, entirely separated from my own PHP scripts, which live in C:\PHP-my-own.

The scripts in C:\PHP-my-own include and make use of the libraries in C:\PHP-untrusted-external.

Since there is no way that anyone, especially not I, could ever vet all the third-party code, and all updates, I’m looking for some way to “secure” or “sandbox” these in some way, even if it’s just partial.

Basically, I’m worried that one day, an update will make an edit such as:



phone_home_to_hacker_server($  contents_of_my_harddrive); 

If that happened, the scripts would happily run and do those actions. Nothing prevents them from doing so.

Is there really no way to specify in the php.ini configuration file, something like:

security.sandbox_dir = "C:\PHP-untrusted-external" 


security.refuse_network_connections_for_dir = "C:\PHP-untrusted-external" security.refuse_disk_io_for_dir = "C:\PHP-untrusted-external" 

… or something like that?

I don’t understand Docker. I have tried it countless times, and it makes no sense whatsoever to me. I don’t want Docker. I don’t want to deal with containers. Correction: I can’t deal with it. I’ve tried to, but didn’t understand it. Several times.

I just want PHP to support this in itself, and it seems more than reasonable to me. Doesn’t it seem reasonable to you?

The saying that “at some point, you have to trust other people” is way too generic/vague to apply here. It’s bypassing the problem. I don’t trust people at all, and for good reason. It seems idiotic that we are (apparently) just supposed to sit around and wait for the disaster to happen. At least if I could prevent the third-party scripts form doing anything with the file system and network, that would go some way toward mitigating this issue. It still won’t make the scripts unable to lie about the numbers/data they return to me, but at least they can’t directly “phone home” or delete random files.

Assign resources that each have a certain amount of work they can provide to tasks that require a certain amount of work

I’m attempting to do a hobby automation project and have come to a roadblock. I have a certain problem I need to solve, but can’t think of the solution nor what the name for the problem would be.

Say we have n tasks where each task requires $ x_i$ amount of work to be done and m resources where each resource can provide $ y_j$ work. The total amount of work required will equal the the total amount of work the resources can provide, i.e. $ \sum_{i=1}^{n} y_i = \sum_{j=1}^{m}x_j$ . For all j from 1 to m, $ y_j \in \left \{1, 2, 6, 12, 24\right \}$ and each $ x_i = a*1 +b *2 + c*6+d*12+e*24$ . I was looking at task assignment problems, but those seemed to be a bit overkill since they were concerned with optimization where I’m just simply trying to slot the correct blocks in the right place so that I don’t have tasks that are given too few or too many resources.

My current guess is that you can iterate over each task, and give it the largest resource available that doesn’t go over the amount of work that is left for the task to be completed. It’s almost analagous to filling a jar with different sized rocks; the best way is to start with the largest rocks and then go down in size from there, so that the smaller rocks fill in the space between the larger ones. Am I not taking something into consideration that complicates this problem further? I’m sorry if this is an obvious one, but I’m a hobbyist programmer and couldn’t think of the name of the problem or of a good set of keywords to google. The closest I could find is task assignment so far.

Psycopg2 using value SET before assign to other column

I have a table with columns as below: (id, col1, col2, col3, col4). I need to insert new row to this table, with given data is a dict: data = {'id': 1, 'col1': 1, 'col2':1, 'col3':1, 'col4': 1} for example.

I want to use the query below to insert data into table if id not existed, or update the table if id existed:

query =  '''     INSERT INTO tablename (id, col1, col2, col3, col4)     VALUES (%(id)s, %(col1)s, %(col2)s, %(col3)s, %(col4)s)     ON CONFLICT (id) DO UPDATE SET     col2 = tablename.col2 + 1;     col3 = col2/100 ''' result = cur.execute(query, data) 

In the code above, I want to assign col3’s value to (value of col2 calculated before)/100. How can I do that?

Encoding System that Assign Same Number of Bits for Each Character

I am trying to get a binary string that has been converted from text of a text file, I am able to get that but the problem is, I need each character to be represented by same number of bits, but that is not what I get (please see the below python code and corresponding output). For example, character i is represented by 1101001, which is 7 bits long, but character ! is represented by 100001, which is 6 bits long.

Is there any encoding/decoding system where each character takes same amount of bits?

content = open('a.txt', 'r').read() test_str = content # using join() + ord() + format()  ... Converting String to binary   Binary = ' '.join(format(ord(i), 'b') for i in test_str)  #Decimal=int(Binary, 2)    # printing original string   print("The original string is : " + str(test_str))  # printing result   print("The string after Binary conversion : \n" + str(Binary)) 


The original string is : Hi! Is there a solution? The string after Binary conversion :  1001000 1101001 100001 100000 1001001 1110011 100000 1110100 1101000 1100101 1110010 1100101 100000 1100001 100000 1110011 1101111 1101100 1110101 1110100 1101001 1101111 1101110 111111 

How to assign a big integer struct to a long n

I have the following code, it does not work properly: void assignInt(bint res ,long n) { int i; / counter / int t; / int to work with */

if (n >= 0)     res->sign = PLUS; else     res->sign = MINUS;  for (i=0; i<MAX_SIZE; i++)     res->digits[i] = (char) 0;  res->size = -1;  t = labs(n);  while (t > 0) {     res->size++;     res->digits[res->size] = (t % 10);     t = t / 10; }  if (n == 0)     res->size = 0; 

} // initialzes a bint to value n