成就代码
* * * *
拉格朗日计划
* * * *
成就代码

本页面包含了需要用特定语言解答特定问题的代码,除最难的“Hextreme Agony”、“Fish n Chips”、“Off-the-grid”三个成就外,其它成就的代码都已囊括。

因成就只需要代码正确就能完成,因此以下代码并不追求最短,事实上这些代码大部分是用代码转换工具在Python代码的基础上转换修改而成。

事实上“Hextreme Agony”、“Fish n Chips”、“Off-the-grid”这三个成就应当也需要通过代码转换来完成,否则很难想象要如何用如此抽象的语言来完成这些问题。

🧙 Alchemist
用Elixir正确解答生命游戏
defmodule X do
  def check(a,i) do
      cond do
      i<0 or i>1055->0
        String.at(a,i)=="#"->1
      true->0
      end   
  end
  def sum(a,i) do
    check(a,i-1)+check(a,i+1)+check(a,i-34)+check(a,i-33)+check(a,i-32)+check(a,i+32)+check(a,i+33)+check(a,i+34)
  end
end
arg=List.first(System.argv())
Enum.map(0..1055, fn x -> cond do 
  rem(x,33)==32 and x>0->"\n"
  X.sum(arg,x)==3 or X.sum(arg,x)+X.check(arg,x)==3->"#"
  true->"."
  end
end)|>IO.puts
📚 Archivist
用任意三种比ISBN更古老的语言正确解答ISBN码

经考证,ISBN诞生于1966年,并于1967年正式投入使用。可以肯定比ISBN更早的语言有BASIC(1964),COBOL(1959),LISP(1958),FORTRAN(1957),不确定用汇编(最早的汇编语言出现于20世纪40年代,但汇编有很多年代不同的版本,代码高尔夫站所使用的汇编版本显然晚于1966年)能否完成此成就。

以下三段代码从上到下使用的分别是BASIC,FORTRAN和LISP:
For i As Integer=1To __FB_ARGC__-1
	Dim k As Integer
  	Dim s As Integer
  	k=1
  	s=0	
	For j As Integer=1To 12
		If Mid(Command(i),j,1)<>"-"Then 
			s+=Val(Mid(Command(i),j,1))*k
			k+=1
		EndIf
	Next
	s=s Mod 11+48
	If s=58Then s=88
	Print Command(i)+Chr(s)
Next
character(len=12)::s
character::t
integer::i,j,k,c
do i=1,iargc()
 call getarg(i,s)
 k=1
 c=0
 do j=1,12
 t=s(j:j)
 if(t/="-")then
  c=modulo(c+k*(iachar(t)-48),11)
  k=k+1
 endif
 enddo
 t=achar(c+48)
 if(c==10)then
  t="X"
 endif
 print "(a)",s//t
end do
end
(loop for arg in *args*
do(setq k 1)
do(setq j 0)
do(
loop for i from 0 to 11
do(setq c (subseq arg i (+ i 1)))
(if(string/= c "-")
(progn(setq j (mod (+ j (* (parse-integer c) k)) 11))(setq k (+ k 1)))))
(if(= j 10)(setq c "X")(setq c (write-to-string j)))
do(write-line(concatenate 'string arg c))
)
🐦 Bird Is the Word
用AWK, Prolog, SQL, Swift, Tcl, Wren中的任意三种语言解答编辑距离

以下三段代码从上到下使用的分别是Swift,Tcl和Wren:
func d(s:String, t:String)->Int{
  let m=s.count
  let n=t.count
  if m==0{return n}
  if n==0{return m}
  var c=Array(0...n)
  for(i,c1)in s.enumerated(){
      c[0]=i+1
      var r=i
      for(j,c2)in t.enumerated(){
          let u=c[j+1]
          if c1==c2{c[j+1]=r}else{c[j+1]=1+min(c[j],u,r)}
          r=u
      }
  }
  return c[n]
}
proc d {s t} {
	if {![set n [string length $t]]} {
	return [string length $s]} elseif {![set m [string length $s]]} {
	return $n}
    for {set i 0} {$i<=$m} {incr i} {
	lappend d 0
	lappend p $i}
	for {set j 0} {$j < $n} {} {
	set tj [string index $t $j]
	lset d 0 [incr j]
	for {set i 0} {$i < $m} {} {
		set a [expr {[lindex $d $i]+1}]
		set b [expr {[lindex $p $i]+([string index $s $i] ne $tj)}]
		set c [expr {[lindex $p [incr i]]+1}]
		lset d $i [expr {$a<$b?$c<$a?$c:$a:$c<$b?$c:$b}]}
	set nd $p; set p $d; set d $nd}
	return [lindex $p end]}
foreach arg $argv {
	lassign [split $arg] a b
	puts [d $a $b] }
import "os" for Process
var w=Fn.new{|s,t|
    var x=s.count
    var y=t.count
    var d=List.filled(x+1, null)
    for (i in 0..x){
        d[i]=List.filled(y+1, 0)
        d[i][0]=i
    }
    for (j in 0..y)d[0][j]=j
    for (j in 1..y){
        for (i in 1..x){
            if(s[i-1]==t[j-1]){
                d[i][j]=d[i-1][j-1]
            }else{
                var m=d[i-1][j]
                if (d[i][j-1]<m) m=d[i][j-1]
                if (d[i-1][j-1]<m) m=d[i-1][j-1]
                d[i][j]=m+1
            }
        }
    }
    return d[-1][-1]
}
for (a in Process.arguments)System.print(w.call(a.split(" ")[0],a.split(" ")[1]))
🎳 COBOWL
用Cobowl正确解答保龄球
PROGRAM-ID. B.
DATA DIVISION
WORKING-STORAGE SECTION.
01 a pic X(99).
01 T.
05 R OCCURS 22 TIMES PIC 9(3).
01 I PIC 99.
01 J PIC 9(3).
01 K PIC 9(3).
01 S PIC 9(3).
01 c PIC X.
01 p PIC X.
01 q PIC X.
01 u PIC 9(3).
01 v PIC 9(3).
PROCEDURE DIVISION.
MAIN-LOGIC.
ACCEPT I FROM argument-number
PERFORM I times
  ACCEPT a FROM argument-value
  MOVE SPACES TO T
  MOVE 0 TO S
  MOVE 0 TO u
  MOVE 'a' TO q
  MOVE 'a' TO p
  INSPECT a REPLACING ALL '⑤' BY '5  '
  INSPECT a REPLACING ALL '⑥' BY '6  '
  INSPECT a REPLACING ALL '⑦' BY '7  '
  INSPECT a REPLACING ALL '⑧' BY '8  '
  PERFORM VARYING J FROM 1 BY 1 UNTIL J>LENGTH OF a
  MOVE a(J:1) TO c
  IF c <> SPACE THEN
    MOVE a(J:1) TO c
    EVALUATE c
    WHEN 'F' MOVE 0 TO R(u)
    WHEN '-' MOVE 0 TO R(u)
    WHEN 'X' MOVE 10 TO R(u)
    WHEN '/' MOVE 10 TO R(u)
    WHEN OTHER MOVE FUNCTION NUMVAL(c) TO R(u)
    END-EVALUATE
    IF c = '/' THEN
    MOVE u TO v
    SUBTRACT 1 FROM v
    SUBTRACT R(v) FROM R(u)
    END-IF
    IF q='/' OR (q='X' AND u<21) THEN
    ADD R(u) TO S
    END-IF
    IF p='X' THEN
    ADD R(u) TO S
    END-IF
    IF u<20 THEN
    ADD R(u) TO S
    END-IF
    ADD 1 TO u
    MOVE q TO p
    MOVE c TO q
  ELSE
    MOVE J TO K
    ADD 1 TO K
    MOVE a(K:1) TO c
    IF c='X' THEN
    ADD 1 TO u
    END-IF
  END-IF
  END-PERFORM
  IF S=0 THEN
  DISPLAY 0
  ELSE
  IF S<100 THEN
    DISPLAY S(2:2)
  ELSE
    DISPLAY S
  END-IF
END-PERFORM
👄 Dammit, Janet!
用Janet正确解答高级猜拳
(def t @{
"✂📄" "✂ cuts 📄"
"📄💎" "📄 covers 💎"
"💎🦎" "💎 crushes 🦎"
"🦎🖖" "🦎 poisons 🖖"
"🖖✂" "🖖 smashes ✂"
"✂🦎" "✂ decapitates 🦎"
"🦎📄" "🦎 eats 📄"
"📄🖖" "📄 disproves 🖖"
"🖖💎" "🖖 vaporizes 💎"
"💎✂" "💎 crushes ✂"
"📄✂" "✂ cuts 📄"
"💎📄" "📄 covers 💎"
"🦎💎" "💎 crushes 🦎"
"🖖🦎" "🦎 poisons 🖖"
"✂🖖" "🖖 smashes ✂"
"🦎✂" "✂ decapitates 🦎"
"📄🦎" "🦎 eats 📄"
"🖖📄" "📄 disproves 🖖"
"💎🖖" "🖖 vaporizes 💎"
"✂💎" "💎 crushes ✂"
})
(each arg (tuple/slice (dyn :args) 1)(def j (get t arg))(if (= j nil)(print "Tie"))(if j (print j)))  
🧠 Inception
用Brainfuck正确解答BF语言

以下代码的前半部分参考了该页面上的代码,与原帖设定不同的是,此处有多条输入,因而在结尾处需要清空寄存器中的数据并将指针复位,代码的后半部分就是清空和复位的代码。
>>>,[[>++++[-<-------->]<-[>+<<]>[----------[>]>[<+<+>>>>]<<<-[>]>[<+<+>>>>]<<<-[>]>[<+<+>>>>]<<<-[>]>[<-<+++>>>>]<<<--------------[>]>[<++<+>>>>]<<<--[>]>[<-<+++++++>>+>>]<<++++[-<------>]+<+[>]>[<++<+>>>>]<<<--[>]>[<<+>>>>]<<-<[+]<[>]>,>]<]<-[<]>[-[<<]>[<+[>]>>[<+[<<[<]<<-[>>]<[>>>>[>]>+<<[<]<]<-[>>]<[>>>>[>]>-<<[<]<]<++[->>+<<]>>[>]>]]<<<[<]>-<]>-[<<]>[<++[>]>+>[<-]<[<<[<]>[-<<+>>]>--[<<]>[[>]>+<<[<]<]>+[<<]>[[>]>-<<[<]<]>+[>]>]<<[<]>--<]>-[<<]>[[>]>>.<<<[<]<]>-[<<]>[[>]>>-<<<[<]<]>-[<<]>[[>]>>,<<<[<]<]>-[<<]>[[>]>>+<<<[<]<]>-[<<]>[[>]>>>[>>]>[<<<[<<]<+>>>[>>]>-]>[-]<<+[<[->>+<<]<]<[->>+<<]<[<]<]>-[<<]>[[>]>-[+>[-<<+>>]>]+<<[-]+[-<<]<[->>>[>>]>+<<<[<<]<]<[<]<]<++++++++>>[+<<->>]>]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[-]>[-]>[-]>,]
🎺 Sounds Quite Nice
用C, C#, D, F#中的任意三种语言解答和弦命名

以下三段代码从上到下使用的分别是C,C#和F#:
#include 
#include 
#define x(i,j)(i^=j^=i^=j)
int main(int u,char* w[]){
  char* d[]={"A","A♯","B♭","B","C♭","C","B♯","C♯","D♭","D","D♯","E♭","E","F♭","F","E♯","F♯","G♭","G","G♯","A♭"};
  int p[]={0,1,1,2,2,3,3,4,4,5,6,6,7,7,8,8,9,9,10,11,-1};
  int q[]={0,0,1,1,2,2,1,2,3,3,3,4,4,5,5,4,5,6,6,6,0};
  char s[]="ABCDEFG";
  int v[]={0,2,3,5,7,8,10};
  char* t="";
  char* x="";
  int a[3];
  int b[3];
  int i,j,k,r,z,m,n;
    for(i=1;ib[0]&&b[1]>b[2]){x(b[1],b[2]);x(a[1],a[2]);}
    if(b[0]>b[2]&&b[0]>b[1]){x(b[0],b[2]);x(a[0],a[2]);}
    if(b[1]-b[0]==2 && b[2]-b[0]==4){r=0;m=a[1]-a[0];n=a[2]-a[1];}
    else if(b[2]-b[1]==2 && 7+b[0]-b[1]==4){r=1;m=a[2]-a[1];n=12+a[0]-a[2];}
    else{r=2;m=12+a[0]-a[2];n=a[1]-a[0];}
    if(a[r]==v[b[r]]){t="";}else{t=a[r]>v[b[r]]?"♯":"♭";}
    if(m==4){x=n==3?"":"+";}else{x=n==3?"°":"m";}
    printf("%c%s%s\n",s[b[r]],t,x);
    }
    return 0;}
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] d = { "A", "A♯", "B♭", "B", "C♭", "C", "B♯", "C♯", "D♭", "D", "D♯", "E♭", "E", "F♭", "F", "E♯", "F♯", "G♭", "G", "G♯", "A♭" };
        int[] p = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, -1 };
        int[] q = { 0, 0, 1, 1, 2, 2, 1, 2, 3, 3, 3, 4, 4, 5, 5, 4, 5, 6, 6, 6, 0 };
        char[] s = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
        int[] v = { 0, 2, 3, 5, 7, 8, 10 };
        string t = "";
        string x = "";
        int[] a = new int[3];
        int[] b = new int[3];
        int i, j, k, r, z, m, n;
        for (i=0; i b[0] && b[1] > b[2]) {(b[1],b[2])=(b[2],b[1]);(a[1],a[2])=(a[2],a[1]); }
            if (b[0] > b[2] && b[0] > b[1]) {(b[0],b[2])=(b[2],b[0]);(a[0],a[2])=(a[2],a[0]); }
            if (b[1] - b[0] == 2 && b[2] - b[0] == 4) { r = 0; m = a[1] - a[0]; n = a[2] - a[1]; }
            else if (b[2] - b[1] == 2 && 7 + b[0] - b[1] == 4) { r = 1; m = a[2] - a[1]; n = 12 + a[0] - a[2]; }
            else { r = 2; m = 12 + a[0] - a[2]; n = a[1] - a[0]; }
            t = a[r] == v[b[r]] ? "" : (a[r] > v[b[r]] ? "♯" : "♭");
            x = m == 4 ? (n == 3 ? "" : "+") : (n == 3 ? "°" : "m");
            Console.WriteLine($"{s[b[r]]}{t}{x}");
        }
    }
}
open System
let notes = [|"A"; "A♯"; "B♭"; "B"; "C♭"; "C"; "B♯"; "C♯"; "D♭"; "D"; "D♯"; "E♭"; "E"; "F♭"; "F"; "E♯"; "F♯"; "G♭"; "G"; "G♯"; "A♭"|]
let p = [|0; 1; 1; 2; 2; 3; 3; 4; 4; 5; 6; 6; 7; 7; 8; 8; 9; 9; 10; 11; -1|]
let q = [|0; 0; 1; 1; 2; 2; 1; 2; 3; 3; 3; 4; 4; 5; 5; 4; 5; 6; 6; 6; 0|]
let s = "ABCDEFG"
let v = [|0; 2; 3; 5; 7; 8; 10|]

let swap (arr: _[]) i j =
    let temp = arr.[i]
    arr.[i] <- arr.[j]
    arr.[j] <- temp

[]
let main args =
    let mutable t = ""
    let mutable x = ""
    let a = Array.zeroCreate 3
    let b = Array.zeroCreate 3
    for arg in args do
        let h = arg.Split [|' '|]
        for k in 0..2 do
            for j in 0..20 do
                if h.[k] = notes.[j] then
                    a.[k] <- p.[j]
                    b.[k] <- q.[j]
        if b.[1] < b.[0] && b.[1] < b.[2] then
            swap b 0 1
            swap a 0 1
        if b.[2] < b.[0] && b.[2] < b.[1] then
            swap b 0 2
            swap a 0 2
        if b.[1] > b.[0] && b.[1] > b.[2] then
            swap b 1 2
            swap a 1 2
        if b.[0] > b.[2] && b.[0] > b.[1] then
            swap b 0 2
            swap a 0 2
        let mutable r = 0
        let mutable m = 0
        let mutable n = 0
        if b.[1] - b.[0] = 2 && b.[2] - b.[0] = 4 then
            r <- 0
            m <- a.[1] - a.[0]
            n <- a.[2] - a.[1]
        elif b.[2] - b.[1] = 2 && 7 + b.[0] - b.[1] = 4 then
            r <- 1
            m <- a.[2] - a.[1]
            n <- 12 + a.[0] - a.[2]
        else
            r <- 2
            m <- 12 + a.[0] - a.[2]
            n <- a.[1] - a.[0]
        if a.[r] = v.[b.[r]] then
            t <- ""
        else
            t <- if a.[r] > v.[b.[r]] then "♯" else "♭"
        if m = 4 then
            x <- if n = 3 then "" else "+"
        else
            x <- if n = 3 then "°" else "m"
        printfn "%c%s%s" s.[b.[r]] t x
    0