Leafletjs legand value = 0 - leaflet

I would like to know (if it's possible) how to add a 0 value ine Leafletjs block's legend.
For an example, this is my class :
function getColorPOPULATION(d) {
return d > 500 ? '#004590' :
d > 250 ? '#00ABFF' :
d > 1 ? '#A0E0FF' :
'#FFF4D0' ;
... and my grades (div legend) :
grades = [0, 1, 250, 500],
-> I get this result :
0 - 1
1 - 250
250 - 500
500+
I would like to isolate the 0 value (my first class will be 0). Does Leafletjs able to do this ?
Thank you,

Related

I would like to change candle colors using the offset function with a variable/conditional offset time

Version 5.0. iff_17 determines whether my conditions are met. It then sets the candlecolor and the offset time (pasttime) which is either -4 or 0. However, it seems that pasttime is not recognized as a numerical value (also using int pasttime = iff_17 == 2 ? -4 : 0) does not work Help would be greatly appreciated. Thanks
iff_17 = va1 == 1 and ((_hh or _lh) or (_hl or _ll)) ? 2 : 0
candleColor2 = iff_17 == 2 ? candleColor1 : candleColor
pasttime = iff_17 == 2 ? -4 : 0
barcolor(candleColor2, offset = pasttime)

this python program guess a random number, how to calculate the average numberguesses?

import random
i went to add another function to calculate the number guesses
def guess(x):
randomNumb = random.randint(1, x)
guess = 0
while guess != randomNumb :
guess = int(input(f'entre number between 1 and {x} : '))
print(guess)
if guess < randomNumb :
print('guess is low')
elif guess > randomNumb :
print('guess is high')
print(f'guess is right {randomNumb}')
guess(100)

DP Coin Change Algorithm - Retrieve coin combinations from table

To find how many ways we have of making change for the amount 4 given the coins [1,2,3], we can create a DP algorithm that produces the following table:
table[amount][coins.count]
0 1 2 3 4
-----------
(0) 1 | 1 1 1 1 1
(1) 2 | 1 1 2 2 3
(2) 3 | 1 1 2 3 4
The last position being our answer. The answer is 4 because we have the following combinations: [1,1,1,1],[2,1],[2,2],[3,1].
My question is, is it possible to retrieve these combinations from the table I just generated? How?
For completeness, here's my algorithm
func coinChange(coins: [Int], amount: Int) -> Int {
// int[amount+1][coins]
var table = Array<Array<Int>>(repeating: Array<Int>(repeating: 0, count: coins.count), count: amount + 1)
for i in 0..<coins.count {
table[0][i] = 1
}
for i in 1...amount {
for j in 0..<coins.count {
//solutions that include coins[j]
let x = i - coins[j] >= 0 ? table[i - coins[j]][j] : 0
//solutions that don't include coins[j]
let y = j >= 1 ? table[i][j-1] : 0
table[i][j] = x + y
}
}
return table[amount][coins.count - 1];
}
Thanks!
--
Solution
Here's an ugly function that retrieves the combinations, based on #Sayakiss 's explanation:
func getSolution(_ i: Int, _ j: Int) -> [[Int]] {
if j < 0 || i < 0 {
//not a solution
return []
}
if i == 0 && j == 0 {
//valid solution. return an empty array where the coins will be appended
return [[]]
}
return getSolution(i - coins[j], j).map{var a = $0; a.append(coins[j]);return a} + getSolution(i, j - 1)
}
getSolution(amount, coins.count-1)
Output:
[[1, 3], [2, 2], [1, 1, 2], [1, 1, 1, 1]]
Sure you can. We define a new function get_solution(i,j) which means all solution for your table[i][j].
You can think it returns an array of array, for example, the output of get_solution(4,3) is [[1,1,1,1],[2,1],[2,2],[3,1]]. Then:
Case 1. Any solution from get_solution(i - coins[j], j) plus coins[j] is a solution for table[i][j].
Case 2. Any solution from get_solution(i, j - 1) is a solution for table[i][j].
You can prove Case 1 + Case 2 is all possible solution for table[i][j](note you get table[i][j] by this way).
The only problem remains is to implement get_solution(i,j) and I think it's good for you to do it by yourself.
If you still got any question, please don't hesitate to leave a comment here.

How to normalize Integer variable to positive negative or zero with bit operations

7 -> 1
0 -> 0
-7 -> -1
I've have code:
(x == 0 ? 0 : x / abs(x)) + 1
but is it possible to avoid division and make it faster?
How about
(x == 0 ? 0 : (x < 0 ? -1 : 1))
The idea was to use bit operations to avoid branching code or value conversion.
Haven't found how to do it with bit operations but apple already add this function
https://developer.apple.com/documentation/swift/int/2886673-signum
signum()
Returns -1 if this value is negative and 1 if it’s positive; otherwise, 0.
so simple) raw test shows ~x100 faster implementation

Calculate total column for each row from a file in matlab

I have file with the content like this :
1.000000 - 1.000200 0 -> 2 A-MPDU 1.000000 - 1.000100 SUCCESS 1.000100 - 1.000200 FAIL
1.000225 - 1.000270 2 -> 0 ACK SUCCESS [01]
1.000425 1 TIMEOUT
1.000270 - 1.000570 0 BACKOFF
1.How to calculate the total number of column for each line? for example : total_column_row[1] = 15, etc
2.Then, how to make index x for each row to make condition as below? :
if total_column_row[x] == 15
something
elseif total_column_row[x] == 9
something
elseif ......
This might help
Assumption : Your file text is saved into array myTextArray
temp = strsplit(myTextArray, \n)
For ii = 1 to length(temp)
myColRows(ii) = length(strsplit(temp(ii), " "))
End
myColRows has the number of columns per row.