October 06, 2017 Re: For fun: Expressive C++ 17 Coding Challenge in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Biotronic | I am a total beginner but I want to post that a lot. auto autoCorrelation(R)(R range) if (isRandomAccessRange!R) { import std.numeric : fft, inverseFft; import std.range : chain, repeat, zip, dropBack; import std.algorithm : map; import std.complex; auto residual = residualPowerOf2(range.length); auto fftResult = range.chain(repeat(0, residual)).fft(); auto autoCorrResult = fftResult.zip(fftResult.map!(a => a.conj())). map!( a=> a[0] * a[1] ). inverseFft(). dropBack(residual). map!( a => a.re ); return autoCorrResult; } I implemented auto correlation in C++ before which is I believe 2~3 time bigger(also I needed to compile fftw, lapack etc.. ) : https://forum.kde.org/viewtopic.php?f=74&t=118619 . That was the moment I feel in love with D. |
October 15, 2017 Re: For fun: Expressive C++ 17 Coding Challenge in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | Another solution using dlangs builtin csv support for reading. import std.csv; import std.file; import std.algorithm : map; import std.range; string csvWrite(Header, Rows)(Header header, Rows rows) { return header.join(",") ~ "\n" ~ rows.map!(r => header.map!(h => r[h]).join(",")).join("\n"); } int main(string[] args) { auto inputFile = args[1]; auto columnName = args[2]; auto replacement = args[3]; auto outputFile = args[4]; auto records = readText(inputFile).csvReader!(string[string])(null); write(outputFile, csvWrite(records.header, records.map!((r) { r[columnName] = replacement; return r; }))); return 0; } Unfortunately this is still far from the powershell solution :/ cK |
Copyright © 1999-2021 by the D Language Foundation