Stand with Hong Kong avatar

數學 × 程式編寫比賽 (第八回) -- 我的解法

vincentyip

Published: 21 Oct 2017 › Updated: 21 Oct 2017數學 × 程式編寫比賽 (第八回) -- 我的解法

數學 × 程式編寫比賽 (第八回) -- 我的解法

這次我又參加了 kenchung@kenchung 的「數學 × 程式編寫比賽 (第八回)」了,真的非常益智和有趣!

帖文可到這裡看一看:https://steemit.com/contest/@kenchung/question-mathematics-programming-competition-8

要解決這條問題,我們首先要思考有那些數字在旋轉後會成為一個有意義的數字。我們可以由0-9999之中逐個數字檢查,嘗試將那數字旋轉,如果旋轉後是另一個有意義而且比自己大的數字,便在那個數字作標記。

所以檢查完成後,沒有標記的數字的數量便是我們的答案了!

程式如下:


var alts=[0,1,5,-1,-1,2,9,-1,8,6];

var log=[];
var x=0;

for(var i=0; i<10000; i++)
    log[i]=false;

for(var i=0; i<10000; i++){

    if(log[i]) continue;
    log[i]=true;
    x++;

    var b=i.toString();

    if(i<1000) b='0'+b;
    if(i<100) b='0'+b;
    if(i<10) b='0'+b;

    var q='';

    for(j=0; j<4; j++)
        q=alts[b[j]]+q;

    if(q.indexOf(-1)===-1)
        log[parseInt(q)]=true;

    console.log(b,q);
}
console.log(x);

希望可以得獎啦 :D

Leave 數學 × 程式編寫比賽 (第八回) -- 我的解法 to:

Written by

Fight for freedom, Stand with Hong Kong.

Read more #contest posts


Best Posts From Stand with Hong Kong

We have not curated any of vincentyip's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Stand with Hong Kong