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

in #contest4 years ago

這次我又參加了 @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

Sort:  

程式看來不錯~

good post dear friend
thank you for sharing

Congratulations @vincentyip! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You got a First Reply
Award for the number of comments
Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @vincentyip! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

不错哦
竖大拇指