ReplaceAll with pattern matching not working with list of lists

Abstract This is just a learning exercise for me. I am trying to create a function that will take a list of vectors, multiply them by a constant if constant is given, and then add all vectors. If we have no constants then the list looks like this: {list1, list2,...}. However if we want to scale one or more vectors the list would look like this: {{c1,list}, {c2,list}}. I can get it to work with one list whether it has a constant or not but not for a list of lists.

u = {1, -2}; v = {2, -5}; c1 = 4; c2 = -3; vec1 = {u, c1}; vec2 = {c2, v}; ReplaceAll[{vec1, vec2}, {x_List, c_} -> c  x] (* gives wrong values *) vec1 /. {x_List, c_} -> c*x (* this works but not if x_List and c_ reordered *) {c1*u, c2*v} (* this is the value I am seeking *) 

Would it be balanced to increase the Spell Level of Hypnotic Pattern?

To me, Hypnotic Pattern seems quite strong for a 3rd Level Spell. The main reason I think so is that it can affect a huge number of targets, and a creature that fails the saving throw will not get another chance and may very well be taken out of the picture for almost the entire combat encounter.

I’m aware of two of the spell’s relative weaknesses. First, a creature can only be affected once when the spell is cast (other than with the 2nd Level Spell Web), even though the spell still requires concentration. Second, the apparent effectiveness against large groups of creatures is somewhat reduced by the fact that some creatures will usually succeed on the saving throw and will wake up others. On the other hand, this requires their action, so one might in fact argue that this makes the spell even better for the first round of combat.

All these things considered, I’m wondering if it would be balanced (possibly even more balanced) if Hypnotic Pattern were moved to Level 4. Or am I missing something?

Pattern matching on function application

Suppose we have a function f :: a -> b and a function g :: b -> a such that f . g = id. You might say that g is the “inverse” of f (and vice versa). Could we then pattern match on something like f x on the left hand side by replacing occurences of x with g x on the right hand side? For example:

-- Here, (- 3) is the "inverse" of (+ 3), or more generally, (- n) is the "inverse" of (+ n)  subtractThree (x + 3) = x subtractThree x = (x - 3) 

This just randomly came to my mind and I’m wondering if there is something fundamentally wrong with this.

Edit: This is my first post here and I’m unsure whether this is the right kind of question for this community. Please don’t hesitate to close this if this doesn’t belong here.

Pattern Matching Algorithm in Java

I have to write an algorithm that solves below problem statement – –There is a project requirement which has list of titles (Developer, Java Developer,C++ Developer) applicable.

–There is a list of applicants who have titles like (Java Engineer , Software Developer).

Which algorithm can be used to find list of applicants that closely match the requirement?

Thank you!

What are the properties of a pattern?

I wonder if a pattern may contain variable parts.

A pattern with a variable part

Supposing the above picture is a pattern, then, in this case, it may match several pictures having a common part (the constant part). Can a pattern have variable parts? If not, which properties are incompatible? If yes, is the pattern still conceptually valid?

I ask the question because in practice, an expression may be matched against a pattern which have a variable part (unknown elements). However, in my opinion, it may lead to obfuscation if the constituents in the pattern have unspecified types.

Concretely, the variable part can be a pointer to an object of any type and the constant part be composed of objects of fixed types.

What is the correct pattern to DeleteCases from a list?

I’m trying to get better with pattern matching but even after years of using MMA it’s still a murky concept. The docs are actually pretty good in this regard but I still struggle. In this situation I have a list of real estate items (that are strings) which I’m trying to clean up. I’ve tried the below to methods and have not been able to delete the “HVAC” elements required from this list.

DeleteCases[featureList, StringContainsQ [#,"HVAC"] & ] 

and

DeleteCases[featureList, __~~"HVAC"~~__] 

Both return the same list back:

{ML #,Property Type,SubSpcSqFt,Land Sz SF,Building Type,List Date,Yr Blt,Address,Area,Class,Clear Ceiling Ht (Feet),Lot Frontage (ft),Lot Depth (ft),Zone,Price,Sale Type,Transaction Type,Zoning/Land Use,Amenities-HVAC System,Building Type-Freestanding,HVAC-See Realtor Remarks,HVAC-Baseboard,HVAC-Central A/C,HVAC-Common Water Heater,HVAC-Electric,HVAC-Forced Air,HVAC-Heat Pump,HVAC-Hot Water,HVAC-In-Floor,HVAC-Make-Up Air,HVAC-Mixed,HVAC-None,HVAC-Radiant,HVAC-Rooftop,HVAC-Separate Controls,HVAC-Separate HVAC Units,HVAC-Separate Water Heaters,HVAC-Space Heaters,HVAC-Steam,HVAC-Window A/C} 

What is the correct what to filter out any string containing “HVAC”?

How to defend against network traffic pattern correlation attacks?

If i am chaining multiple VPN’s and possibly running through Tor as well, network correlation attacks can be performed against me to try to locate my position. If my network spikes a download for 40MB/s for 3 secounds, governments with collectors accross the world would be able to see this spike and correlate me with my VPN chains.

Is there a way to defend against this?

I would assume if a tool was made to generate random dummy traffic each at layer of VPNs, then they would not be able to correlate as well. Does such a tool exists?

Replace pattern with the number of matches so far

I want to replace a n-th pattern match in an expression with n. This is a very simple task, though it appears very hard to find an elegant implementation.

For example, with input

inp = {x, y, z, x, y, x, x, z} 

I wish to compute, replacing pattern x,

{1, y, z, 2, y, 3, 4, z} 

Preferably, I’d like to access the index n in the replacement rule. E.g. something like

Func[inp, x :> Symbol[m<>ToString@#]& ]  >>> {m1, y, z, m2, y, m3, m4, z} 

How can I achieve this? It’s trivial using Count and a For loop, but is very un-stylistic.

Proving a pattern exist in a string without revealing where

Some time ago i read the following problem (i don’t remember the article from which i read it from) :

“Suppose you are given a picture where the goal is to find waldo (from the game where is waldo), you search for a bit and don’t find him so you become suspicious of the fact that waldo actually is in the picture, how can one prove to you that waldo indeed is without revealing where ? Well one can just take a very big sheet of paper, bore a hole inside it and place this sheet of paper on top of your picture so that waldo’s head appears inside the hole.”

My question is how could one transfer this idea to a mathematical concept ? One idea would be something along the lines of :

  • Let L be some language in complexity class C

  • given $ a_1 , a_2 , … a_n$ can one prove to you that there is a $ i$ for which $ a_i \in L$ without revealing for which $ i$ it stands

However this falls short as it stands right now because one can just feed the same input $ a$ n times for which it wishes to know appartenance to class L. So we either need to consider specific complexity class C for which the problem becomes interesting or loosen the condition of “non disclosure”, and it doesn’t seem that obvious. Or we could just change paradigm, my question is just how to convert the waldo idea to a computationnal model, i suspect the approach i gave isn’t the right one.

Password Pattern in ML

Trying to figure out the patterns of passwords. I’m new to ML, but was inspired by PassGan, a ML tool that generates sample passwords. The likelihood is low enough that it’s not very useful for password cracking, but I’d like to take the technique and use it for password discovery.

My intention is to train a model to understand what a password is, then compare that against words found on services (Slack, File Shares, etc.) to detect instances of people being sloppy and leaving passwords where they shouldn’t be.

My core assumptions are that passwords are far from random, and if analyzed appropriately many share a common pattern(s). This pattern could be used to identify and hopefully eradicate poor operational security practices.

Ideally, I’d like to choose something that evaluates words and provides a probability of that word being a password, then given the likely hood, I could have the application make some kind of a decision.

Is there an algorithm or model that works well for this kind of task? It’s single dimensional data, I’d assume unsupervised learning is really the only approach.