(ต้องขอบคุณ El'endia Starman และ Sp3000 ที่ช่วยฉันออกแบบเคสสำหรับเรื่องนี้!)
กำหนดจำนวนเต็มบวกn
และรายการของช่วงเวลาการหมุนจำนวนเต็มบวกสำหรับจำนวนเข็มนาฬิกา (เป็นวินาที) ส่งออกจำนวนเต็มบวกที่เล็กที่สุดx
โดยที่x
วินาทีหลังจากเริ่มนาฬิกาโดยที่เข็มทุกเข็มn
อยู่ในแนวเดียวกัน พวกเขาไม่จำเป็นต้องจัดตำแหน่งที่ตำแหน่งเริ่มต้น - ตำแหน่งใด ๆ ก็ดีตราบเท่าที่x
เป็นจำนวนเต็มและถูกย่อให้เล็กสุด นอกจากนี้ไม่จำเป็นต้องจัดตำแหน่งมือทั้งหมดในตำแหน่งเดียวกัน - สำหรับn=4
วิธีแก้ปัญหาที่จัดกลุ่มมือ 2 กลุ่ม 2 กลุ่มให้ถูกต้อง กลุ่มจะต้องมีขนาด 2 หรือมากกว่า - มือที่ไม่ได้จัดแนวสองมือนั้นไม่ถือเป็น 2 กลุ่มของ 1 มือที่ถูกปรับแนวเดียวดังนั้นจึงไม่ใช่วิธีแก้ปัญหาที่ถูกต้อง
คุณอาจสันนิษฐานว่าเฉพาะอินพุตที่เป็นไปได้ที่จะมีการn
จัดตำแหน่งของมืออย่างแน่นอนหลังจากจำนวนเต็มของวินาทีจะได้รับ - 2, [3,3,3]
ไม่ใช่อินพุตที่ถูกต้องเพราะหลังจากจำนวนวินาทีใด ๆ ทั้ง 3 มือจะได้รับการจัดตำแหน่งและดังนั้นจึงเป็นไปไม่ได้ เพื่อให้ได้ตำแหน่งที่ตรงกัน 2 ตำแหน่ง
ตัวอย่าง:
2, [3,4] -> 12
(the only option is a multiple of 12, so we pick 12 - 4 and 3 full rotations, respectively)
3, [3,5,6,9,29] -> 18
(picking 3, 6, and 9, the hands would align after 6, 3, and 2 rotations, respectively)
2, [1,1,4,5,10] -> 1
(picking 1 and 1 - note that 0 is not a valid answer because it is not a positive integer)
3, [2,2,6,7,11] -> 3
(picking 2, 2, and 6 - the 2s would be halfway through their second revolution, and the 6 would be halfway through its first revolution)
2, [2,7,5,3,3] -> 1
(picking 3 and 3, they are always aligned, so 1 is the minimum)
5, [4, 14, 36, 50, 63, 180, 210] -> 45
(after 45 seconds, the first, third, and sixth are aligned, as well as the second and seventh, for a total of 5)
ข้อมูลการทดสอบ:
7, [10, 22, 7, 6, 12, 21, 19] -> 87780
6, [25, 6, 2, 19, 11, 12] -> 62700
6, [23, 1, 8, 10, 9, 25] -> 41400
7, [6, 4, 1, 8, 10, 24, 23] -> 920
3, [18, 5, 23, 20, 21] -> 180
5, [10, 8, 14, 17, 5, 9] -> 2520
6, [1, 18, 12, 9, 8, 10, 23] -> 360
6, [12, 11, 6, 23, 25, 18, 13] -> 118404
4, [18, 11, 2, 9, 12, 8, 3] -> 8
7, [18, 25, 9, 13, 3, 5, 20] -> 11700
2, [17, 20, 15, 8, 23, 3] -> 15
3, [16, 3, 24, 13, 15, 2] -> 24
5, [7, 23, 24, 8, 21] -> 1932
6, [16, 10, 12, 24, 18, 2, 21] -> 720
6, [1, 17, 16, 13, 19, 4, 15] -> 53040
2, [3, 4, 20] -> 5
3, [9, 4, 16, 14, 1, 21] -> 16
5, [5, 17, 10, 20, 12, 11] -> 330
2, [21, 5, 22, 18] -> 90
4, [7, 25, 2, 8, 13, 24] -> 84
4, [13, 19, 2, 20, 7, 3] -> 420
5, [4, 14, 36, 50, 63, 180, 210] -> 45
5, [43, 69, 16, 7, 13, 57, 21] -> 27664
3, [22, 46, 92, 43, 89, 12] -> 276
4, [42, 3, 49, 88, 63, 81] -> 882
6, [2, 4, 7, 10, 20, 21, 52, 260] -> 65
6, [2, 3, 4, 7, 10, 20, 21, 52, 260] -> 35
2, [3, 4] -> 12
3, [3, 5, 6, 9, 29] -> 18
2, [1, 1, 4, 5, 10] -> 1
3, [2, 2, 6, 7, 11] -> 3
3, [41, 13, 31, 35, 11] -> 4433
3, [27, 15, 37, 44, 20, 38] -> 540
5, [36, 11, 14, 32, 44] -> 22176
3, [171, 1615, 3420] -> 3060
3, [46, 36, 12, 42, 28, 3, 26, 40] -> 36
5, [36, 25, 20, 49, 10, 27, 38, 42] -> 1350
4, [40, 28, 34, 36, 42, 25] -> 2142
5, [24, 26, 47, 22, 6, 17, 39, 5, 37, 32] -> 1248
4, [9, 27, 12, 6, 44, 10] -> 108
กฎ:
- ช่องโหว่มาตรฐานเป็นสิ่งต้องห้าม
- นี่คือรหัส - กอล์ฟดังนั้นรหัสที่สั้นที่สุดชนะ!
ลีดเดอร์บอร์ด
สแต็คส่วนย่อยที่ด้านล่างของโพสต์นี้สร้างกระดานแต้มนำจากคำตอบ a) เป็นรายการของวิธีแก้ปัญหาสั้นที่สุดต่อภาษาและ b) เป็นกระดานแต้มนำโดยรวม
เพื่อให้แน่ใจว่าคำตอบของคุณปรากฏขึ้นโปรดเริ่มคำตอบด้วยหัวข้อโดยใช้เทมเพลต Markdown ต่อไปนี้:
## Language Name, N bytes
ที่N
มีขนาดของส่งของคุณ หากคุณปรับปรุงคะแนนของคุณคุณสามารถเก็บคะแนนเก่าไว้ในบรรทัดแรกโดยการตีพวกเขาผ่าน ตัวอย่างเช่น
## Ruby, <s>104</s> <s>101</s> 96 bytes
หากคุณต้องการรวมหลายตัวเลขไว้ในส่วนหัวของคุณ (เช่นเนื่องจากคะแนนของคุณคือผลรวมของสองไฟล์หรือคุณต้องการแสดงรายการการลงโทษการตั้งค่าสถานะของล่ามแยกต่างหาก) ตรวจสอบให้แน่ใจว่าคะแนนจริงเป็นตัวเลขสุดท้ายในส่วนหัว:
## Perl, 43 + 2 (-p flag) = 45 bytes
คุณยังสามารถทำให้ชื่อภาษาเป็นลิงก์ซึ่งจะปรากฏในตัวอย่างข้อมูล:
## [><>](http://esolangs.org/wiki/Fish), 121 bytes
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 64424; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 45941; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>