Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Last active October 14, 2016 05:07
Show Gist options
  • Save tanaikech/a9171857cea11167cd6354e66ace58ce to your computer and use it in GitHub Desktop.
Save tanaikech/a9171857cea11167cd6354e66ace58ce to your computer and use it in GitHub Desktop.
Google Apps Scriptで配列要素の総和処理を高速で行いたい ref: http://qiita.com/tanaike/items/17c88c69a0aa0b8b18d7
Declare a string variable arr, sum
Declare an integer variable loopcounter
Set arr to size n
for loopcounter = 0 to (size of arr) - 1
sum = sum + arr[loopcounter]
loopcounter = loopcounter + 1
endfor
\Psi = \sum_{\lambda=1}^{\theta} \mu \lambda \tag{1}
\frac{d\Psi(\phi, \omega)}{d\omega} = -\frac{\theta \log \phi}{\phi^{\omega}} + \phi + 3 \tag{6}
\omega = \log_{\phi}{\frac{\theta \log \phi}{\phi + 3}} \tag{7}
\omega = \log_{\phi}\theta-1 \tag{8}
SOUWA.souwa(配列, デリミタ, 改行コード);
Declare a string variable arr, tempsum, sum
Declare an integer variable division, loopcounter1, loopcounter2
Set arr to size n
division = d
for loopcounter1 = division to (size of arr) - 1
for loopcounter2 = 0 to (size of arr) - 1
tempsum = tempsum + arr[loopcounter2]
loopcounter2 = loopcounter2 + 1
endfor
sum = sum + tempsum
tempsum = ''
loopcounter2 = loopcounter1
loopcounter1 = loopcounter1 + division
endfor
\left(\sum_{\lambda=1}^{\phi_1} \mu_{1} \lambda\right)\frac{\theta_{1}}{\phi_{1}} +
\left(\sum_{\lambda=1}^{\phi_2} \mu_{2} \lambda\right)\frac{\theta_{2}}{\phi_{2}} +
\cdots
\cdots +
\left(\sum_{\lambda=1}^{\phi_{\omega-1}} \mu_{\omega-1} \lambda\right)\frac{\theta_{\omega-1}}{\phi_{\omega-1}} +
\left\{\left(\sum_{\lambda=1}^{\phi_{\omega}} \mu_{\omega} \lambda\right)\frac{\theta_{\omega}}{\phi_{\omega}} + \sum_{\lambda=1}^{\frac{\theta_{\omega}}{\phi_{\omega}}} \mu_{\omega}\phi_{\omega}\lambda \right\}
\tag{2}
\theta_{\omega} = \frac{\theta}{\phi^{\omega-1}}
\mu_{\omega} = \mu\phi^{\omega-1}
\Psi(\phi, \omega) = \frac{\mu\theta}{2}\left\{ \left(\phi + 3\right)\omega + \frac{\theta}{\phi^{\omega}} - 1 \right\} \tag{3}
\frac{d\Psi(\phi, \omega)}{d\phi} = \frac{\mu\theta\omega}{2}\left( 1 - \theta \phi^{-(\omega+1)} \right) \tag{4}
\phi = \left( \frac{1}{\theta} \right)^{-\frac{1}{\omega+1}} \tag{5}
function ss2csv() {
var ss_file = "sampless"; // csvに変換したいスプレッドシートのファイル名
var csv_file = "sampless.csv"; // 出力するcsvファイル名
var sheet = SpreadsheetApp.open(DriveApp.getFilesByName(ss_file).next());
var data = sheet.getRange('a1').offset(0, 0, sheet.getLastRow(), sheet.getLastColumn()).getValues();
var csvdata = SOUWA.souwa(data, ',', '\r\n');
DriveApp.createFile(csv_file, csvdata, MimeType.CSV);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment