piątek, 20 lipca 2018

Codility - MinAvgTwoSlice

  public int solution03(int[] A) {
    final int N = A.length;
    double minSlc = (A[0] + A[1]) / 2.0;
    int indMinSlc = 0;

    for (int i = 0; i < N - 2; i++) {
      double slc = (A[i] + A[i + 1]) / 2.0;
      if (A[i + 2] < slc) {
        slc = (A[i] + A[i + 1] + A[i + 2]) / 3.0;
      }
      if (slc < minSlc) {
        minSlc = slc;
        indMinSlc = i;
      }
    }
    if ((A[N - 2] + A[N - 1]) / 2.0 < minSlc) {
      indMinSlc = N - 2;
    }

    return indMinSlc;
  }

=============
Explanation:
1. First slice consist of two elements.
2. You can lover the value of original slice by adding some new elements.
3. In order to lover the value of original slice, added elements have to have "slice value" lesser than original slice.
4. If pt. 3 is fullfilled than value of new slice created that way is bigger than slice of added elements.
5. So it has no sense try to create a new slice with lesser value by adding more than ONE element, because added elements will create a slice of even lesser value than one we try to create.
6. You can omit using double and dividing, by using multiplying and type int. But solution will less clear.

środa, 14 lutego 2018

How to compare folders

1. diff -rq folder1 folder2
-r - means recursive
-q - means give only differences

2. rsync -n -avrc /abc/home/sample1/* server2:/abc/home/sample2/
https://stackoverflow.com/a/19410791
rsync -n -avr --size-only --delete /abc/home/sample1/ server2:/abc/home/sample2/


3. using "meld".
It is slow, but graphical interface

4. using "find"
A good way to do this comparison is to use find with md5sum, then a diff.
Example:
Use find to list all the files in the directory then calculate the md5 hash for each file and pipe it to a file:
find /dir1/ -type f -exec md5sum {} \; > dir1.txt
Do the same procedure to the another directory:
find /dir2/ -type f -exec md5sum {} \; > dir2.txt
Then compare the result two files with "diff":
diff dir1.txt dir2.txt
This strategy is very useful when the two directories to be compared are not in the same machine and you need to make sure that the files are equal in both directories.
 https://stackoverflow.com/questions/16787916/difference-between-two-directories-in-linux

piątek, 26 sierpnia 2016

How to partialy enter a date in libreoffice calc 5

http://przepis-na-lo.pl/2013/03/automatyczne-rozpoznawanie-niepelnych-dat/
"Nowe problemy Wprowadzona zmiana spowodowała jeden dość istotny problem — w niektórych językach niemożliwe stało się szybkie wpisywanie dat za pomocą klawiatury numerycznej. We wspomnianym języku czeskim (ponownie: tak jak w polskim) separatorem liczb dziesiętnych jest przecinek, a nie kropka. W rezultacie użytkownicy prawą ręką mogą wpisać „13,02”, „13/02” oraz „13-02”, ale nie „13.02”; tymczasem tylko ten ostatni zapis pasuje do wzorca i zostanie potraktowany jako data. Tworzenie i modyfikowanie wzorców dat Aby rozwiązać ten problem, wprowadzono możliwość samodzielnego tworzenia wzorców dat. Odpowiednie pole zatytułowane jest Akceptowane wzorce dat i znajduje się w Narzędzia → Opcje... → Ustawienia językowe → Języki. Każdy wzorzec musi składać się z przynajmniej dwóch znaków — symbolu zastępczego fragmentu daty oraz separatora. Dostępne są trzy symbole zastępcze: D (dzień), M (miesiąc) oraz Y (rok)."

niedziela, 31 lipca 2016

How to remove a plain text protecting single quote from all the selected cells in LibreOffice Calc?

http://superuser.com/questions/394092/how-to-remove-a-plain-text-protecting-single-quote-from-all-the-selected-cells-i You can remove the leading single quote (which actually isn't part of the string in the cell) using a regex-based search and replace: Search for all characters between the start and end of the string ^.*$ replace with match &

poniedziałek, 20 czerwca 2016

Language tool on libreoffice on ubuntu

Just this solution
On Ubuntu, install the libreoffice-java-common or openoffice.org-java-common package. One problem solved by this is getting a long error message with "NoClassDefFoundError" during installation (see screenshot). On Ubuntu, if you get a message similar to Exception in thread "Thread-402" java.awt.HeadlessException in LibreOffice/OpenOffice, see this stackoverflow answer. Note that the message might not appear in a dialog but only on the command line, so you might want to start LibreOffice/OpenOffice from a terminal window.

Java on ubuntu

How to find out version:
update-java-alternatives -l java -showversion java -version
How to install java8 sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk sudo update-alternatives --config java sudo update-alternatives --config javac And from oracle $ sudo add-apt-repository ppa:webupd8team/java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer How to remove
sudo apt-get purge openjdk-7-*
How to install: sudo apt-get install openjdk-7-jre or sudo apt-get install openjdk-7-jdk