x = str(input())
while "a" in x:
x.replace("a", "", 1)
print(x)
when I run this code I expect it to give me the string x without any "a"s in it, but the problem is that it doesn't give me anything. How do I fix this?
I suggest you turn your code into code snippets in a post, to make it more readable.
Here is my implementation:
x = str(input())
x = x.replace('a','')
Related
For 2 datatype like this.
datatype flight = F of int * int;
datatype flights = Fs of flight list;
I want to make a function that can check if (a,b) is in flights or not.
Example:
val reachable = fn : flights * (int * int) -> bool
reachable (Fs [F(0,1), F(1,0)], (0, 1));
val it = true : bool
I have no idea how can i compare a (int*int) to flights.
I use
fun get_f_x (F(x,y)) = x;
to get the first integer in flight.
But when i try to do the same thing to flights.
I do it like below:
fun test_hd(Fs[i,_]) = i;
In order to get the first flight out for the flights.
But it can only take flights with 2 flight only (Fs [F(0,1), F(1,0)])
If flight have more than 2 element, it show error.
Similarly
fun test_tl(Fs[_,i]) = i;
have the same problem.
How can I make a hd and tl for flights? Or what is the correct way to think about this problem?
Not having seen the errors you're encountering, it's hard to say, but looking at the code you've shown, I suspect in-exhaustive pattern matching is a factor. With that in mind, let's look at a way of breaking down the recursion and pattern matching involved.
If you want to see if a particular flight is in flights, first we need to start with what we absolutely know: If a flights value contains no values in its list, then the answer must be false, no matter what we're looking for.
fun reachable(Fs([]), _) = false
What if there is something in that list? Well, let's check the first element to see if it's what we are looking for.
fun reachable(Fs([]), _) = false
| reachable(Fs(F(x) :: xs), flt) = flt = x
But what about the rest, if that one doesn't match? We'd need to check the rest of the list.
fun reachable(Fs([]), _) = false
| reachable(Fs(F(x) :: xs), flt) =
flt = x orelse reachable(Fs(xs), flt)
While I was playing and testing various things with SwiftUI.
I found this bizarre situation. It is I guess related to the limit value that Double can handle, but anyway I thought it was weird enough to make a post. And hopefully someone can explain exactly what is happening or let me know where I made a mistake.
It seems like any odd value for t in the following code will cause the same kind of trouble.
let v:Double = 13082761331670030, t:Double = 1
var u:Double
u = v - t;
u += t;
if u == v {print("All is right.")}
else {
print("This is weird. We now have:")
print("v = \(String(format: "%.0f",v)) and u = \(String(format: "%.0f",u))")
}
Executing the code leads to:
u != v
I am new with google OR SAT in python and the documentation is not very clear. What I am trying to do is the following:
There's a list like this:
desk[1] = 3
desk[2] = 5
desk[3] = 4
desk[4] = 2
desk[5] = 1
and a variable called person_la_croix, with value = 4, let's say.
I would like to create a boolean list (t) out of that t[i] = 1, if desk[i] != person_la_croix and 0 otherwise. And then I would like to take the i from t[i] which t[i] == 1 and assign it to variable desk_la_croix
I tried this:
for i in s:
model.Add(desk[i] == person_la_croix).OnlyEnforceIf(t[i])
for i in s:
model.Add(desk_la_croix == i).OnlyEnforceIf(t[i])
It is not working...
Can someone help me out either with this code or suggesting a smarter way to do this?
Have you read
https://github.com/google/or-tools/blob/stable/ortools/sat/doc/channeling.md ?
I guess you miss the opposite of the OnlyEnforceIf as these are only implications, not equivalences.
I am trying to solve a beginner problem with lists but can't find an example to help me get it work. I am given a list of positive and negative integers (AccountHistory) and I need to check if the negative integers in this list have ever exceeded -1000. I expected my code to work with a freshly introduced helper function like this:
def checkAccount(account: AccountHistory): Boolean = {
def helper(i: AccountHistory): Int = {
var total = 0
i.collect{case x if x < 0 => Math.abs(x) + total}
return total
}
if (helper(account) >1000) true else false
}
But it doesn't work. Please help me find my mistake or problem in wrong approach.
Edit: The pre-given tests include
assert(checkAccount(List(10,-5,20)))
assert(!checkAccount(List(-1000,-1)))
So if assert expects true then my approach is wrong to solve it like this.
By 'exceeded' I mean <-1000, for any or all elements in a list (like exceeding a credit amount in given period).
i.collect{case x if x < 0 => Math.abs(x) + total}
In the above code snippet, not assign back to total, maybe you need:
val total = i.filter(_ < 0).map(Math.abs).sum
I think this is what you're supposed to do:
def checkAccount(account: AccountHistory): Boolean =
account.forall(_ > -1000)
I need to make sure that at least 1 change occurred in a specific uint item X, i.e. X had 2 different values (it is unknown what specific values). Something like this:
cover some_event {
item X : uint = some_uint using no_collect;
transition X using when = (prev_X != X);
};
** The code causes compilation error
Is it possible to define such coverage in Specman?
Thank you for your help
what you wrote is almost accurate, but instead of "when" - use "ignore"
cover some_event is {
item X : uint = some_uint using no_collect;
transition X using ignore = (prev_X == X);
};