Â

Just don’t laugh.

Skip to content
# Category: Uncategorized

# Stable Marriage problem

# Rotating a 2D Array by 90 Degrees (Java)

# Data Structure: How to Implement the stack using two queues?

# PONG+ JAVASCRIPT

### PLAYÂ Pong Plus

#### Basic features:

#### Advanced features:

#### Music License:

# Prime number algorithm

##### Run theÂ ScriptÂ in CodeSkulptor

# Python Game:

#### Games:

#### Play 2048

#### Play Space Shooter

#### Play Black Jack

# Simple Automation for Maya Rendering

I am an Artist, Mathematics Enthusiast, and Code Geek. But not a Nerd đ

Â

Just don’t laugh.

Implement a function that takes aÂ **square**Â 2D array (#Â columns = #Â rows = n) and rotates it by 90 degrees. Do not create a separate 2D array for the rotation, it rotates in the 2D array.

Example:

```
int a1[][] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
Â // rotate(a1, 3) should return:
// [[7, 4, 1],
// [8, 5, 2],
// [9, 6, 3]]
```

Example:

```
Â int a2[][] = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}};
Â // rotate(a2, 4) should return:
// [[13, 9, 5, 1],
// [14, 10, 6, 2],
// [15, 11, 7, 3],
// [16, 12, 8, 4]]
```

To understand this problem, we need to analyzeÂ what is really going on in the rotation.

**a.**Â each element in the rotationÂ is changing position with 3 other elements in the 2D array: a->b, b->c, c->d, d->a

[?, a, ?, ?] [?, ?, ?, b] [d, ?, ?, ?] [?, ?, c, ?]

If a={i,j}, then b={j,n-1-i}, c={n-1-i, n-1-j},d={n-1-j,i}

**b.**Â In each rotation happens in aÂ “ring” (example, a1, a2, a2, b1, b2 ….d2, d2), we only swap the positions ofÂ n-2Â elements in the first row. We do not swape n-1th element again because it is a duplicate (We swapped a1 with b1, and b1 does not need to be swappedÂ again. So we only swap a1, a2, a3. ).

[a1, a2, a3, b1] [d3, ??, ??, b2] [d2, ??, ??, b3] [d1, c3, c2, c1]

So the outer loop should beÂ **for (int i=0; i < n-1; i++)**:

**c.**Â We swap the positions from the outside ring (1’s) to the inner rings (2’s). Each time the iteration decrements by 2 elements. At **ith** row, we swap from **ith** element to **n-2-**i th elements.

[1, 1, 1, 1] [1, 2, 2, 1] [1, 2, 2, 1] [1, 1, 1, 1]

So the inner loop isÂ **for (int j=i; j<n-1-i; j++)**

Put everything together:

public static int[][] rotate(int[][] a, int n) { for (int i=0; i< n-1; i++){ for (int j=i; j<n-1-i; j++){ int temp = a[i][j]; a[i][j] = a[n-1-j][i]; a[n-1-j][i] = a[n-1-i][n-1-j]; a[n-1-i][n-1-j] = a[j][n-1-i]; a[j][n-1-i] = temp; } } return a; } }

Pop Efficient:

- Push(x):
- Enqueue x on q2
- Enqueue each elements on q1 on to q2
- Switch names between q1 and q2

- Pop():
- Dequeue from q1.

Push Efficient:

- Push(x):
- Enqueue x on q2

- Pop():
- Dequeue each element except the last element from q2 to q1.
- Dequeue the last element on q2.
- Switch names between q1 and q2.

**Health Bars**: Each time player fails to reflect a ball, the health bar decreases in length. If the health reaches zero, the game is over.**POW bars**: It allows the player to use Power Ups, such as Bubble Shields and Rainbow Shots. Each use of the Power Ups consumes a certain amount of POWs.**Slippery Paddles**: Paddles do not stop immediately if the player stops pressing UP/Down buttons. The paddles decelerate and cushion in. This feature makes the paddles harder to control and challenges players to plan the moves ahead.**The ball**: The ball will shoot from the center with a random color, size, speed, and angle.**Sound**: added sound effects and music (Enjoy it!).

**Bubble Shield**: Players can consume POWs to generate a bubble shield. It reflects the balls back.**Rainbow Shot**: Players can consume POWs to activate the paddles into rainbow mode. Any ball hits a paddle with rainbow mode will be reflected and move at a doubled speed.**Reflection**: Balls will bounce back from each other.**Exchange of Momentum**: If a rainbow ball hits a normal ball, they will exchange the momentum. Meaning the normal ball will become a rainbow ball and vice versa.**Particles**: A particle system is built in this game. If a ball hits the left or right boundary, it will explode and generate a particle cluster, like fireworks.

RoccoW_-*07*-_Fuck_Sidechain_Compression_on_Gameboy.mp3

ăăăł by RoccoW is licensed under a Attribution-ShareAlike License.

Based on a work athttps://roccow.bandcamp.com/album/-

Permissions beyond the scope of this license may be available atwww.soundcloud.com/roccowor contact artist via email.

**1 st method (very inefficient):**

get value for an number n

if n =2, output âIt is a prime numberâ

set the value i =2;

set the value isPrime = True;

if i if n % i == 0, isPrime=False;

else i + 1;

output âIt is a prime numberâ if isPrime is true

output âIt is a not prime numberâ if isPrime is False.

The above method is inefficient. If the input is a very big prime number, it will make division from 2 all the way to n-1.

**2nd method (slightly faster):**

If :

an integer x < another integer n,

ân % x != 0 (n is not divisible by x )

then: nÂ˛ % x !=0 (nÂ˛ is not divisible by x)

Vise versa, n % x == 0, then nÂ˛ % x ==0 ;

So, we can implement the 1st method, by looping only from 2 to n. we just have to modify the above algorithm âi<nâ into âi<ânâ. it optimized (n ) algorithm into (ân) algorithm.

**3rd method (Sieve of Eratosthene):**

This method works when given a number n and get all the prime numbers that is smaller than n. It filters out all the composite numbers, and left the prime number.

It works in this way:

- given a number n,
- in the range of 2 to n, find the prime number one by one.
- the first prime number is 2, then filter out all the numbers that is multiple of 2.
- find the next prime number, which is 3, and filter out all the multiples of 3.
- find the next prime number 5, and filter out all the multiples of 5.
- continue the above process. until the searched prime number reaches n.

- output all the remaining numbers.

The pseudo code would be:

- given a number n, n>1
- define a list IsPrime[], indexed from 2 to n, initially all items are set to True
- i start from 2, if i < n, repeat the following steps:

if IsPrime[i] == true:

set IsPrime[ i2, i2+i, i2+2i, i2+3i, …] to False (not exceeding n)

Â Â Â 4.output the indices in IsPrime[] âs item that is true.

I used CodeSkuptor. It allows Python scripts toÂ run on the commonly used browser. Click the upper left “Run” button to start the games. (Â CodeSkulptor runs in Chrome 18+, Firefox 11+, and Safari 6+)

——————————————————————

——————————————————————

Maya Batch Render doesn’t allow user to render multiple shots with one click. What ifÂ I want to let the computer create a render queue and automate the rendering process? You may installÂ backburnerÂ to solve this. or there is another simple way of doing so without setting up the Manager and Server.

First of all, createÂ a .bat file from Windows desktop.

The Template is like this:

C:\Progra~1\Autodesk\Maya2014\bin\render -r file -s <starting_frame>Â -e <ending_frame>Â -cam <camera>Â -rd “<render_location>” “<maya_file_directory>”

here under are the possible settings that you can modify

-r file: render from scene setting.

-s : starting frame

-e: ending frame

-cam: camera Name

-rd: where you want to save rendered image / where is the maya file.

For more info for rendering command, refer to this link.