Algorithm for producing array of objects according to optimal distribution

I have a set of objects, and each object has (let’s say) a color. Given a distribution such as:

red : 50% green : 30% blue : 20% 

I need to produce an N-length array of objects with a color distribution as close to this as possible. It is possible that the length of the original list is smaller than N, so duplicates may be required.

Is there an efficient algorithm that might be suited for this kind of task? I imagine there is, but I’m lacking the terminology to find it.

Q: Set Folder’s path according to it’s title in a list with SPFx

I am creating a folder inside a List with the following code:

TypeScript import {sp} from "@pnp/sp";  const shpList = sp.site.rootWeb.lists.getById(ListId);  shpList.items.add( {   Title: folderName,   FileSystemObjectType: 1,   ContentTypeId: '0x0120',   FileLeafRef: folderName,   DisplayName: folderName } ) 

And it does create the folder, but the navigation displays 130_.000 as the folder. (It’s the item’s ID plus underscore, dot and three zeros)

Is there a way to create the item so it uses the title as the navigation?

Is there any place I can look for the default properties of SharePoint?


Here a list of the properties I have already tested:

  • Name (and name) | value: folderName | result: error (not registered property)
  • FileRef | value: folderName | result: Does not seem to do anything
  • Path (and path) | value: folderName | result: error (not registered property)
  • Folder | value: folderName | result: error (primitive value not null)
  • Url (& url & URL) | value: folderName | result: error (not registered property)

Can Modular Abilities get an extra 10% savings according to GURPS Supers rules if they don’t grant skills?

I want the player characters to have lots of super-powers. For example, I want them to have inexpensive mental Modular Abilities with typically psionic abilities such as Psychokinesis and ESP and Mind Control (but no skills). Modular Abilities cost less if they are only mental. On the topic of Telekinesis, the main rulebook, page B92, says:

Psychokinetic: Your ability is part of the Psychokinesis psi power (see p. 256). This makes it mental rather than physical. -10%

I want to give the players all available savings, but I want to avoid double-dipping by giving the same discount twice.

In a normal campaign, level 10 Telekinesis would cost 50 points as a physical power, but 45 points as a Psychokinetic mental power.

Now let us suppose that the player characters start off with Modular Abilities, mental advantages only. Assume each mental advantage costs 45 points, and only one can be used at a time, so this power is a one-slot modular ability, base cost 5 points, slot cost 3 points per advantage point. $ 5+3\times45=190$ .

I think the basic cost should be $ 190-19=171$ , because the quasimoral power modifier deducts 10%. But I see in GURPS Supers, p. 46, that a wizard can have an extra 10% savings due to “mental advantages only” (i.e. no skills are allowed). So perhaps the basic cost of this mental slot should be 152.

[Question: which is more appropriate, 171 points or 152 points?]

Color of line in ParametricPlot according to indepedent variable

I solve a set of pdes numerically using NDSolve:

ic1[x_, y_] := Which[x < 3 && y < 3, 6, True, 0] ic2[x_, y_] := Which[x < 3 && y < 3, 0.5, True, 1/c11] sol = NDSolve[{D[pp[t, x, y], t] ==  0.05*Laplacian[pp[t, x, y], {x, y}] +   pp[t, x,     y]*(1 - c11*pp[t, x, y] - z[t, x, y]/(1 + pp[t, x, y]^2)),  D[z[t, x, y], t] ==  0.05*Laplacian[z[t, x, y], {x, y}] +   z[t, x, y]*(eps*pp[t, x, y]/(1 + pp[t, x, y]^2) - m), (D[    pp[t, x, y], x] /. x -> 0) ==  0, (D[pp[t, x, y], y] /. y -> 0) ==  0, (D[z[t, x, y], x] /. x -> 0) ==  0, (D[z[t, x, y], y] /. y -> 0) ==  0, (D[pp[t, x, y], x] /. x -> 20) ==  0, (D[pp[t, x, y], y] /. y -> 20) ==  0, (D[z[t, x, y], x] /. x -> 20) ==  0, (D[z[t, x, y], y] /. y -> 20) == 0, z[0, x, y] == ic1[x, y],  pp[0, x, y] == ic2[x, y]}, {pp, z}, {t, 0,  100} {x, 0, 20}, {y, 0, 20}]; 

First of all, evaluation over a long time interval does not work. Can I do something to export only certain time steps to save memory or something?

Furthermore, I want to plot the results of a certain point in space (x,y) in a parametric plot. I can do this with the following code:

ParametricPlot[ Evaluate[{pp[t, 4, 4], z[t, 4, 4]} /. sol], {t, 0, 100},  PlotRange -> {{0, 2}, {0, 4}}, AxesLabel -> {p, z},  PlotStyle -> {Thickness[0.002]},  ColorFunction -> {Function[{x, y, t}, Hue[t]]}] 

However, I find it hard to link the Hue-Colors to the temporal evolution. I would prefer a color gradient with changing opacity or some temperature (CoolWarm) scale or something. How can I do this? I thought this should be quite straight forward but I didn’t find anything about it the last days.

Thank you!

Ranking items according to their position within a list and their display time within this list

I’ve build a scraper that gathers articles on a the main page of a news website every 15 minutes (this website really looks like Google News). I give those articles a kind of weight based on their ranking on the main page, and I also monitor their display time on this main page.

So, for instance:

  • During its first run started at time T1, the scraper collects article A, article B and article C. A appears first on the main page of the news website, and is followed by B and C. I give A a score of 3, B a a score of 2 and C a score of 1 (score = number or items within the list – index, the list is zero-indexed).
  • 15 min later, at time T2, the scraper collects article D (a new article at 1st position), followed by A and B (C does not appear on the list anymore). Thus D score = 3, A score = 3 (score obtained during the scraper’s first run) + 2 (score obtained on the second run), B score = 2 + 1.
  • At this point, I know that A & B have probably been displayed at least for 15min on the main page so I give them a display time of 15 minutes.
  • Third run, time T3: B is still there, at the third position. All the other articles are gone from the main page. So B score = 2 + 1 + 1 and display time = 15 min + 15 min.

I’d like to devise an algorythm that would allow me to say with certainty which articles have been the most visible during a given time period (most visible = displayed the most and at the highest position on the main page during the time period).

I thought of calculating score of the article / number of times my scrapper has run on the time period (which is a (timedelta / 15) + 1, since my scrapper runs every 15 min after it is launched), but this is not satisfying if I want to give more importance to the display time.

For instance, with the case described above, I have T3 – T1 = 30 min, script ran (30/15+1=3 times). Score of the article / number of times my scrapper has run on the time period would give 5/3 for article A and 4/3 for article B. So A has been more “important” over those 30 min.

Now imagine I run the script a 4th time and it still finds B at the third place on the main page. That would give A a score of 5/4 and B a score of 5/4 as well. However, one can argue they don’t have the same importance, as B could be seen on the main page for 45 min straight while A just sat there for 15 min (at a better place, though).

Do you have any piece of advice to improve the way I calculate the importance score of each article? Sorry for the long post, I know this is basic maths but I’m a bad student 😉

According to the Rules Compendium can I charge through a square that would hamper my movement as long as it isn’t difficult terrain?

Relevant text

INITIATING A CHARGE

If you don’t have line of sight to the opponent you want to charge at the start of your turn, you can’t charge that foe. To charge, you must move at least 10 feet (2 squares) and can move up to double your speed. You must be able to reach the closest space from which you can attack the designated opponent. This movement must occur before your attack. If any line from your starting space to the ending space passes through a square that blocks movement, is difficult terrain, or contains a creature (not a helpless one), you can’t charge. You can’t charge if the ending space is occupied or blocked. Since you move to charge, you can’t take a 5-foot step during the same turn. You provoke attacks of opportunity as normal for your movement.
(Rules Compendium p.27)

It seems that squares that aren’t difficult terrain, that only hamper movement but not block it are legal.

This would include Obstacles, Poor visibility (Any time you can’t see at least 60 feet in the prevailing conditions of visibility), and Squeezing.

Also some spells cause hampered movement that isn’t difficult terrain.

SUM weekly values according to date in one column A and values in column B

As shown in the screenshot, I have values I am looking to add for weekly totals to track, however, this is very tedious having to create new code for every week, especially as the weeks change per month and so on. What I am looking to do is use the date feature as I have lined up in column A to match with column b and so on to make weekly values so I only have to type in the sum of a week number rather than a sum of ex b2:b8

I was thinking because if I were to type =ISOWEEKNUM(“July 1”) it gives me 27, so I am looking to use some code to say =SUM(week27in column a, B:B) type of thing but I don’t know google sheets code well enough to think of it on my own.

If anyone has ideas please let me know. Thanksenter image description here

finding duplicates and updating a column with values according with number of duplicates using mysql stored procedure

I am using Mysql 10.1.29-MariaDB Database to create a new table.

What I am trying to do is to increment a number for each duplicate appearance of a value of company_name in another column. For example, for the table:

provided order_placed column of both table should be null

# req    +--------------------------------------------------+ |                        req                       | +--------------------------------------------------+ | req_id | order_placed | contact_id | seq_records | +--------+--------------+------------+-------------+ | 1      |         null |       1000 |        null | +--------+--------------+------------+-------------+ | 2      |         null |       1002 |        null | +--------+--------------+------------+-------------+ | 3      |         null |       1003 |        null | +--------+--------------+------------+-------------+    +--------------------------------------------------------------------+ |                               contact                              | +--------------------------------------------------------------------+ | contact_id | first_name | order_placed | company_name | company_id | +------------+------------+--------------+--------------+------------+ | 1000       | dirt       |         null |         Asus | 12         | +------------+------------+--------------+--------------+------------+ | 1002       | dammy      |         null |         Asus | 12         | +------------+------------+--------------+--------------+------------+ | 1003       | samii      |         null |         Asus | 12         | +------------+------------+--------------+--------------+------------+ | 1004       | xenon      |         null |       Lenova | 1          | +------------+------------+--------------+--------------+------------+   CREATE TABLE `req` (   `req_id` bigint(20) NOT NULL,    `order_placed` char(1) COLLATE utf8_bin DEFAULT NULL,    `contact_id` bigint(20) DEFAULT NULL,    `seq_records` bigint(2) DEFAULT NULL,   PRIMARY KEY (`req_id`),   KEY `contact_id` (`contact_id`),   CONSTRAINT `req_ibfk_10` FOREIGN KEY (`contact_id`) REFERENCES    `contact` (`contact_id`) )  /*!40101 SET character_set_client = @saved_cs_client */;  # contact  CREATE TABLE contact (   contact_id bigint(20) NOT NULL,   `first_name` varchar(100) COLLATE utf8_bin NOT NULL,   `company_name` varchar(100) COLLATE utf8_bin DEFAULT NULL,   `company_id` varchar(100) COLLATE utf8_bin DEFAULT NULL,   `order_placed` char(1) COLLATE utf8_bin DEFAULT NULL,   PRIMARY KEY (`contact_id`),   KEY `index_name` (`contact_id`), )   

query used

DELIMITER $  $   DROP procedure IF EXISTS `recordsequence` $  $   CREATE procedure `recordsequence` () BEGIN  declare companyname varchar(250); declare recordcount integer default 0; declare duplcount integer default 0; DECLARE vfinished INTEGER DEFAULT 0; declare icount int default 0; DEClARE records_cursor CURSOR FOR select c.company_name,count(c.company_name),r.opr_id from contact c, request r where c.contact_id=r.contact_id and r.order_placed is null  group by c.company_name; -- declare NOT FOUND handler DECLARE CONTINUE HANDLER FOR NOT FOUND SET vfinished = 1; OPEN records_cursor; transfer_records: LOOP FETCH records_cursor INTO companyname,duplcount; IF vfinished = 1 THEN LEAVE transfer_records; END IF;  begin set recordcount := duplcount; set icount := 1; DEClARE records_cursor1 CURSOR FOR select c.contact_id,c.company_name from contact c, request r where c.company_name = companyname and c.contact_id=r.contact_id and r.order_placed is null group by c.company_name; -- declare NOT FOUND handler DECLARE CONTINUE HANDLER FOR NOT FOUND SET vfinished = 1; OPEN records_cursor1; transfer_records1: LOOP FETCH records_cursor INTO contactid,companyname; IF vfinished = 1 THEN LEAVE transfer_records1; END IF;  begin  UPDATE contact set reorder_sequence = icount where contact_id = contactid; set icount := icount + 1; end;  END LOOP transfer_records1;  CLOSE records_cursor1;  if(recordcount == icount) THEN  select concat('company_name Updated successfully', companyname);  else select concat('company_name count mismatches please check', companyname); end if  end  END LOOP transfer_records;  CLOSE records_cursor;  End$  $   DELIMITER ; 

the above query is to create a procedure for the steps below

  1. To fetch records companyname and duplcount of the company names with the cursor.
  2. To fetch contact id of each company names and start a loop for a update statement.
  3. To update reorder_sequence table with values like the example given below

expected Result

Eg:  contact table  +--------------------------------------------------------+ |                         contact                        | +--------------------------------------------------------+ | order_placed | contact_id | company_name | seq_records | +--------------+------------+--------------+-------------+ | null         |       1002 |         Asus | 1           | +--------------+------------+--------------+-------------+ | null         |       1003 |         Asus | 2           | +--------------+------------+--------------+-------------+ | null         |       1005 |         Asus | 3           | +--------------+------------+--------------+-------------+ | null         |       1006 |       Lenova | 1           | +--------------+------------+--------------+-------------+  

Like the above example i have updated seq_records column with values according to the company_name column provided both order_placed column is null

error

A syntax error occurred with code 1064 near second select statement.

How to reply user according to different result?

i am working on a chat-bot for answering questions related me, like what are my 10th,diploma,BE scores? Hobbies? Work Experience? and other things. i am working on dialog-flow. So what i am trying to do is?

User says Hi Bot says Greetings,how can i assist you? User says How much you scored in 10th? Bot says 93% User says In diploma? Bot says 9.4 C.G.P.A. User says What are your hobbies? Bot says Reading,writing are my hobbies. now if user asks things without context then what should i do,like User says Can i know your score? Bot says Which one? 10th? Diploma? BE? User says 10th Bot says 93% User says Diploma Bot says 9.4 C.G.P.A.

please assist me with this 🙂

i have tried the S.S.C. one but it is not working if i immediate ask about the diploma scores after it.