## Dynammic programming – Computer Science Stack Exchange

Lets say we have integer array $$A$$ with size $$n$$ and $$B$$ with size $$k$$. Items in $$B$$ are unique.

I want to come up with a dynamic programming algorithm that finds indices $$j' such that all elements of $$B$$ belong to $$A[j’:j”]$$. I want to minimize the difference between $$j”$$ and $$j’$$. At the end, I want to return $$j’$$ and $$j”$$ if such pair exists.

For example, $$A = [1, 2, 9, 6, 7, 8, 1, 0, 0, 6]$$ and $$B = [1, 8, 6]$$ then $$Bsubseteq{A[1:6]}$$ and $$Bsubseteq{A[4:7]}$$. Since $$7-4<6-1$$, we return $$j’=4, j”=7$$.

## C programming – Post Increment

Why is ‘i’ remaining 1 even though its post incremented in (1) part
and why is the ‘i’ changing here to 2 in the (2) part though its post incremented

``````(1)
int main()
{

int a , i;

i = 1;
i = i++;
printf("%d %d",i,i);
}
output - 1,1.

(2)
int main()
{

int a , i;

i = 1;
a = i++;
printf("%d %d",a,i);
}
output - 1,2
``````

## functional programming – C program to print a vertical english ruler whose length is given by the user

In this source code, i have writena program, using for loops, to print an english ruler whose length is given by the user.
So what i want to know is that is it possible to modify this program, to print the ruler in a more logical way And if so, how can it be done, without applying reculsions ?

This is the program to print ruler vertically.

``````#include<stdio.h>
int main()
{
int q,num,x;
int y,p,n;
printf("Enter height of central dashesn");
scanf("%d",&n);
printf("Enter number of inchesn");
scanf("%d",&num);
for(x=0;x<num;x++)
{
for(q=0;q<n;q++)
{
printf("-");
}
printf("%dn",x);
for(p=0;p<n-3;p++)
{
printf("-");
}
printf("n");
for(p=0;p<n-2;p++)
{
printf("-");
}
printf("n");
for(p=0;p<n-3;p++)
{
printf("-");
}
printf("n");
for(p=0;p<n-1;p++)
{
printf("-");
}
printf("n");
for(p=0;p<n-3;p++)
{
printf("-");
}
printf("n");
for(p=0;p<n-2;p++)
{
printf("-");
}
printf("n");
for(p=0;p<n-3;p++)
{
printf("-");
}
printf("n");
}
for(y=0;y<n;y++)
{
printf("-");
}
printf("%d",x);
printf("n");
return 0;
}
``````

## functional programming – How to write a C program to print Pi basing on Madhava series

in this question, i have been tasked to write a program that prints pi basing on madava series, using pi() function and power() function.

The issue is that, when i use power(), i dont get the actual value of pi.
This is the source code i have written.

``````#include<stdio.h>
#include<math.h>
double pi();
int power(int x, int y);
int n;
int main()
{
double ret;
ret=pi();
printf("%.16f",ret);
}
double pi()
{
double j, result;
int x, k, n;
printf("Input value of n:");
scanf("%d",&n);
result=0;
for( k=0; k<n; k++ )
{
result+=(power((-1),(k))/ power((2*k+1.3),k)) ;
}
j=(sqrt(12))*result;
return j;
}
int power(int x, int y)
{
int res = 1;
for( y; y>0; y--)
{
res = res*x;
}
return res;
}
``````

## functional programming – How to make my Clojure code more “funcional”?

I’ve started learning Clojure a few days ago and I wrote this code that factorises numbers. How do I make it better? Is there any way to avoid doing it with a loop? Is that how I am supposed to code in Clojure?

``````(defn classify (n)
(loop (n n
i 2
f ())
(cond
(= n i) (conj f i)
(= (mod n i) 0) (recur (/ n i) 2 (conj f i))
:else (recur n (inc i) f))))
``````

## logic – Analogue of disjunction and existence properties for a Turing-complete programming language?

Quoting from Wikipedia:

In mathematical logic, the disjunction and existence properties are
the “hallmarks” of constructive theories such as Heyting arithmetic
and constructive set theories (Rathjen 2005).

The disjunction property is satisfied by a theory if, whenever a
sentence `A ∨ B` is a theorem, then either `A` is a theorem, or `B` is a
theorem.

The existence property or witness property is satisfied by a theory
if, whenever a sentence `(∃x)A(x)` is a theorem, where `A(x)` has no other
free variables, then there is some term `t` such that the theory proves
`A(t)`.

In the realm of logic (to the best of my understanding), these properties are violated when a logic is “classical”, which, through the Curry-Howard lens, corresponds to it having support for capturing undelimited continuations.

For Turing-complete programming languages, the presence or absence of first-class control and undelimited continuations is also a meaningful and important distinction. However, being inconsistent as logics, the disjunction and existence properties in their above form hold trivially: every ‘sentence’ is a ‘theorem’.

So: Is there any formal property that can distinguish Turing-complete programming languages based on whether or not they have undelimited continuations, which is similar in spirit to the disjunction and existence properties for logics? (Let’s assume the languages are statically typed and do possess sum types and/or existential types.)

If you are reading this, then I think you like programming, or you want to learn it.

I started with the basics of HTML and CSS. I loved creating new websites and designs. I taught myself HTML and CSS during high school using youtube tutorials, forums, documentation etc.
Every time I finished 50% of my project, I started working on a new one. I couldn’t help myself. I just love to explore new features and lines.

My goal is to learn Python and C++, but I am too lazy to start.

What are your favorite programming languages? Also, which one are you exploring right now?

## programming – How to properly drop (remove or disable) privileges in Windows?

I’m trying to write a secure application that performs a privileged operation on Windows (in particular it changes system time). Because of that I ask the user to run this application with Admin privileges. As one of the first things I want to do in the program is to drop all unnecessary privileges from my access token to limit the impact of any bugs I introduce later. From the Microsoft documentation on the topic I understand that I can either “disable” those privileges via AdjustTokenPrivileges, or create a new access token with “removed” privileges via CreateRestrictedToken and relaunch my application with it. If I understand this correctly the disabled privileges can be re-enabled at any time, so any sufficiently compromised application will just do that and ignore any restrictions I tried to impose. On the other hand, If I remove the privileges completely with CreateRestrictedToken they can’t be added back, which sounds safer and what I’d generally imagine under the term “dropping privileges” (also this way sounds like an enormous amount of hassle with the relaunching and such).

I suspect that this understanding might be wrong. What would be the most appropriate way of dropping all but needed privileges in windows?

## programming languages – Problem in run Kotlin

I tried to use Kotlin on vs code, but when I doing run,I see this message” code language not supported or defined ”
Can you help me?

That is setting. Json:

” [Kotlin] “:{KT},

” files. Associations”:{
“*KT” :”git-commit”

},

” code-runner.runInTerminal”: true,

“files.autosave”:”afterDelay

}

## lambda calculus – Is there a functional programming language with inherent change propagation?

Change propagation in programming environments is an add-on at the framework level such as React.

There was a lot of work on dataflow virtual machines in the wake of Backus’s Turing Award Lecture on formal functional programming. This is because dataflow programming is one way of thinking about change propagation in functional programming, and people were seriously re-visiting the conflict, going back to the first implementation of LISP, between the concepts of state and pure lambda calculus.

While I recognize that dataflow merely pushes that conflict to the end-points of the dataflow graph, it does seem to have practical merit as evidenced by frameworks attempting to grapple with it. However, in the decades since then, I’ve not noticed any functional programming languages that have inherent change propagation.

Am I missing something?