I am trying to make this statement applicable to some cells in my google spreadsheet :
if ((B29 - B36) > 0) {
(B29 - B36) * (D36 / 100) + F35 + F34 + F33
} else if ((B29 - B35) > 0) {
(B29 - B35) * (D35 / 100) + F34 + F33);
} else if (B29 - B34 > 0) {
(B29 - B34) * (D34 / 100) + F33);
} else {
0
}
I tried to make it with only IF, but the cells didn't like the syntax :
=IF((B29 - B36) > 0);((B29 - B36) * (D36 / 100) + F35 + F34 + F33);IF((B29 - B35) > 0);((B29 - B35) * (D35 / 100) + F34 + F33);IF((B29 - B34) > 0);((B29 - B34) * (D34 / 100) + F33);0
How can I achieve this?
correct syntax would be like this:
=IF(B29-B36 > 0; (B29-B36)*(D36/100)+F35+F34+F33;
IF(B29-B35 > 0; (B29-B35)*(D35/100)+F34+F33;
IF(B29-B34 > 0; (B29-B34)*(D34/100)+F33; 0)))
Related
I was looking at some code which came with the following short-hand statement
score = ((initialPlayer == player) ? CAPTURE_SCORE : -CAPTURE_SCORE) + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
I think that I understand the first portion of the code,
if(initialPlayer == player){
score = CAPTURE_SCORE;
}
else
score = -CAPTURE_SCORE;
but im confused to how the +recursive_solver function is added to this, any help would be greatly appreciated :)
As stated above I tried to write out the statement in a longer from thats easier for me to read. My best guess is that the recursive solver function is then added to the score of the if-else statement?
if(initialPlayer == player)
score = CAPTURE_SCORE + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
else
score = -CAPTURE_SCORE + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
Explanation:
A = (C ? B : D) + E;
If C is true: A = (B) + E;
If C is false: A = (D) + E;
In sum
if (C)
A = B + E;
else // if (!C)
A = D + E;
score = ((initialPlayer == player) ? CAPTURE_SCORE : -CAPTURE_SCORE) + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
Equals to
if(initialPlayer == player) {
score = CAPTURE_SCORE;
} else {
score = -CAPTURE_SCORE;
}
score += recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
I want to write the If statement below in a Google Sheet:
If today's date is greater than the payment deadline, then return the overdue payment amount. Otherwise, return 0.
I did this:
=if(F11<"=TODAY()",C11,0) + if(F12<"=TODAY()",C12,0) + if(F13<"=TODAY()",C13,0) + if(F14<"=TODAY()",C14,0) + if(F15<"=TODAY()",C15,0) + if(F16<"=TODAY()",C16,0) + if(F17<"=TODAY()",C17,0)
The values in column F are dates written the date format month/day/year. All of the dates in column F are greater than today's date.
The values in column C are dollar amounts with decimals.
First Attempt:
=if(F11<"=TODAY()",C11,0) + if(F12<"=TODAY()",C12,0) + if(F13<"=TODAY()",C13,0) + if(F14<"=TODAY()",C14,0) + if(F15<"=TODAY()",C15,0) + if(F16<"=TODAY()",C16,0) + if(F17<"=TODAY()",C17,0)
Second Attempt:
=if(F11<"TODAY()",C11,0) + if(F12<"TODAY()",C12,0) + if(F13<"TODAY()",C13,0) + if(F14<"TODAY()",C14,0) + if(F15<"TODAY()",C15,0) + if(F16<"TODAY()",C16,0) + if(F17<"TODAY()",C17,0)
Third Attempt:
=if(DATEVALUE(F11)<"TODAY()",C11,0) + if(DATEVALUE(F12)<"TODAY()",C12,0) + if(DATEVALUE(F13)<"TODAY()",C13,0) + if(DATEVALUE(F14)<"TODAY()",C14,0) + if(DATEVALUE(F15)<"TODAY()",C15,0) + if(DATEVALUE(F16)<"TODAY()",C16,0) + if(DATEVALUE(F16)<"TODAY()",C17,0)
I expect to get 0 overdue payments as all the payment deadlines are greater than today's day. Could you please help me?
your formula should be:
=IF(F11<TODAY(), C11, 0) +
IF(F12<TODAY(), C12, 0) +
IF(F13<TODAY(), C13, 0) +
IF(F14<TODAY(), C14, 0) +
IF(F15<TODAY(), C15, 0) +
IF(F16<TODAY(), C16, 0) +
IF(F17<TODAY(), C17, 0)
next level formula would be:
=ARRAYFORMULA(SUM(IF(F11:F17<TODAY(), C11:C17, 0)))
or shorter:
=SUMIF(F11:F17, "<"&TODAY(), C11:C17)
I am trying to translate some Pascal code into C++ code. I am stuck trying to figure out how to translate this portion.
Function ThetaG_JD(jd : double) : double;
var
UT,TU,GMST : double;
begin
**UT := Frac(jd + 0.5);**
jd := jd - UT;
TU := (jd - 2451545.0)/36525;
GMST := 24110.54841 + TU * (8640184.812866 + TU * (0.093104 - TU * 6.2E-6));
**GMST := Modulus(GMST + 86400.0*1.00273790934*UT,86400.0);**
ThetaG_JD := twopi * GMST/86400.0;
end; {Function ThetaG_JD}
I am particularly having trouble with the two lines I made bold. How can I translate this to c++? Thank you so much.
In C++ the equivalent functions would be:
fmod to get a floating point modulus
modf to break a floating point item into its fraction and integral parts (equivalent of Frac).
If you want to calculate Julian Day, Greenwich Mean Sidereal Time and Local Mean Sidereal Time, maybe the below can help you - written in PowerShell:
<#
.Synopsis
Astronomy calculations
.Description
Some helper functions to calculate:
- Julian Day,
- Greenwich Mean Sidereal time,
- Local Mean Sidereal Time.
#>
cls
# https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation
function Get-JulianDay
{
param ( [System.DateTime]$dt )
$year = $dt.Year
$month = $dt.Month
$day = $dt.Day
$hour = $dt.Hour
$minute = $dt.Minute
$second = $dt.Second
$a = [System.Math]::Floor((14 - $month) / 12)
$y = $year + 4800 - $a
$m = $month + 12 * $a - 3
$JDN = $day + [System.Math]::Floor((153 * $m + 2) / 5) + 365 * $y + [System.Math]::Floor($y / 4) - [System.Math]::Floor($y / 100) + [System.Math]::Floor($y / 400) - 32045
$JD = $JDN + ($hour - 12) / 24 + $minute / 1440 + $second / 86400
return ($JD)
}
# https://en.wikipedia.org/wiki/Sidereal_time#Definition
# http://aa.usno.navy.mil/faq/docs/GAST.php
function Get-GMST
{
param ( [double]$JD )
$D = $JD - 2451545.0
$GMST = 18.697374558 + 24.06570982441908 * $D
return ($GMST % 24)
}
function Get-LMST
{
param ( [double]$gmst, [double]$longitude )
return ( $gmst + $longitude / 15.0 )
}
# Test above functions
$current = (Get-Date).ToUniversalTime()
$jd = Get-JulianDay -dt $current
$gmst = Get-GMST -JD $jd
$longitude = 17.668487800
$lmst = Get-LMST -gmst $gmst -longitude $longitude
$lst = [timespan]::FromHours($lmst).ToString()
Write-Host "Local mean sidereal time: $lst"
Just a basic Casaer Cipher. I've tested all of the sub functions, just encryptChar() does not particularly work. I get an infinite loop. It's supposed to be recursive. Here's the all code:
fun replace (str : string, index : int, newChar : char) : string = String.substring(str,0,index) ^ String.str(newChar) ^ String.substring(str,index+1,(size str) - index - 1;
fun encryptChar (msgStr : string, shiftAmnt : int, index : int) : string =
let val asciiCode = 0
in
if (not (String.sub(msgStr, index) = #" ")) then
(
asciiCode = ord( String.sub(msgStr, index) ) + shiftAmnt;
if (asciiCode < ord(#"A")) then asciiCode = asciiCode + 26
else if (asciiCode > ord(#"Z")) then asciiCode = asciiCode - 26
else asciiCode = asciiCode;
msgStr = replace(msgStr, index, chr(asciiCode))
)
else asciiCode = asciiCode;
index = index + 1;
if (index < (size msgStr - 1)) then encryptChar(msgStr, shiftAmnt, index)
else msgStr
end
;
fun encrypt(msgStr : string, shiftAmnt : int) : string = encryptChar (String.map Char.toUpper msgStr, shiftAmnt mod 26, 0);
The problem here is that you're misusing =. Outside of a variable definition, = is simply a boolean function which checks its arguments for equality. So if you do for example asciiCode = ord( String.sub(msgStr, index) ) + shiftAmnt;, it will simply return false (because asciiCode is not equal to ord( String.sub(msgStr, index) ) + shiftAmnt) and then throw that result away (because you have additional expressions after the ;). It will not reassign asciiCode.
Variables in SML are immutable. If you want to emulate mutable variables you can use refs and the := operator. However I would not recommend that approach as it is generally not good functional style and not necessary in this case. The preferable approach would be to rewrite the code in a way that each variable is only assigned once.
This is very basic indeed, and it's surprising that you ran into it in such a complicated situation.
Did you port this from some other language?
You need to forget everything you know about programming using assignments.
let val x = y in something
means more or less "within 'something', replace the identifier 'x' with the value of 'y'".
There is no way for you to change the value of x.
Do the substitution (this is not the actual evaluation order or anything, but it should give you an idea of what's going on):
encryptChar("THIS", amount, 0)
=>
let val asciiCode = 0
in
if (not (String.sub("THIS", 0) = #" ")) then
(
asciiCode = ord( String.sub("THIS", 0) ) + amount;
if (asciiCode < ord(#"A")) then asciiCode = asciiCode + 26
else if (asciiCode > ord(#"Z")) then asciiCode = asciiCode - 26
else asciiCode = asciiCode;
"THIS" = replace("THIS", 0, chr(asciiCode))
)
else asciiCode = asciiCode;
0 = 0 + 1;
if (0 < (size "THIS" - 1)) then encryptChar("THIS", amount, 0)
else str
end ;
=>
if (not (String.sub("THIS", 0) = #" ")) then
(
0 = ord( String.sub("THIS", 0) ) + amount;
if (0 < ord(#"A")) then 0 = 0 + 26
else if (0 > ord(#"Z")) then 0 = 0 - 26
else 0 = 0;
"THIS" = replace("THIS", 0, chr(0))
)
else 0 = 0;
0 = 0 + 1;
if (0 < (size "THIS" - 1)) then encryptChar("THIS", amount, 0)
else str
=>
if (not (String.sub("THIS", 0) = #" ")) then
(
0 = ord( String.sub("THIS", 0) ) + amount;
if true then false
else if false then false
else true;
false
)
else true;
false;
if (0 < (size "THIS" - 1)) then encryptChar("THIS", amount, 0)
else "this"
->
if (not false) then
(
false;
false;
false
)
else true;
false;
if true then encryptChar("THIS", amount, 0)
else "THIS"
=>
(
false;
false;
false
)
false;
encryptChar("THIS", amount, 0)
=>
encryptChar("THIS", amount, 0)
Which is where your infinite loop came from.
You would do well to get hold of an introductory text about ML programming.
I would convert Gregorian date to Hijri (Islamic) date. After may search on the web, I found a source code to convert it.
I converted the code from Java and PHP to C base.
The implement some times working without any problem. But some days has problem.
I need your help either fix the implement or a available code that will work without any problem!
BTW I found another source code (http://emr.cs.iit.edu/~reingold/calendar.C) that is C++ base. As I don't know C++ if anyone can convert that to C Base or Objective C would be prefect (still not sure this code will work correctly or not).
P.S. You can check the correct date in: islamicfinder.org/Hcal/index.php
void gregorian_to_hijri(int* h_y, int* h_m, int* h_d, int g_y, int g_m, int g_d)
{
int year, month, day;
int zyr;
int zd;
int zm;
int zy;
float zjd;
int zl;
int zn;
int zj;
year = g_y;
month = g_m;
day = g_d;
zyr = year;
zd = day;
zm = month;
zy = zyr;
if((zy > 1582) || ((zy == 1582) && (zm > 10)) || ((zy == 1582) && (zm == 10) && (zd > 14)))
{
zjd = ((1461 * (zy + 4800 + ((zm - 14) / 12))) / 4)
+ ((367 * (zm - 2 - 12 * (((zm - 14) / 12)))) / 12)
- ((3 * (((zy + 4900 + ((zm - 14) / 12)) / 100))) / 4) + zd - 32075;
}
else
{
zjd = 367 * zy - ((7 * (zy + 5001 + ((zm - 9) / 7))) / 4)
+ ((275 * zm) / 9) + zd + 1729777;
}
zl = zjd - 1948440 + 10632;
zn = ((zl - 1) / 10631);
zl = zl - 10631 * zn + 354;
zj = (((10985 - zl) / 5316)) * ((int)((50 * zl) / 17719))
+ ((zl / 5670)) * ((int)((43 * zl) / 15238));
zl = zl - (((30 - zj) / 15)) * (((17719 * zj) / 50))
- ((zj / 16)) * (((15238 * zj) / 43)) + 29;
zm = ((24 * zl) / 709);
zd = zl - ((709 * zm) / 24);
zy = 30 * zn + zj - 30;
*h_y = zy;
*h_m = zm;
*h_d = zd;
}
Assuming this is for a Mac (Cocoa) or iOS (Cocoa Touch) app, since that's where you see Objective C most often, then you can just do something like this:
// Create a Gregorian Calendar
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// Set up components of a Gregorian date
NSDateComponents *gregorianComponents = [[NSDateComponents alloc] init];
gregorianComponents.day = 4;
gregorianComponents.month = 12;
gregorianComponents.year = 2010;
// Create the date
NSDate *date = [gregorianCalendar dateFromComponents:gregorianComponents];
[gregorianComponents release];
[gregorianCalendar release];
// Then create an Islamic calendar
NSCalendar *hijriCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCivilCalendar];
// And grab those date components for the same date
NSDateComponents *hijriComponents = [hijriCalendar components:(NSDayCalendarUnit |
NSMonthCalendarUnit |
NSYearCalendarUnit)
fromDate:date];
NSLog(#"[In Hijri calendar ->] Day: %ld, Month: %ld, Year:%ld",
[hijriComponents day],
[hijriComponents month],
[hijriComponents year]);
[hijriCalendar release];
If all you want is the current date, then you can skip setting up the gregorian date altogether and just do this:
// Create an Islamic calendar
NSCalendar *hijriCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
// And grab the date components for the current date
NSDateComponents *hijriComponents = [hijriCalendar components:(NSDayCalendarUnit |
NSMonthCalendarUnit |
NSYearCalendarUnit)
fromDate:[NSDate date]];
[hijriCalendar release];
Have a look at this topic: how to convert hijari date into gregorian date in java script?
The question mentions JavaScript but the top answer seems to have links to implementations in a variety of languages.
You should be able to do this in Objective-C (if that really is an option) using NSCalendar.