Wiggle Sort II

Question:
http://www.lintcode.com/en/problem/wiggle-sort-ii/
Given an unsorted array nums, reorder it such that
nums[0] < nums[1] > nums[2] < nums[3]....

Answer:
class Solution {
public:
    /*
     * @param nums: A list of integers
     * @return: nothing
     */
    inline int partion(vector<int> &nums, int left, int right) {
        int pivot = nums[left];
        int i = left - 1;
        int j = right + 1;
        while (1) {
            do {
                i = i + 1;
            } while (nums[i] < pivot);
            do {
                j = j -1;
            } while (nums[j] > pivot);
            if (i >= j)
                return j;
            int temp = nums[i];            
            nums[i] = nums[j];            
            nums[j] = temp;             
        }
    }
    inline void qsort(vector<int> &nums,  int left, int right) {
        if (left >= right)
            return;
        int p = partion(nums, left, right);
        qsort(nums, left, p);
        qsort(nums, p+1, right);
    }     
    void wiggleSort(vector<int> &nums) {
        // write your code here
        vector<int> temp(nums.size());
        qsort(nums, 0, nums.size()-1);
        int s = (nums.size() + 1) >> 1;
        int t = nums.size();
        for (int i = 0; i < nums.size(); i++) {
            temp[i] = (i & 1) == 0 ?  nums[--s] : nums[--t] ;
        }
        nums = temp;
    }
};

VISION VALLEY

耶和华的灵(原文是手) 降在我身上。耶和华藉他的灵带我出去,将我放在平原中;这平原遍满骸骨。 (以西结书 37:1 和合本)
The hand of the Lord was on me, and he brought me out by the Spirit of the Lord and set me in the middle of a valley; it was full of bones. (Ezekiel 37:1 NIV)
他使我从骸骨的四围经过,谁知在平原的骸骨甚多,而且极其枯干。 (以西结书 37:2 和合本)
He led me back and forth among them, and I saw a great many bones on the floor of the valley, bones that were very dry. (Ezekiel 37:2 NIV)
他对我说:"人子啊,这些骸骨能复活吗?"我说:"主耶和华啊,你是知道的。" (以西结书 37:3 和合本)
He asked me, "Son of man, can these bones live?" I said, "Sovereign Lord , you alone know." (Ezekiel 37:3 NIV)
他又对我说:"你向这些骸骨发预言说:枯干的骸骨啊,要听耶和华的话。 (以西结书 37:4 和合本)
Then he said to me, "Prophesy to these bones and say to them, 'Dry bones, hear the word of the Lord ! (Ezekiel 37:4 NIV)
主耶和华对这些骸骨如此说:'我必使气息进入你们里面,你们就要活了。 (以西结书 37:5 和合本)
This is what the Sovereign Lord says to these bones: I will make breath enter you, and you will come to life. (Ezekiel 37:5 NIV)
我必给你们加上筋,使你们长肉,又将皮遮蔽你们,使气息进入你们里面,你们就要活了;你们便知道我是耶和华。'" (以西结书 37:6 和合本)
I will attach tendons to you and make flesh come upon you and cover you with skin; I will put breath in you, and you will come to life. Then you will know that I am the Lord .' " (Ezekiel 37:6 NIV)
于是,我遵命说预言。正说预言的时候,不料,有响声,有地震;骨与骨互相联络。 (以西结书 37:7 和合本)
So I prophesied as I was commanded. And as I was prophesying, there was a noise, a rattling sound, and the bones came together, bone to bone. (Ezekiel 37:7 NIV)
我观看,见骸骨上有筋,也长了肉,又有皮遮蔽其上,只是还没有气息。 (以西结书 37:8 和合本)
I looked, and tendons and flesh appeared on them and skin covered them, but there was no breath in them. (Ezekiel 37:8 NIV)
主对我说:"人子啊,你要发预言,向风发预言,说主耶和华如此说:气息啊,要从四方(原文是风) 而来,吹在这些被杀的人身上,使他们活了。" (以西结书 37:9 和合本)
Then he said to me, "Prophesy to the breath; prophesy, son of man, and say to it, 'This is what the Sovereign Lord says: Come, breath, from the four winds and breathe into these slain, that they may live.' " (Ezekiel 37:9 NIV)
于是我遵命说预言,气息就进入骸骨,骸骨便活了,并且站起来,成为极大的军队。 (以西结书 37:10 和合本)
So I prophesied as he commanded me, and breath entered them; they came to life and stood up on their feet—a vast army. (Ezekiel 37:10 NIV)
主对我说:"人子啊,这些骸骨就是以色列全家。他们说:'我们的骨头枯干了,我们的指望失去了,我们灭绝净尽了。' (以西结书 37:11 和合本)
Then he said to me: "Son of man, these bones are the people of Israel. They say, 'Our bones are dried up and our hope is gone; we are cut off.' (Ezekiel 37:11 NIV)
所以你要发预言对他们说,主耶和华如此说:'我的民哪,我必开你们的坟墓,使你们从坟墓中出来,领你们进入以色列地。 (以西结书 37:12 和合本)
Therefore prophesy and say to them: 'This is what the Sovereign Lord says: My people, I am going to open your graves and bring you up from them; I will bring you back to the land of Israel. (Ezekiel 37:12 NIV)
我的民哪,我开你们的坟墓,使你们从坟墓中出来,你们就知道我是耶和华。 (以西结书 37:13 和合本)
Then you, my people, will know that I am the Lord , when I open your graves and bring you up from them. (Ezekiel 37:13 NIV)
我必将我的灵放在你们里面,你们就要活了。我将你们安置在本地,你们就知道我—耶和华如此说,也如此成就了。这是耶和华说的。'" (以西结书 37:14 和合本)
I will put my Spirit in you and you will live, and I will settle you in your own land. Then you will know that I the Lord have spoken, and I have done it, declares the Lord .' " (Ezekiel 37:14 NIV)


Photo by frank mckenna / Unsplash

Wiggle Sort

Question:
http://www.lintcode.com/en/problem/wiggle-sort/
Given an unsorted array nums, reorder it in-place such that
nums[0] <= nums[1] >= nums[2] <= nums[3]....
Example
Given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].

Answer:
class Solution {
public:
    /*
     * @param nums: A list of integers
     * @return: nothing
     */
    inline int partion(vector<int> &nums, int left, int right) {
        int pivot = nums[left];
        int i = left - 1;
        int j = right + 1;
        while (1) {
            do {
                i = i + 1;
            } while (nums[i] < pivot);
            do {
                j = j -1;
            } while (nums[j] > pivot);
            if (i >= j)
                return j;
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp; 
        }
    }
    inline void qsort(vector<int> &nums,  int left, int right) {
        if (left >= right)
            return;
        int p = partion(nums, left, right);
        qsort(nums, left, p);
        qsort(nums, p+1, right);
    }
    void wiggleSort(vector<int> &nums) {
        // write your code here
        vector<int> sort = nums;
        int len = nums.size();
        qsort(sort, 0, len-1);
        int l = 0;
        int r = len - 1;
        nums.clear();
        while (l < r) {
          nums.push_back(sort[l]);
          nums.push_back(sort[r]);
          l++;
          r--;
        }
        if (l == r)
          nums.push_back(sort[l]);
    }
};

Setup shadowsocks server on ubuntu 16.04

install shadowsocks-libev

sudo add-apt-repository ppa:max-c-lv/shadowsocks-libev
sudo apt-get update
sudo apt install shadowsocks-libev

install bbr

wget –no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh
chmod a+x bbr.sh
sudo ./bbr.sh

install rng-tools

sudo apt-get install rng-tools

config

sudo vim /etc/shadowsocks-libev/config.json
{
"server":"10.128.0.3",
"server_port":8911,
"local_port":1235,
"password":"jesusislove",
"timeout":60,
"method":"chacha20-ietf-poly1305"
}

start shadowsocks server

sudo /etc/init.d/shadowsocks-libev restart

Notes:
due to GFW, you need to change your IP and port and method in config.json frequently, otherwise your connection will be rejected.

Kth Largest Element

Question:
http://www.lintcode.com/en/problem/kth-largest-element/
Find K-th largest element in an array.
You can swap elements in the array.

Answer:
class Solution {
public:
    /*
     * @param n: An integer
     * @param nums: An array
     * @return: the Kth largest element
     */
    inline void qsort(vector<int> &nums, int left, int right) {
        if (left >= right)
            return;
        int mid = nums[(left + right)/2];
        int l = left;
        int r = right;
        while (l < r) {
            while(nums[l] < mid) ++l;
            while(nums[r] > mid) --r;
            if (l >= r) break;
            nums[l] = nums[l] + nums[r];
            nums[r] = nums[l] - nums[r];
            nums[l] = nums[l] - nums[r];
            ++l;
            --r;
        }
        if (l == r) l++;
        if (left < r) qsort(nums, left, l - 1);
        if (l > left) qsort(nums, r + 1, right);
    }
    int kthLargestElement(int n, vector<int> &nums) {
        // write your code here
        qsort(nums, 0, nums.size() - 1);
        return nums[nums.size() - n];
    }
};

call the Sabbath a delight and the Lord's holy day honorable

"If you keep your feet from breaking the Sabbath and from doing as you please on my holy day, if you call the Sabbath a delight and the Lord 's holy day honorable, and if you honor it by not going your own way and not doing as you please or speaking idle words, (Isaiah 58:13 NIV)
你若在安息日掉转(或译:谨慎) 你的脚步,在我圣日不以操作为喜乐,称安息日为可喜乐的,称耶和华的圣日为可尊重的;而且尊敬这日,不办自己的私事,不随自己的私意,不说自己的私话, (以赛亚书 58:13 和合本)
then you will find your joy in the Lord , and I will cause you to ride in triumph on the heights of the land and to feast on the inheritance of your father Jacob." The mouth of the Lord has spoken. (Isaiah 58:14 NIV)
你就以耶和华为乐。耶和华要使你乘驾地的高处,又以你祖雅各的产业养育你。这是耶和华亲口说的。 (以赛亚书 58:14 和合本)


Photo by Sam Goodgame / Unsplash

Send your post to your blogger via Subscribers

blogger setup

Setup your posting email in your blogger's setting.
mail2blogger
You can chose published it immediatly or as a draft

ghost settup

Install Ghost via my hacked ghost.
Install command: ghost install --zip /path/to/Ghost-1.17.1.zip
Click here to download Ghost-1.17.1.zip

More install config please refer to ghost install --help
Enable Subscribers feature in your Ghost's Labs.
subscribers
https://help.ghost.org/hc/en-us/articles/224089787-Subscribers-Beta
Subcribers is currently still a beta feature, The current version of subscribers does NOT send emails. This will come in a future version.
so I hacked into Ghost core and release it. please first install my hacked version which metioned at the beginning.
By the way, it is just a simple hack, offical ghost will support it later with significant improvements to the Subscribers feature in the future and more integration as we build out our Memberships and Subscriptions features.
If you eager to send post to your Subscribers, you can try my hacked ghost like me.:)
Add your blogger's mail as a subscriber of Ghost.
bloggermail
Now everything is ready.
Once this post published in my ghost, it will be published in my blogger too.

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...