1597006800

# Smallest positive integer X satisfying the given equation

ven two integers N and K, the task is to find the smallest positive integer X satisfing the equation:

(X / K) * (X % K) = N

Examples:

Input:_ N = 6, K = 3 _

Output:_ 11 _

Explanation:

_For X = 11, (11 / 3) * (11 % 3) = 3 * 2 = 6 _

Therefore, the following equation satisfies.

Input:_ N = 4, K = 6 _

Output:_ 10 _

Explanation:

_For X = 10, (10 / 6) * (10 % 6) = 1 * 4 = 4 _

_Therefore, the following equation satisfies. _

Approach:

The idea is to observe that, since (X / K) * (X % K) = N, therefore, N will be divisible by p = X % K, which is less than K. Therefore, for all i in the range [1, K) try all values of p where:

Below is the implementation of the above approach:

• C++
• Java
• C#

// C++ Program to implement

// the above approach

#include <bits/stdc++.h>

**using** **namespace** std;

// Function to find out the smallest

// positive integer for the equation

**int** findMinSoln(**int** n, **int** k)

{

// Stores the minimum

**int** minSoln = INT_MAX;

// Iterate till K

**for** (**int** i = 1; i < k; i++) {

// Check if n is divisible by i

**if** (n % i == 0)

minSoln

= min(minSoln, (n / i) * k + i);

}

// Return the answer

**return** minSoln;

}

// Driver Code

**int** main()

{

**int** n = 4, k = 6;

cout << findMinSoln(n, k);

}

Output:

10


Time Complexity:_ O(N) _

Auxiliary Space:_ O(1)_

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

#arrays #mathematical #school programming #searching

1665369120

## CellularAutomata.jl: Cellular Automata Simulation toolkit for Julia

Cellular Automata

A cellular automaton is a collection of "colored" cells on a grid of specified shape that evolves through a number of discrete time steps according to a set of rules based on the states of neighboring cells. The rules are then applied iteratively for as many time steps as desired.

mathworld.wolfram.com/CellularAutomaton

## Elementary CA

To generate an elementary cellular automaton, use

ca = CellularAutomaton(rule, init, gen)


where rule is the Wolfram code (integer), init is a vector containing the initial starting condition and gen is the number of generations to be computed. For a single starting cell in the middle just omit the init vector.

To generate 15 generations of elementary cellular automaton of rule 90 use

using CellularAutomata

ca90 = CellularAutomaton(90, 16)

                            #
# #
#   #
# # # #
#       #
# #     # #
#   #   #   #
# # # # # # # #
#               #
# #             # #
#   #           #   #
# # # #         # # # #
#       #       #       #
# #     # #     # #     # #
#   #   #   #   #   #   #   #
# # # # # # # # # # # # # # # #


## Totalistic CA

For a more complex cellular automaton you can change the number of states k the cell can be and the radius r of neighbors that can influence the states. If k is changed to be larger than 2, a totalistic CA is computed where only the average value of all neighbors count. This can be done like this

ca = CellularAutomaton(993, 15, k=3)

                        X
XXX
X# #X
X     X
XXX   XXX
X# #X X# #X
X     #     X
XXX   ###   XXX
X# #X # X # X# #X
X      # X #      X
XXX    ## X ##    XXX
X# #X  #   X   #  X# #X
X     X### XXX ###X     X
XXX   X XX  # #  XX X   XXX
X# #X XX###X## ##X###XX X# #X


## 2 dimensional CAs

Two dimensional cellular automaton (like Conway's Game of Life) can be created by

ca = CA2d(B, S, init, gen)


where B and S are vectors that have the numbers of neighboring cells that define when cell is born or survives, init (matrix) is the initial starting condition and gen is the number of generations the CA is to be computed.

Game of life is then run for 9 generations for e.g. a turbine pattern by typing

ca = CA2d([3], [2, 3], init, 9)


1st step

   ###### ##
###### ##
##
##     ##
##     ##
##     ##
##
## ######
## ######



2nd

    ####
#    # ##
#    #   #
##    #
##    #  #
#  #   #  #
#  #    ##
#    ##
#   #    #
## #    #
####



3rd

     ##
####
# ## ## #
##  #
##  ##  ###
#### #  ###
#  #   #  #
###  # ####
###  ##  ##
#  ##
# ## ## #
####
##



4th

    #  #
#
##
# ##      #
#  #   #
#   # ###
#           #
### #   #
#   #  #
#      ## #
##
#
#  #



5th

        ##
#
###  ##
### #   #
#    # ##
# #
## #    #
#   # ###
##  ###
#
##


6th

        ##
#
# #  ##
# # ###  #
#  ######
## ##
######  #
#  ### # #
##  # #
#
##



7th

     #  # #
## # ###
#      #
##     #

#     ##
#      #
### # ##
# #  #



8th

    ## ## #
##  ## ##
#
##
##     ##
##
#
## ##  ##
# ## ##



9th

   ###### ##
###### ##
##
##     ##
##     ##
##     ##
##
## ######
## ######



## Running Tests

To run tests, execute the following command from the root folder of the repository:

julia tests/run_tests.jl

Author: Natj
Source Code: https://github.com/natj/CellularAutomata.jl

1597006800

## Smallest positive integer X satisfying the given equation

ven two integers N and K, the task is to find the smallest positive integer X satisfing the equation:

(X / K) * (X % K) = N

Examples:

Input:_ N = 6, K = 3 _

Output:_ 11 _

Explanation:

_For X = 11, (11 / 3) * (11 % 3) = 3 * 2 = 6 _

Therefore, the following equation satisfies.

Input:_ N = 4, K = 6 _

Output:_ 10 _

Explanation:

_For X = 10, (10 / 6) * (10 % 6) = 1 * 4 = 4 _

_Therefore, the following equation satisfies. _

Approach:

The idea is to observe that, since (X / K) * (X % K) = N, therefore, N will be divisible by p = X % K, which is less than K. Therefore, for all i in the range [1, K) try all values of p where:

Below is the implementation of the above approach:

• C++
• Java
• C#

// C++ Program to implement

// the above approach

#include <bits/stdc++.h>

**using** **namespace** std;

// Function to find out the smallest

// positive integer for the equation

**int** findMinSoln(**int** n, **int** k)

{

// Stores the minimum

**int** minSoln = INT_MAX;

// Iterate till K

**for** (**int** i = 1; i < k; i++) {

// Check if n is divisible by i

**if** (n % i == 0)

minSoln

= min(minSoln, (n / i) * k + i);

}

// Return the answer

**return** minSoln;

}

// Driver Code

**int** main()

{

**int** n = 4, k = 6;

cout << findMinSoln(n, k);

}

Output:

10


Time Complexity:_ O(N) _

Auxiliary Space:_ O(1)_

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

#arrays #mathematical #school programming #searching

1585723009

Appdupe offers the leading rental app development services to help you in launching your own Airbnb for business at affordable prices. You can rent anything, ranging from cars to music studios. Develop an app, and you’re all set to reach your target market. Reach out to us to know more.

#airbnb for x #airbnb for x app #airbnb for x script #rental app development #airbnb for x app development

1630996646

## ECMAScript class static initialization blocks

Class static blocks provide a mechanism to perform additional static initialization during class definition evaluation.

This is not intended as a replacement for public fields, as they provide useful information for static analysis tools and are a valid target for decorators. Rather, this is intended to augment existing use cases and enable new use cases not currently handled by that proposal.

## Status

Stage: 4
Champion: Ron Buckton (@rbuckton)

For detailed status of this proposal see TODO, below.

## Authors

• Ron Buckton (@rbuckton)

Motivations

The current proposals for static fields and static private fields provide a mechanism to perform per-field initialization of the static-side of a class during ClassDefinitionEvaluation, however there are some cases that cannot be covered easily. For example, if you need to evaluate statements during initialization (such as try..catch), or set two fields from a single value, you have to perform that logic outside of the class definition.

// without static blocks:
class C {
static x = ...;
static y;
static z;
}

try {
const obj = doSomethingWith(C.x);
C.y = obj.y
C.z = obj.z;
}
catch {
C.y = ...;
C.z = ...;
}

// with static blocks:
class C {
static x = ...;
static y;
static z;
static {
try {
const obj = doSomethingWith(this.x);
this.y = obj.y;
this.z = obj.z;
}
catch {
this.y = ...;
this.z = ...;
}
}
}


In addition, there are cases where information sharing needs to occur between a class with an instance private field and another class or function declared in the same scope.

Static blocks provide an opportunity to evaluate statements in the context of the current class declaration, with privileged access to private state (be they instance-private or static-private):

let getX;

export class C {
#x
constructor(x) {
this.#x = { data: x };
}

static {
getX = (obj) => obj.#x;
}
}

return getX(obj).data;
}


## Relation to "Private Declarations"

The Private Declarations proposal also intends to address the issue of privileged access between two classes, by lifting the private name out of the class declaration and into the enclosing scope. While there is some overlap in that respect, private declarations do not solve the issue of multi-step static initialization without potentially exposing a private name to the outer scope purely for initialization purposes:

// with private declarations
private #z; // exposed purely for post-declaration initialization
class C {
static y;
static outer #z;
}
const obj = ...;
C.y = obj.y;
C.#z = obj.z;

// with static block
class C {
static y;
static #z; // not exposed outside of class
static {
const obj = ...;
this.y = obj.y;
this.#z = obj.z;
}
}


In addition, Private Declarations expose a private name that potentially allows both read and write access to shared private state when read-only access might be desireable. To work around this with private declarations requires additional complexity (though there is a similar cost for static{} as well):

// with private declarations
class C {
#z = ...; // only writable inside of the class
get #zRead() { return this.#z; } // wrapper needed to ensure read-only access
}

// with static
class C {
#z = ...; // only writable inside of the class
static { zRead = obj => obj.#z; } // callback needed to ensure read-only access
}


In the long run, however, there is nothing that prevents these two proposals from working side-by-side:

private #shared;
class C {
static outer #shared;
static #local;
static {
const obj = ...;
this.#shared = obj.shared;
this.#local = obj.local;
}
}
class D {
method() {
C.#shared; // ok
C.#local; // no access
}
}


Prior Art

Syntax

class C {
static {
// statements
}
}


Semantics

• A static {} initialization block creates a new lexical scope (e.g. var, function, and block-scoped declarations are local to the static {} initialization block. This lexical scope is nested within the lexical scope of the class body (granting privileged access to instance private state for the class).
• A class may have any number of static {} initialization blocks in its class body.
• static {} initialization blocks are evaluated in document order interleaved with static field initializers.
• A static {} initialization block may not have decorators (instead you would decorate the class itself).
• When evaluated, a static {} initialization block's this receiver is the constructor object of the class (as with static field initializers).
• It is a Syntax Error to reference arguments from within a static {} initialization block.
• It is a Syntax Error to include a SuperCall (i.e., super()) from within a static {} initialization block.
• A static {} initialization block may contain SuperProperty references as a means to access or invoke static members on a base class that may have been overridden by the derived class containing the static {} initialization block.
• A static {} initialization block should be represented as an independent stack frame in debuggers and exception traces.

Examples

// "friend" access (same module)
let A, B;
{
let friendA;

A = class A {
#x;

static {
friendA = {
getX(obj) { return obj.#x },
setX(obj, value) { obj.#x = value }
};
}
};

B = class B {
constructor(a) {
const x = friendA.getX(a); // ok
friendA.setX(a, x); // ok
}
};
}


References

TODO

The following is a high-level list of tasks to progress through each stage of the TC39 proposal process:

### Stage 1 Entrance Criteria

• Prose outlining the problem or need and the general shape of a solution.
• Illustrative examples of usage.
• High-level API.

### Stage 4 Entrance Criteria

For up-to-date information on Stage 4 criteria, check: #48

• Test262 acceptance tests have been written for mainline usage scenarios and merged.
• Two compatible implementations which pass the acceptance tests:
• A pull request has been sent to tc39/ecma262 with the integrated spec text.
• The ECMAScript editor has signed off on the pull request.

Author: tc39
The Demo/Documentation: View The Demo/Documentation