Code for a programming of python lists

In the python list, the name contains these names:

Name =[“zam”,”tam”,”pam”]

How to get an exit like this
Zam
Zam
Zam
Tam
Tam
Tam
Pam
Pam
Pam
And also like that
Zam
Tam
Pam
Zam
Tam
Pam …
Without using multiple printing instructions?

Merging two sequences ordered in linear programming.

Given two sequences of integers. $ a_1, dots, a_t $ Y $ b_1, dots, b_m $ every $> 0 $ where $ a_i <a_ {i + 1} $ Y $ b_i <b_ {i + 1} $ Is there a linear program to merge in orderly sequence without integer variables?

Related: Classification as a linear program.

programming challenge – Euler Project Problem # 14 largest Collatz sequence written in Python

Problem Statement:
The following iterative sequence is defined for the set of positive integers:

n → n / 2 (n is even)
n → 3n + 1 (n is odd)

Using the previous rule and starting with 13, we generate the following sequence:

13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
You can see that this sequence (starting at 13 and ending at 1) contains 10 terms. Although it does not have
still tested (Collatz problem), it is thought that all the initial numbers end in 1.

What initial number, less than one million, produces the longest chain?

NOTE: Once the string starts, the terms can go over a million.
Here is my implementation written in Python, waiting for your comments.

from the time of import
from the operator import itemgetter


def collatz_count (n, count = {1: 1}):
"" "use cache (account) to speed up the search, return the sequence
length for the given number "" "
try:
return count[n]
    except KeyError:
if n% 2 == 0:
tell[n] = collatz_count (n / 2) + 1
plus:
tell[n] = collatz_count (n * 3 + 1) + 1
return count[n]


def run_test ():
"" "uses the previous function, returns the number generated by the
Major sequence "" "
time1 = time ()
articles = ordered ([(x, collatz_count(x)) for x in range(1, 1000000)],
key = itemgetter (1), reverse = True)
maximum = articles[0]
    print (f & # 39; Initial number: {maximum[0]}  n sequence length:
{maximum[1]}  n & # 39;
f & # 39; Calculated in: {time () - time1} seconds. & # 39;)


yes __name__ == & # 39; __ main __ & # 39;
run_test ()

programming challenge – Euler Project, problem # 9, Pythagoras triplet

A triplet of Pythagoras is a set of three natural numbers, a <b <c, for which, a ** 2 + b ** 2 = c ** 2

For example, 3 ** 2 + 4 ** 2 = 9 + 16 = 25 = 52.

There is exactly one triplet of Pythagoras for which a + b + c = 1000. Find the product abc.

Here is my implementation in Python, waiting for your comments …

def get_triplet ():
for c in range (2, 1000):
for b in rank (2, c):
a = 1000 - c - b
if a ** 2 + b ** 2 == c ** 2:
returns & # 39; n1 =% s  n n2 =
% s  n n3 =% s  n product =% s & # 39;% (a, b, c, a * b * c)




yes __name__ == & # 39; __ main __ & # 39;
print (get_triplet ())

Linear programming: Why does not my code correctly complete the augmented matrix?

I'm trying to enter data from a training file. He's skipping the first row altogether.

                double ** augmentMatrix (double ** matrix, int dim) {
double ** identityMatrix = CreateIdentityMatrix (dim, dim); // create identity matrix

double ** augmentedMatrix = (double **) malloc (sizeof (double *) * dim);
for (int row = 0; row <tenue; row ++) {
increased matrix[row] = (double *) malloc (sizeof (double) * dim * 2);
} // attribute space

for (int row = 0; row <tenue; row ++) {
for (int col = 0; col <dim; col ++) {
increased matrix[row][col]    = matrix[row][col]; // set the first part of the matrix augmented to the parameters of the matrix parameter
}
for (int col = dim; col <2 * dim; col ++) {
increased matrix[row][col]    = identityMatrix[row][col - dim]; // separates the identity matrix
}
}
printMatrix (augmentedMatrix, dim, dim * 2);
return augmentedMatrix;
}

This is what is producing:

                0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,
26.2, 84.8, 61.9, 58900.0, 51789.8, 0.0, 1.0, 0.0, 0.0, 0.0,
6493.8, 19487.8, 12220.3, 9864262.5, 12861241.2, 0.0, 0.0, 1.0, 0.0, 0.0,
21384.0, 70762.0, 55533.2, 57206075.0, 42298973.0, 0.0, 0.0, 0.0, 1.0, 0.0,
19713.0, 61172.0, 41552.0, 39621035.0, 38865313.0, 0.0, 0.0, 0.0, 0.0, 1.0,

Here is the training data file:

                18.0, 55.0, 37.0, 33025.0, 35598.0,
26.2, 84.8, 61.9, 58900.0, 51789.8,
6493.8, 19487.8, 12220.3, 9864262.5, 12861241.2,
21384.0, 70762.0, 55533.2, 57206075.0, 42298973.0,
19713.0, 61172.0, 41552.0, 39621035.0, 38865313.0, 

Programming: how to run a specific cell in a notebook from another notebook

I have a long Mathematics Code in a notebook, denoted by NB1. Since it is a very long code, and I just need some of the results of NB1 to be used in another laptop indicated by NB2, I assigned Mobile Tags to those cells NB1 that generate the outputs required by NB2. I like to know how to remember the cells labeled in NB1 in NB2.

I know how to run NB1 while it is in NB2, but I do not want to execute all the operations in NB1 since I only need a subset of the outputs of NB1.

Here is an example of NB1:

Clear[Evaluate[Context[] <> "*"]];
Clear[n, d, G, transfer, absorption, info, capParam, infoStock, 
edgeCapacityMat, infoStocks, system, reducedSystem, sa, wG];

SeedRandom[14];
n = 6;
d = 0.3;
G = RandomGraph[{Round[n], Round[n*(n - 1)*d]}, DirectedEdges->
True];

transfer = Table[t[i], {i, 1, n}]; (* transfer capacity *)
absorption = table[a[i], {i, 1, n}]; (* Absorption capacity *)
info = table[x[i], {i, 1, n}]; (* information stock capacity *)

(* parameterization *)
capParam = Table[{t[i] -> RandomReal[], a[i]-> RandomReal[]}
{i, 1, n}]//Flatten;
infoStock =
Table[x[i] -> RandomInteger[{1, 10}], {i, 1, n}]//Flatten;

edgeCapacityMat[transferCap_, 
absorptionCap_] : = (# - DiagonalMatrix[Diagonal[#]]) &[
KroneckerProduct[transferCap, absorptionCap]];
InfoStocks[stock_] : = DiagonalMatrix[stock];
system = infoStocks[info].edgeCapacityMat[transfer, 
absorption]; (* completely defined system *)

ReducedSystem =
Adjacency matrix[G]*
system; (* the system associated with AdjacencyGraph "G" *)
sa = SparseArray[reducedSystem];
wG = Graphic[sa["NonzeroPositions"],
EdgeWeight-> sa["NonzeroValues"], DirectedEdges
-> True, VertexLabels -> "Name"];

(* Answer by @ KGLR: use this to formulate "attention
assignment problem in my work *)

Clear all[edgeW];
edgeW = Module[{g = #, 
e = DirectedEdge @@@ Partition[#, 2, 1] & / @
FindPath[##, [Infinity], Everyone]}
Transpose[{e, PropertyValue[{g, #}, EdgeWeight] & / @ # & / @
my}]]&;

desiredOutput1 = edgeW[wG, 5, 2]
desiredOutput2 = HighlightGraph[wGedgeW[wGedgeW[wGedgeW[wGedgeW[wG, 5, 2][[All, 1]]]

I like to use desiredOutput1 Y desiredOutput2 in NB2, therefore I have created two cell tags in NB1 it must be recovered from NB2, but I do not know how to recover only the two cell labels of NB2.

Thanks for your help.

design – How can you call other programming languages?

This mechanism is called an external function call. Almost all major programming languages ​​can do so, although the ease of use of an external function call differs between implementations of each language pair.

Python itself, for example, has ctypes in the standard library and a third-party library Cffi that allows you to call any C code, and other languages ​​that expose a foreign function interface similar to C (for which there is a lot). Java has JNI (Java Native Interface).

.NET CLR and Java are somewhat different, since they expose an interface by which any language that is executed in the same virtual machine can call any other language in the virtual machine, so the foreign function call from the same time of execution is generally quite simple. This is possible because those languages ​​already have to be assigned in the construction of the virtual machine anyway.

design – What are some programming languages ​​that are compiled with others?

So today I found about IronPython:

IronPython is an open source implementation of the Python programming language that is tightly integrated with the .NET Framework.

This was my first experience with the use of multiple programming languages ​​in a single program. I thought it was really cool to be able to call my Python script as a container for the compiled dll from C #.

But this made me think … how many more programming languages ​​could be attached to this? Is there a limit? What are some other programming languages ​​that have a similar feature?

c # – book to learn object oriented programming in C # _

Thanks for contributing in StackOverflow in Spanish with an answer!

  • Please, make sure answer the question. Provide information and share your research!

But avoid

  • Ask for help or clarifications, or respond to other answers.
  • Make statements based on opinions; Be sure to back them up with references or your own personal experience.

For more information, see our tips on how to write great answers.

Functional programming: refactoring an if statement into a higher order function in Swift

Using Swift, I am sorting some objects first by date order, then second by title if the date is the same, according to the following extract:

.sorted {
yes $ 0.date! = $ 1.date {
return $ 0. date <$ 1 date // object date
} else {
return $ 0.title <$ 1.title // String
}
}

This brief si / else is used several times, and as such I would like to extract this functionality and convert it into a reusable component. Any ideas or suggestions on how this can be achieved, given that the return value could be a date or a chain?