plotting – Arrange elements in PlotLegend

I have the following test code

Plot(Evaluate@Table(Sin(i*Pi*x), {i, 0, 10}), {x, 1, 20}, 
 PlotLegends -> 
  SwatchLegend({"#0", "#1", "#2", "#3", "#4", "#5", "#6", "#7", "#8", 
    "#9", "#10"} , 
   LegendMarkers -> Graphics({EdgeForm(Black), Rectangle()}), 
   LegendLabel -> "Legend", 
   LegendFunction -> (Framed(#, RoundingRadius -> 2) &), 
   LegendMargins -> 2), Frame -> True, 
 LabelStyle -> Directive(Black, FontSize -> 20), 
 FrameLabel -> {Style("!(*
StyleBox("x",nFontColor->GrayLevel(0)))"), Style("SIN")}, 
 ImageSize -> 800)

I would like to achieve two things:

  1. Arranging the elements in PlotLgends such that in the first column there are six elements and on the second the other five;
  2. Changing the FontSize different from that of the plot, I would like for example to make it smaller.

8 – Is it possible to use only one module for multiple Site Studio (Cohesion) elements?

I’m creating custom elements to use within Acquia Site Studio/Cohesion (following this), but one majorly inconvenient thing is that you have to create a whole new module for each element. I’m trying to integrate an entire preexisting design system with several components, so registering and enabling modules for each of them is a bit of a pain.

I noticed that all of Site Studio’s stock elements use only one module, so it gave me the idea to do the same. However, those elements aren’t like custom ones, in the sense that they’re retrieved from an API and the markup is generated at runtime. So I can’t exactly just follow the same process.

So far what I’ve tried is creating a single “Components Package” module, then defining multiple classes for each element inside the src/Plugin/CustomElement/ComponentPackage.php file. But the class has to match the file name, so that doesn’t work.

I’ve read through all of Acquia’s documentation and there’s nothing that addresses this, so I fear it may not be possible. But their documentation lacks in several areas, so maybe it is. Any help would be much appreciated.

python – Figuring out how two elements are connected

At Daisy’s party there are fruit skewers that the guests put together themselves. There are six types of fruit to choose from: apple, banana, blackberry, strawberry, plum and grape. All
Pieces of one kind are in their own bowl. Daisy loves surprises and all that
she covered the six bowls and only provided them with numbers so that the guests wouldn’t
Know beforehand what type of fruit to expect when they get to the top of the queue
before a certain number.
Donald doesn’t like Daisy’s surprises at all. He only wants to eat certain types of fruit
but does not like to admit this. Therefore he observes other guests and makes a note of which ones
Queue them up before putting their skewers together, and how the skewers end up
look. In this way, however, he does not find out which piece of fruit came from which bowl
is. Here are his first observations:

• Mickey has a skewer with apple, banana and blackberry, the fruit pieces from the
Bowls 1, 4, and 5 come (but not necessarily in that order).
• Minnie’s skewer is made from banana, plum and grape and was made from the bowls
3, 5 and 6 put together.

• Gustav has a skewer with apple, blackberry and strawberry and has bowls 1, 2
and 4 visited.

Now Donald wants to make himself a fruit skewer with grapes, blackberries and apples. Unfortunately, from the information available, he cannot clearly determine in which bowls these types of fruit can be found. Therefore, he also observes at the end
• Daisy has a strawberry and plum skewer and was on bowls 2 and 6.
a) Help Donald and tell him which bowls to use. Sketch how
you determined the number of bowls.
b) After the party, Daisy is thrilled: It was a complete success! She is determined
To organize brilliant fruit skewer happenings, with umpteen types of fruit and many guests.
Donald wants to be there, of course. But now he’ll have to make an even bigger effort to
put together the skewer you want.
Write a program that can help Donald. It should read in the following data:
• the amount of fruits available;
• Information about some fruit skewers: for each skewer

  • the amount of fruit on the skewer and
  • the same number of numbers of the bowls from which these types of fruit originate;
    • a lot of desired varieties.

I have the following result for the question:

Plum => 6
Strawberry => 2
Banana => 5
grapes => 3

How can I implement this in Python?

I will get the input as a .txt file which has:

-The number of available types of fruit (as an upper limit: not all available types of fruit have to appear in the file) in the first line,

In the second line Donald’s preferred version,

n the third line the number N of observed fruit skewers and
in the following 2N lines in two lines one after the other one observation; in the first line the set of bowl numbers from which the types of fruit specified in the second line come (although it is unclear which type comes from which bowl).
There are a maximum of 26 different types of fruit. Each variety name begins with a different letter of the alphabet.

Example for .txt file

Clementine Strawberry Grapefruit Raspberry Cassis 
6 10 3 
Banana Fig Ginger
2 1 9 8 4 
Apple Clementine Jujube Strawberry Raspberry
5 8 10 4 2 
Apple Strawberry Fig Raspberry Cassis
6 4 2 5 9 
Jujube Strawberry Raspberry Ginger Cassis

How to generate a random matrix with arbitrary correlation between elements?

I would like to find a smart way to generate a $Ntimes N$ random matrix $M$ with arbitrary correlation:
boxed{langle M_{ij}M_{kl}rangle=tau_{ijkl}}

Where the mean and variance of the elements are given by:
langle M_{ij}rangle&=0 \
langle M_{ij}^2rangle&=sigma^2

The case I am interested in is actually a sub-problem of this. I would like to generate a matrix whose elements follow a normal distribution of mean $0$ and variance $1/N$, and whose elements are correlated the following way:
langle M_{ij}M_{ki}rangle=tau_{ijk}

When $tau_{ijk}=delta_{jk}N^{-1}$ I recover a symmetric matrix.

combinatorics – Minimum numbers of elements of a partition of $ell$-separated sets

Given a positive integers $n,ellge1$, and given a subset $L$ of ${1,dots,n}$, I say that $L$ is $ell$-separated if there is an ordering of its elements $a_1,a_2,dots,a_k$ such that $a_{j+1}-a_jgeell$ for all $j=1,dots,k-1$. Clearly, every singleton is $ell$-separated. For example ${2,5,7,11}$ is a $2$-separated set, but not 3-separated.

I would like to find the minimum integer possible such that there is a partition of the set ${1,dots,n}$ of $ell$-separated sets with each of the sets of the partitions having at most $d$ elements, where $d$ is a fixed integer.

Clearly if $n=1$ or $ell=1$ or $d=1$ the answer is obvious.

Any help is appreciated.

dynamic programming – Maximum sum of elements from each column of the 2 x n matrix

Given the $2times N$ matrix, the algorithm should maximize the total sum of points from each column of the matrix.
I should choose only one point from each column, and I can choose the points consecutively up to two in the same row of matrix.

Input is $2times N$ size matrix, and the output is the maximum total sum.

For example, for $2times 3$ matrix $A=begin{bmatrix}1&5&7\3&6&11end{bmatrix}$, without the constraint, the answer will be $3+6+11=20$. But with the constraint, the algorithm should give $3+5+11=19$ as the output.

How can I do this in recursive manner? (I want it in polynomial time complexity.)

javascript – How do you make html elements not blurry

I was making a html game and all the elements are blurry is there a fix to this?
I use css but it makes it blurry


 <!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
canvas {
    border:1px solid #d3d3d3;
    background-color: #f1f1f1;
    width:  75%;
  height: 75%;
  margin: 0;
<body onload="startGame()">

var myGamePiece;
var myObstacles = ();
var myScore;

function startGame() {
    myGamePiece = new component(30, 30, "red", 10, 120);
    myGamePiece.gravity = 0.05;
    myScore = new component("30px", "Consolas", "black", 280, 40, "text");

var myGameArea = {
    canvas : document.createElement("canvas"),
    start : function() {
        this.canvas.width = 480;
        this.canvas.height = 270;
        this.context = this.canvas.getContext("2d");
        document.body.insertBefore(this.canvas, document.body.childNodes(0));
        this.frameNo = 0;
    clear : function() {
        this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

function component(width, height, color, x, y, type) {
    this.type = type;
    this.score = 0;
    this.width = width;
    this.height = height;
    this.speedX = 0;
    this.speedY = 0;    
    this.x = x;
    this.y = y;
    this.gravity = 0;
    this.gravitySpeed = 0;
    this.update = function() {
        ctx = myGameArea.context;
        if (this.type == "text") {
            ctx.font = this.width + " " + this.height;
            ctx.fillStyle = color;
            ctx.fillText(this.text, this.x, this.y);
        } else {
            ctx.fillStyle = color;
            ctx.fillRect(this.x, this.y, this.width, this.height);
    this.newPos = function() {
        this.gravitySpeed += this.gravity;
        this.x += this.speedX;
        this.y += this.speedY + this.gravitySpeed;
    this.hitBottom = function() {
    var rockbottom = myGameArea.canvas.height - this.height;
    if (this.y > rockbottom) {
        this.y = rockbottom;
        this.gravitySpeed = 0;
} // This curly brace was missing.

this.hitTop = function() {
    var skyhigh = 0;          // Top of the window.
    if (this.y < skyhigh) {   // Use less-than to check if you're above.
        this.y = skyhigh;
        this.gravitySpeed = 0;
    this.crashWith = function(otherobj) {
        var myleft = this.x;
        var myright = this.x + (this.width);
        var mytop = this.y;
        var mybottom = this.y + (this.height);
        var otherleft = otherobj.x;
        var otherright = otherobj.x + (otherobj.width);
        var othertop = otherobj.y;
        var otherbottom = otherobj.y + (otherobj.height);
        var crash = true;
        if ((mybottom < othertop) || (mytop > otherbottom) || (myright < otherleft) || (myleft > otherright)) {
            crash = false;
        return crash;

function updateGameArea() {
    var x, height, gap, minHeight, maxHeight, minGap, maxGap;
    for (i = 0; i < myObstacles.length; i += 1) {
        if (myGamePiece.crashWith(myObstacles(i))) {
    myGameArea.frameNo += 1;
    if (myGameArea.frameNo == 1 || everyinterval(150)) {
        x = myGameArea.canvas.width;
        minHeight = 20;
        maxHeight = 200;
        height = Math.floor(Math.random()*(maxHeight-minHeight+1)+minHeight);
        minGap = 50;
        maxGap = 200;
        gap = Math.floor(Math.random()*(maxGap-minGap+1)+minGap);
        myObstacles.push(new component(10, height, "green", x, 0));
        myObstacles.push(new component(10, x - height - gap, "green", x, height + gap));
    for (i = 0; i < myObstacles.length; i += 1) {
        myObstacles(i).x += -1;
    myScore.text="SCORE: " + myGameArea.frameNo;

function everyinterval(n) {
    if ((myGameArea.frameNo / n) % 1 == 0) {return true;}
    return false;

function accelerate(n) {
    if (!myGameArea.interval) {myGameArea.interval = setInterval(updateGameArea, 20);}

    myGamePiece.gravity = n;
<button onmousedown="accelerate(-0.2)" onmouseup="accelerate(0.05)">ACCELERATE</button>
<p>Click the ACCELERATE button to start the game</p>
<p>How long can you stay alive? Use the ACCELERATE button to stay in the air..</p>

linear algebra – minimum number of elements of a spanning set of vectors of $(mathbb Z / n mathbb Z)^m$

A spanning set of $(mathbb Z / n mathbb Z)^m$ is a set $V = {v_1, ldots, v_{ell}}$ of $m$-coordinates vectors with coefficients in $mathbb Z / n mathbb Z$ such that, for each vectors $u$ of $(mathbb Z / n mathbb Z)^m$, there exists a linear combination of $V$ that gives $u$, i.e. : $$ (mathbb Z / n mathbb Z)^m = left {a_1v_1 + a_2v_2 + ldots + a_{ell}v_{ell} mid a_1, ldots, a_{ell} in mathbb Z / n mathbb Z right }$$
It is obvious that, for every $n geq 2$ and $m geq 2$, there always exists such $V$ with $m$ elements (with the vectors $(0, ldots, 0, 1), (0, ldots, 0, 1, 0)$ and so on) but for a given spanning set $V$ of $(mathbb Z / n mathbb Z)^m$ could we always reduce $V$ to have $n$ elements (that is $ell = m$) ? and if not, on what condition?

Thank you in advance for your help.

design – What approaches are there for handling elements in contiguous memory while being dependent on other user input

I am creating a vectorized reinforcement learning environment. It handles multiple instances of a board game in synchron. Up until now, the state of the environment was a specific representation of the board. However, the need arose for running tests with different board representations and later it might expand to include data aside the representation (altough very unlikely).

Structure-wise I am utilizing Data Oriented Design and not Object Oriented Proremming. As result I have contiguous vectors for each environment attribute (board, turns, score) and not a vector of environments. This way of processing resulted with a 5-6x speed increase with otherwise same functions.

What options do I have in supporting multiple state types, especially if performance is a key aspect? (There is no need to support multiple types in the same instance of a vectorized environment.)

In my initial approach (after using a single std::vector with “fancy” indexing) I utilized a std::vector of std::arrays. This was sufficient for handling one board representation, but not for multiple. Therefore I switched to a custom templated class in my last approach with a std::array as its member. The size of the array was was set by an enum template argument. (I wanted my data to be in contiguous memory, therefore kept the vector of arrays design, and used tempalting to determine the size for holding all the features of the representation.) This method had advantages such as type safety and handling different scenarios by simple overloads. The disadvantages include the requirement of an extra tempalte argument (who would have though) and – the most importantly – I am not convined whether it could later be expanded into supporting a state that consists of something other than the board.

(To clarify the last part, if the state only requires the boards, then no issues there for handling multiple representations. However, if for a certain representation it needs an extra argument then the overloading only works if I add that extra argument as a dummy argument to all other functions.)

My ideas regarding the next possible approach include switching the type enum from a template argument to a member variable. The states could be handled with a single std::vector and fancy indexing or each representation would have their own storage allocated and only the selected one used. The proper function calls would be handled by branching (so multi argument state creation is no issue). This appraoch seems to be rather flexible, but maybe it would cost in performance.

What did I miss? How could my approaches be improved? What other solutions do you see?