Compiler Design Assignment

1.grammar G which is context-free has the productions

S → aAB

A → Bba

B → bB

B → c

Compute the string w = ‘acbabc’ with left most derivation, right most derivation and draw Top Down parse tree.

2.Compute the First and Follow sets

S→ Aa


B→ b|λ

D→ d|λ

Hola tengo este error (python): TypeError: ‘Image’ object does not support item assignment

tengo un error que no sé como solucionar: TypeError: ‘Image’ object does not support item assignment. Lo que hago es convertir un punto rgb a cmyk -> punto a un cuadrícula de 3*3 (la imagen resultante será más grande), estos puntos de la cuadrícula serán magenta, cyan, yellow, black en proporción a la cantidad de color que haya dado la conversión. No soy programador profesional, solo un gran aficionado interesado en la programación. Así que posiblemente este programa se podría mejorar totalmente, cualquier sugerencia se agradece.

from PIL import Image
from PIL import ImageColor
import cv2
import numpy as np
imagen ="tintin.jpg")#primero pasamos a RGB
rgb_imagen = imagen.convert('RGB')
width, height = rgb_imagen.size
imagen2 ="RGB", (width*3, height*3), (255,255,255,255))
matriz = ((0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0))
m = np.array(matriz)
while ( y<(height-1) ):
    while ( x<(width-2)):
       r, g, b = rgb_imagen.getpixel((x, y)) 
       k = 1.0000001-(max(r,g,b)/255)
       cyan = (1-r/255-k)/(1-k)
       magenta = (1-g/255-k)/(1-k)
       yellow = (1-b/255-k)/(1-k)
       k1=100*round(k, 2)
       cyan1=100*round(cyan, 2)
       total= (k1+cyan1+magenta1+yellow1)+0.0000001
       k2= (k1/total)*100
       cyan2= (cyan1/total)*100
       magenta2= (magenta1/total)*100
       yellow2= (yellow1/total)*100
       while (i!=9):
             if (cyan4!=0):
                m(i)= (0,255,255); cyan4=cyan4-1; i=i+1
             if (magenta4!=0):
                m(i)= (255,0,255); magenta4=magenta4-1; i=i+1
             if (yellow4!=0):
                m(i)= (255,255,0); yellow4=yellow4-1; i=i+1
             if (k4!=0):
                m(i)= (0,0,0); k4=k4-1; i=i+1 
       print (m)        

       imagen2(x-1, y-1)=  m(1)                                       
       imagen2(x, y-1)=  m(2) 
       imagen2(x+1, y-1)= m(3)  
       imagen2(x-1, y)=  m(4) 
       imagen2(x+1,y)= m(5)   
       imagen2(x, y)=  m(6) 
       imagen2(x-1, y+1)=  m(7)   
       imagen2(x, y+1)=  m(8) 
       imagen2(x+1, y+1)=  m(9)  
    y=y+1"cmyk_aprox.gif") ````

javascript – What is the expected performance of While loops using `array.pop()` assignment vs other methods

Recently I was asked to refactor some code that leverages JavaScript’s array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some JavaScript array iteration performance benchmarks, to help me validate various approaches. I wanted to know what the fastest way to reduce an array would be, but I don’t know if I can trust the initial results:
enter image description here
enter image description here
enter image description here

I added the test cases for “while loop array.pop() assignments” to the benchmarks linked above (mostly for the fun of it) but I think there must be something wrong with the tests. The variation in ops/sec seem to large to be accurate. I fear that something is wrong with my test case as I don’t understand why this method would be so much faster.

I have researched this quite a bit and have found a lot of conflicting information from over the years. And I want to better understand what specificity is causing the high variance measured in the benchmark tests linked above. Which leads to this post: How would you expect the following benchmark test cases to compare?

//Benchmark Setup
var arr = ();
var sum = 0; //set to 0 before each test
for (var i = 0; i < 1000; i++) {
  arr(i) = Math.random();
// Test Case #1
// While loop, pop assignment, inlined code
var current;
while (current = arr.pop()) {
  sum += current;
// Test Case #2
// Reverse loop, implicit comparison, inlined code
for ( var i = arr.length; i--; ) {
    sum += arr (i);


In response to the downvotes.
I want this post to be useful. I am adding images to provide context for the links. I removed unnecessary details and refined the content to focus on the questions I am seeking answers for.

macbook pro – External HD: The partition assignment check failed because no slices were found. (-69770)

Please help!

Hello, I no longer know what to do to access my external hard drive.

This is the error I get when I try to run First Aid in Disk Utility:

Run first aid on "WD My Passport 25E2 Media" (disk2)
Check requirements
Check the partition list
Partition mapping issues have been identified that may prevent booting
The partition mapping check failed because no slices were found. : (-69770)
Operation failed …

What can I do?

I have a MacBook Pro mid 2014 with Catalina 10.15.14

Thank you very much

linear programming – Gaussian elimination: check an assignment

This question is similar to the question of whether a row is in the area of ​​a matrix

Suppose I have a matrix $ M $ over $ GF (2) $ with lines that represent a system of linear equations:

A x or B x or C = 1

A x or B x or D = 1

X xor A xor Z = 0


The system has a variety of solutions. For a specific assignment via a subset of the variables, I would like to know whether there are solutions that contain this assignment or not (for example {A = 0, D = 1}).

One way to do this is to assign the variables and eliminate the simplified matrix to check whether there are still solutions or not.

Now I want to review an enormous number of tasks and the matrix is ​​large. If I calculate the reduced row-level shape of the original matrix, is there an algorithm to test assignments without changing the matrix?

Find the values ​​of the largest key of an assignment

I have an association:

1->{1,5,10,50,100}, 2->{2,4,6,9,11,15,20,40,51,55,60,90}, 3->{3,7,12,14,16,19,21,25,30,41,45,52,54,56,59,61,65,70,91,95}, 4->{8,13,17,22,24,26,29,31,35,42,44,46,49,53,57,62,64,66,69,71,75,80,92,94,96,99}, 5->{18,23,27,32,34,36,39,43,47,58,63,67,72,74,76,79,81,85,93,97}, 6->{28,33,37,48,68,73,77,82,84,86,89,98}, 7->{38,78,83,87}, 8->{88}

I want the value of the largest key, i.e. H. 8, from the above assignment, d. H. 88. Is there any way to do this?

Automatic assignment of materials when importing FBX from Blender to Unreal

I have a model in Blender and have assigned placeholder materials to its faces. I can export it from Blender to FBX and import it into Unreal Editor. After importing the mesh, I can manually assign unreal materials to it in the Unreal Editor.

Is there a way to do this automatically? I tried to name my materials in Blender the same as in Unreal, but it didn't seem to work.

List manipulation – efficient assignment of numbers

I wonder about possible techniques to efficiently solve the following problem in Mathematica. For example, suppose you get a list of integers that represent digits in a base 40 number. This list should be translated into digits with base 253, ie every 3 digits with base 40 should be translated into 2 digits with base 253. A simple solution is as follows.

l = RandomInteger({0, 39}, 10000000);
Flatten@Map(IntegerDigits(#, 253) &, 
            Map(FromDigits(#, 40) &,
                Partition(l, 3, 3, {1, 1}, {}))); // AbsoluteTiming
{5.16098, Null}

As an additional complication, it is believed that the digits with base 253 should be permuted according to a given permutation f. This can also be easily solved by

MapIndexed((f(#2((1))) = #1) &, RandomSample(Range(0, 252)));
Map(f(#) &,
    Flatten@Map(IntegerDigits(#, 253) &, 
                Map(FromDigits(#, 40) &, 
                    Partition(RandomInteger({0, 39}, 10000000), 3, 3, {1, 1}, {})))); // AbsoluteTiming
{7.46978, Null}

How can performance be improved in both cases?

python 3.x – UnboundLocalError: Local variable & # 39; ACE & # 39; which is referenced before the assignment

I don't know how to solve it, I'm trying to create an acceleration system. Arcade and an API that I use and little known

import arcade
import os


SCREEN_TITLE = "Move Sprite with Keyboard Example"

ACE = 0

class Player(arcade.Sprite):

    def update(self):
        self.center_x += self.change_x
        self.center_y += self.change_y

        if self.left < 0:
            self.left = 0
        elif self.right > SCREEN_WIDTH - 1:
            self.right = SCREEN_WIDTH - 1

        if self.bottom < 0:
            self.bottom = 0
        elif > SCREEN_HEIGHT - 1:

class MyGame(arcade.Window):
    Main application class.

    def __init__(self, width, height, title):

        # Call the parent class initializer
        super().__init__(width, height, title)

        # Set the working directory (where we expect to find files) to the same
        # directory this .py file is in. You can leave this out of your own
        # code, but it is needed to easily run the examples using "python -m"
        # as mentioned at the top of this program.
        file_path = os.path.dirname(os.path.abspath(__file__))

        # Variables that will hold sprite lists
        self.player_list = None

        # Set up the player info
        self.player_sprite = None

        # Set the background color

    def setup(self):
        """ Set up the game and initialize the variables. """

        # Sprite lists
        self.player_list = arcade.SpriteList()

        # Set up the player
        self.player_sprite = Player(":resources:images/animated_characters/female_person/femalePerson_idle.png", SPRITE_SCALING)
        self.player_sprite.center_x = 50
        self.player_sprite.center_y = 50

    def on_draw(self):
        Render the screen.

        # This command has to happen before we start drawing

        # Draw all the sprites.

    def on_update(self, delta_time):
        """ Movement and game logic """

        # Call update on all sprites (The sprites don't do much in this
        # example though.)

    def on_key_press(self, key, modifiers):
        """Called whenever a key is pressed. """
        ACE += 1

        if key == arcade.key.UP:
            self.player_sprite.change_y = MOVEMENT_SPEED
        elif key == arcade.key.DOWN:
            self.player_sprite.change_y = -MOVEMENT_SPEED
        elif key == arcade.key.LEFT:
            self.player_sprite.change_x = -MOVEMENT_SPEED
        elif key == arcade.key.RIGHT:
            self.player_sprite.change_x = MOVEMENT_SPEED

    def on_key_release(self, key, modifiers):
        """Called when the user releases a key. """

        if key == arcade.key.UP or key == arcade.key.DOWN:
            self.player_sprite.change_y = 0
        elif key == arcade.key.LEFT or key == arcade.key.RIGHT:
            self.player_sprite.change_x = 0

def main():
    """ Main method """

if __name__ == "__main__":