## 8 – How can I extend the webform #states conditions to save a custom set of conditions for webform fields?

I need to store sets of conditions on the webform field level (these would then be evaluated according to the field’s submitted values within a custom submit callback).

I would like these conditions to be editable on the webform field level just like #states conditions that honour the field type for value ranges, set values, boolean etc:

No new custom state is necessarily needed here as this new type of condition would not be related to interacting fields. I’m merely looking for a way to expand webforms and add a custom field to each element that will allow adding (on the UI) sets of conditions based on its value(s). These sets would be part of the field’s properties and accessible in a validation / submit callback.

## Determine the number of reachable states in a subset construction?

Is there a method to determine the number of reachable states in the subset construction of a NFA to a DFA without having to construct the entire DFA?

## security – Threat probability? 1 state controls >70% of miners. Other states go to war with them

This is almost certainly a silly question, but there are a lot of new bitcoin owners like me and a specific threat was made today which sounds credible to those of us who lack deep knowledge of bitcoin.

The specific threat is this one:

1: China controls 70% of the miners. SOURCE

2: They are using Hydroelectric and Nuclear Power reactors to do this. SOURCE

3: The United States (and allies) are seeking to destroy bitcoin in a war with China.

4: Bitcoin will go to 0 and US regulated coins will survive. SOURCE

So it’s kind of 2 threats rolled into 1 and I’m trying to come up with a “probability of threat number” to determine if I should even devote time to considering this.

My guess is that the probability is less than 1% but it’s just a guess and I have a high amount of uncertainty due to my current depth of knowledge.

Again, please forgive the silliness of the question, but any assistance to help improve my confidence that the threat is not to be taken seriously would be appreciated.

## curated data – How to determine population from a list of arbitrary jurisdictions (cities, states, counties, et al.)?

I am an aspiring data scientist who’s working on a passion project, namely to assign danger-level scores to police departments in the United States.

One specific metric I’m developing results from analyzing data on fatal encounter incidents with police since 2000, including the name of the specific agency involved in the death(s), which I’ve imported as strings, stripped of qualifiers like “Police Department” (among others), and arranged into a list called `dept`.

For example, take the first element of the list, “Mendocino County Sheriff’s Office”, which then becomes “Mendocino County”, the geographic area I want to know the population of. This is simple enough with semantic interpretation, i.e.,

``````jurisdiction = SemanticInterpretation(dept((1)))

"UnitedStates"}) *)
``````

To get the population:

``````population = AdministrativeDivisionData(jurisdiction, "Population")

(* output: 87649 people *)
``````

From here it’s trivial to calculate my “danger” index for that department and expand to do the calculation for all incidents.

``````deathCounts = Values(Counts(dept));
dangerCalc(i_) := Module({jur, pop, dVal},
jur = SemanticInterpretation(dept((i)));
dVal = N(deathCounts((i))/pop*100);
);
``````

However, I run into problems trying to apply this same process to non-county jurisdictions (testing the first 100 entries). As an example, the second incident is Highland Park (a city). With `dept((2))` being `"Highland Park"`, I get:

``````danger = {};
For(i = 1, i < 101, ++i, AppendTo(danger, dangerCalc(i)));

(* output:

...

AdministrativeDivisionData::notent: Highland Park is not a known entity, class, or tag for AdministrativeDivisionData. Use AdministrativeDivisionData() for a list of entities.

...

*)

``````

This seems to be related to different classifications like “City”, etc. I’m a total novice in this area of Mathematica, so I have little to no clue how to handle varying geographic regions uniformly. I had success with Highland Park by testing:

``````Interpreter("City")(depts((2)))

(* output: Entity("City", {"HighlandPark", "Illinois", "UnitedStates"}) *)

``````

Obviously this doesn’t fit neatly into my current code, and given the multiplicity of different inputs, I’m unsure how to create a general-handling function accounting for all possibilities.

Mathematica’s built-in functions are so numerous, and the semantic interpretation is so sophisticated that I have no idea how to proceed. The “Entity” and other classifiers confuse me conceptually; in plain English, I want to get the population of cities, counties, states, townships, districts, etc. without knowing ahead of time which category each list element belongs to.

Can anyone more knowledgeable than myself suggest a path forward?

## Are technical stopovers not allowed in the United States?

When an airplane stops over in the US, all passengers must alight the aircraft and proceed through US Customs and Border Protection before they’re allowed to advance on with the next leg of their journey.

Am I correct to infer that technical stopovers are not allowed in the United States?

## opengl – Memory Usage Issue with declared variables (when swapping between states)

So my problem is that When I make a Shader variable and I swap between mainmenustate and gamestate really fast I notice my memory usage increase alot but as soon I switch my Shader varaible into a pointer memory usage dont increase until I put cameraShader = new Shader(); I tried deleting the cameraShader but memory usage still increase

BAREBONE EXAMPLE

``````#include "glfw.h"
class State{
private:
public:
State(glfwwindow* window, std::stack<State*>* states){

}
virtual ~State(){
}
}
void update(float& dt){
}

void render(){
}
``````

main

``````  #include "State.h"
#include "stdafx.h"
#include "Game.h"

void Game::framebufferCallback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}

Game::Game()
:previousTime(0.f), dt(0.f)
{
//Variables
const unsigned int width = 854, height = 480;

//Initiating GLFW Window
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef _APPLE_
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif

//Creating a GLFW window
window = glfwCreateWindow(width, height, "EXAMPLE", NULL, NULL);

//Checking if Window was initiated
if (window == NULL) {
std::cout << "GLFW FAILED TO INITIATE WINDOW!n";
glfwTerminate();
}

glfwMakeContextCurrent(window);

//Setting Window's aspect ratio
glfwSetWindowAspectRatio(window, 16, 9);

//Centering Window
int windowWidth, windowHeight;
glfwGetWindowSize(window, &windowWidth, &windowHeight);
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, mode->width / 2 - windowWidth / 2, mode->height /
2 - windowHeight / 2);

std::cout << "GLAD FAILED TO BE INITIATEDn";
}

//Enabling OpenGl features
glEnable(GL_CULL_FACE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);

//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

//Setting-Up Viewport
glfwSetFramebufferSizeCallback(window, framebufferCallback);

}

Game::~Game()
{
}

int Game::glfwGetWindowShouldClose()
{
return glfwWindowShouldClose(window);
}

void Game::processWindowEvents()
{
//Calculating Deltatime
double currentTime = glfwGetTime();
dt = currentTime - previousTime;
previousTime = currentTime;
}

void Game::update()
{
processWindowEvents();
if (!states.empty()) {

states.top()->update(dt);
if (states.top()->getQuit()) {
states.top()->endstate();
delete states.top();
states.pop();
std::cout << "States has been deletedn";
}
}
else {
glfwSetWindowShouldClose(window, GL_TRUE);
}
}

void Game::render()
{
//Clearing display
glClearColor(0.15f, .45f, .60f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

if (!states.empty()) {
states.top()->render();
}

glfwSwapBuffers(window);
glfwPollEvents();
}
``````

``````#ifndef SHADER_H

#include <glm/glm.hpp>

#include <string>
#include <fstream>
#include <sstream>
#include <iostream>

{
public:
unsigned int ID;

Shader(const char* vertexPath, const char* fragmentPath, const char* geometryPath = nullptr)
{
// 1. retrieve the vertex/fragment source code from filePath
std::string vertexCode;
std::string fragmentCode;
std::string geometryCode;
// ensure ifstream objects can throw exceptions:
try
{
// open files
// read file's buffer contents into streams
// close file handlers
// convert stream into string
if(geometryPath != nullptr)
{
}
}
catch (std::ifstream::failure& e)
{
}
const char * fShaderCode = fragmentCode.c_str();
unsigned int vertex, fragment;
checkCompileErrors(vertex, "VERTEX");
checkCompileErrors(fragment, "FRAGMENT");
unsigned int geometry;
if(geometryPath != nullptr)
{
const char * gShaderCode = geometryCode.c_str();
checkCompileErrors(geometry, "GEOMETRY");
}
ID = glCreateProgram();
if(geometryPath != nullptr)
checkCompileErrors(ID, "PROGRAM");
// delete the shaders as they're linked into our program now and no longer necessery
if(geometryPath != nullptr)

}
// ------------------------------------------------------------------------
void use()
{
glUseProgram(ID);
}
// utility uniform functions
// ------------------------------------------------------------------------
void setBool(const std::string &name, bool value) const
{
glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);
}
// ------------------------------------------------------------------------
void setInt(const std::string &name, int value) const
{
glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
}
// ------------------------------------------------------------------------
void setFloat(const std::string &name, float value) const
{
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
}
// ------------------------------------------------------------------------
void setVec2(const std::string &name, const glm::vec2 &value) const
{
glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, &value(0));
}
void setVec2(const std::string &name, float x, float y) const
{
glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y);
}
// ------------------------------------------------------------------------
void setVec3(const std::string &name, const glm::vec3 &value) const
{
glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &value(0));
}
void setVec3(const std::string &name, float x, float y, float z) const
{
glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z);
}
// ------------------------------------------------------------------------
void setVec4(const std::string &name, const glm::vec4 &value) const
{
glUniform4fv(glGetUniformLocation(ID, name.c_str()), 1, &value(0));
}
void setVec4(const std::string &name, float x, float y, float z, float w)
{
glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w);
}
// ------------------------------------------------------------------------
void setMat2(const std::string &name, const glm::mat2 &mat) const
{
glUniformMatrix2fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat(0)(0));
}
// ------------------------------------------------------------------------
void setMat3(const std::string &name, const glm::mat3 &mat) const
{
glUniformMatrix3fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat(0)(0));
}
// ------------------------------------------------------------------------
void setMat4(const std::string &name, const glm::mat4 &mat) const
{
glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat(0)(0));
}

private:
// ------------------------------------------------------------------------
{
GLint success;
GLchar infoLog(1024);
if(type != "PROGRAM")
{
if(!success)
{
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "n" << infoLog;
}
}
else
{
if(!success)
{
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "n" << infoLog;
}
}
}
};
#endif
``````

## forms – #States required not working

I’m trying to use “#states”. When my checkbox is true, I want to make “required” another field. Drupal prints the “required” asterisk but not correctly.

Here it’s the code:

``````  // Return origin.
\$form('search')('return')('return_ori') = (
'#attributes'    => (
'class'       => ('field-autocomplete', 'ret-ori-name'),
'data-type'   => 'busstop',
'placeholder' => t('Write your origin', (), ('context' => 'Backend')),
'required'    => TRUE,
),
'#default_value' => !empty(\$_GET('return_ori')) ? \$_GET('return_ori') : '',
'#prefix'        => '<div class="row"><div class="col-md-5">',
'#states'        => (
'required' => (
':input(name="search_return")' => (
'checked' => TRUE,
),
),
),
'#size'          => 40,
'#suffix'        => '</div>',
'#title'         => t('Return origin'),
'#type'          => 'textfield',
);
// Return trip.
\$form('search')('search_return') = (
'#default_value' => !empty(\$_GET('search_return')) ? \$_GET('search_return') : FALSE,
'#prefix'        => '<div class="row"><div class="col-md-5">',
'#suffix'        => '</div></div>',
'#title'         => t('Search return trip'),
'#type'          => 'checkbox',
'#attributes'    => (
'class' => ('search-return-trip'),
),
);
``````

The submit button has not specific method, so Drupal should handle it. When I press it, the form is sended ignoring my new required field.

Thanks all for help!!

## search algorithms – How did the authors get that there are \$2 cdot 2 cdot 2 = 8\$ or \$n cdot 2^n\$ states?

I am currently studying the textbook Artificial Intelligence, 4th edition, by Russell and Norvig. Chapter 3 Solving Problems by Searching says the following:

A grid world problem is a two-dimensional rectangular array of square cells in which agents can move from cell to cell. Typically the agent can move to any obstacle–free adjacent cell–horizontally or vertically and in some problems diagonally. Cells can contain objects, which the agent can pick up, push, or otherwise act upon; a wall or other impassible obstacle in a cell prevents an agent from moving into that cell. The vacuum world from Section 2.1 can be formulated as a grid world problem as follows:

STATES: A state of the world says which objects are in which cells. For the vacuum world, the objects are the agent and any dirt. In the simple two-cell version, the agent can be in either of the two cells, and each call can either contain dirt or not, so there are $$2 cdot 2 cdot 2 = 8$$ states (see Figure 3.2). In general, a vacuum environment with $$n$$ cells has $$n cdot 2^n$$ states.

How did the authors get that there are $$2 cdot 2 cdot 2 = 8$$ or $$n cdot 2^n$$ states? This was not explained, and it is not evident to me. Furthermore, it isn’t really clear to me from the description and figure 3.2 what’s going on here with the robot and the dirt states.

I went back through my discrete mathematics textbook, Discrete Mathematics with Applications by Susanna S. Epp, because the $$2 cdot 2 cdot 2 = 8$$ calculation and the structure of the diagram in figure 3.2 reminds me of a variation of the multiplication rule:

However, as I said, the vacuum world seems to be a variation of this.

## formal languages – Number of states in MDFA accepting strings w such that |w|=0(mod x) OR 0(mod y)

After trying this with various values of x and y, I noticed this:

If one of them is a multiple of other then the number of states in MDFA is MIN(x,y)

Otherwise, it comes out to be LCM(x,y)

Is this true for all values of x and y?
And What will happen if the OR in the question is replaced by AND?

## 8 – Hide fields in Paragraphs conditionally using Form API #states

I had to do something similar for having localized paragraphs for foreign languages with an option to hide the paragraph (until release date).

The paragraph types I needed this I added a “Display Languages” checkboxes field with the options of All, supported languages, Hide. For example, you could create a paragraph and tick the DE option and the Hide option. This paragraph was hidden until the Hide tick mark was removed and then it only showed when the language was DE.

Here’s an example of the code I used for my announcement_banner paragraph type. If you need it for more types, just implement the hook code for that type.

``````/**
* Implements hook_preprocess_paragraph__announcement_banner().
*
* Handles language display for paragraph type.
*
* @param array \$variables
*/
function MY_MODULE_preprocess_paragraph__announcement_banner(&\$variables) {
\$paragraph = \$variables('paragraph');
if (!MY_MODULE_can_display(\$paragraph)) {
\$variables('attributes')('style')() = 'display: none;';
\$variables('content') = ();
}
}
/**
* Checks if a paragraph can be displayed for the current language.
*
* @param stdClass \$paragraph
*   The paragraph entity to be tested.
* @return boolean
*   True if it can be displayed / False if it can't
*/
function MY_MODULE_can_display( \$paragraph ) {
// Transition check remove once new corporate branding active.
if (!isset(\$paragraph->field_display_languages)  || \$paragraph->field_display_languages->count() == 0) {
return TRUE;
}
\$lang = Drupal::languageManager()->getCurrentLanguage()->getId();
\$hide = FALSE;
\$allowed = FALSE;
foreach (\$paragraph->field_display_languages as \$value ) {
\$langCode = \$value->getValue()('value');
if ( \$langCode == 'hide' ) {
\$hide = TRUE;
}
if ( \$langCode == 'all'  || \$langCode == \$lang ) {
\$allowed = TRUE;
}
}
// Hide if hidden option checked.
if (\$hide) {
return FALSE;
}
// Show if nothing is checked or match found.
return \$allowed;
}
``````