Chris Bouchard
  • Member for 6 years, 3 months
  • Last seen this week
Open or Close the Parentheses
6 votes

C (clang) on Linux, 82 79 66 62 bytes c;f(*x){for(c=0;*x;++x)*x&22?:*x&1?--c:++c;c*=*--x&16|*x==41;} Try it online! Expects a nul-terminated ASCII wide string (4 bytes per character). ...

View answer
Is it an elementary matrix?
3 votes

Core Maude, 315 302 286 277 276 273 268 bytes mod E is pr LIST{Int}. ops e i : Int ~> Int . var A B N X Y Z :[Int]. ceq e(N X A Y B Z)= 1 if(size(X)rem N + size(Y)rem N)size(A)size(B)i(N 0)X B Y A ...

View answer
Drop down the numbers
3 votes

Core Maude, 248 244 236 bytes load linear mod D is inc MATRIX{Nat0}*(sort Matrix{Nat0}to M). var A B C D : Nat . op d : Nat M -> M . eq(A,B)|-> C ;(A,B)|-> D =(A,B)|-> max(C,D). eq d(A,(B,...

View answer
List array elements which can be summed from other elements
3 votes

Core Maude, 261 275 263 bytes mod A is pr LIST{Int}*(sort List{Int}to L). op f : L -> L . op _,_ : L L -> L . op _,_,_ : L L L ~> Bool . vars A B C D E : L . eq f(A)= A,nil . ceq A B C,D = A ...

View answer
Harmonic divisor numbers
2 votes

Core Maude, 248 bytes mod H is pr LIST{Rat}. ops o h : Rat ~> Rat . var A B C D : Rat . eq o(A)= o(2 A). eq o(s A 0)= A . eq o(A s B)= o(s A(B + ceiling(frac(h(A A 0 0))))). eq h(A s B C D)= h(A B(...

View answer
Constructing Solar Panels from Squares
2 votes

Core Maude, 245 bytes mod S is pr LIST{Nat}. ops([_])([_})({_]): Nat ~> Nat . var A B : Nat . eq[A]=[A 0]. ceq[A B]=[A B}if A ={[A B}]. eq[A B]=[A s B][owise]. eq[A s B}=((s B rem s A)^ 2)[A(s B ...

View answer
Rotate N Values in a List
2 votes

Core Maude, 242 219 bytes mod R is pr LIST{Nat}. ops r x : Nat Nat ~> Nat . var A B I J : Nat . var R X Y :[Nat]. ceq r(X A Y,I R)= X x(A I Y,R)if size(X)= I . ceq x(A I X B Y,J R)= B X x(A J Y,R)...

View answer
God is real . . . unless declared integer
2 votes

Core Maude, 271 bytes mod G is pr LIST{String}+ LEXICAL . op g : String ~> Qid . var A B C D :[Qid]. var X Y :[String]. ceq g(X Y)= A if A '`( B C D '`) := tokenize(Y)/\ C == 'G or substr(string(C),...

View answer
Swap Two Values in a List
2 votes

Core Maude, 158 bytes mod S is pr ARRAY{Nat,Nat0}*(sort Array{Nat,Nat0}to A). var I J X Y : Nat . op s : A Nat Nat -> A . eq s(A:A,I,J)= insert(I,A:A[J],insert(J,A:A[I],A:A)). endm Example Session ...

View answer
Multiply elements of the dihedral group
2 votes

Core Maude, 81 bytes mod D is inc LIST{Nat}. eq 0 0 0 0 = nil . eq 1 1 = nil . eq 1 0 = 0 0 0 1 . endm Example Session \||||||||||||||||||/ --- Welcome to Maude --- ...

View answer
Print a 10 by 10 grid of asterisks
2 votes

C, 47 bytes main(i){while(i<111)putchar(10|!!(i++%11)<<5);} Try it online. Not as compact as the other C answer (putchar is such a long name!), but I don't use the asterisk character in my ...

View answer
Open or Close the Parentheses
1 votes

Core Maude, 206 bytes mod B is pr LIST{Int}. ops b p : Nat ~> Nat . var A : Nat . var X Y Z :[Nat]. eq b(nil)= 0 . eq b(X A)= 0 ^((~ A & 16)*(A xor 41)+ 0 ^ p(X A)). eq p(nil)= 0 . eq p(A X)= 0 ...

View answer
How long till Halley's Comet returns?
1 votes

Core Maude, 266 263 262 204 bytes mod H is pr LIST{Nat}. op n : Nat ~> Nat . vars A B C : Nat . eq n(A)= n(A 66 5710855311372188087909795024940117969860147607). eq n(A B C)= if A > B then n(A(B +...

View answer
The Computer Thief
1 votes

Core Maude, 594 571 472 bytes in linear mod C is inc LIST{Set{IndexPair}}*(sort IndexPair to D). vars A B C : D . vars N M P Q : Nat . vars S T U X Y :[D]. op p : D D D ~> D . op f : D D D ~> ...

View answer
Compute matrix blockiness
1 votes

Core Maude, 319 317 bytes mod M is pr LIST{Nat}*(op size to z). ops b n : Nat Nat ~> Nat . var A B M N W X Y Z :[Nat]. eq b(M,W)= n(M,W s W). ceq n(M,W s N)= n(M,W N)if X A Y B Z := M /\ W rem N + ...

View answer
Swap every two elements in a list
1 votes

Core Maude, 115 bytes mod S is pr LIST{Nat}. op f : Nat ~> Nat . var A B : Nat . eq f(A B X:[Nat])= B A f(X:[Nat]). eq f(nil)= nil . endm The result is obtained by reducing the f function with the ...

View answer
Find the k-th order summary of a number
1 votes

Core Maude, 354 bytes mod R is pr LIST{Nat}+ CONVERSION . ops k s : Nat Nat ~> Nat . op f : Nat ~> String . var N K : Nat . var X Y :[Nat]. eq k(N,0)= N . eq k(N,s K)= k(rat(f(s(N,0 0 0 0 0 0 0 ...

View answer
Dynamic Memory Allocator — Shortest Code
1 votes

C (gcc) on Linux, 45 bytes #include<unistd.h> int*a(n){return sbrk(n);} Try it online! The sbrk system call on Linux moves the program break by the specified number of bytes, and returns a ...

View answer
Is it a prefix normal word?
1 votes

Core Maude, 186 bytes mod P is pr NAT-LIST . var L P F X Y Z :[Nat]. ops n c : Nat ~> Nat . ceq n(L)= F if P X 2 Y F Z := L 2 L /\ size(P)= size(F)/\ c(F)> c(P). eq c(X 1 Y)= s c(X Y). eq c(L)= ...

View answer
Compute the generalised XOR
1 votes

Core Maude, 155 bytes mod X is pr INT . vars B X Y : Nat . op f : Nat Nat Nat -> Nat . eq f(0,0,B)= 0 . eq f(X,Y,B)= B * f(X quo B,Y quo B,B)+((B - 1)*(X + Y))rem B[owise]. endm The answer is ...

View answer
Exact generalised harmonic numbers
1 votes

Core Maude, 111 bytes fmod H is pr RAT . op __ : Nat Nat -> Rat . vars N M : Nat . eq 0 M = 0 . eq(s N)M = 1 / s N ^ M +(N M) . endfm Example Session \||||||||||||||||||/ --...

View answer
Remove submatrices
0 votes

Core Maude, 310 bytes in linear mod R is pr INT-MATRIX *(sort IntMatrix to M). op r : M M -> M . op t : Int Int M M -> Int . var A B C D E : Int . var W X Y Z : M . ceq r((A,B)|-> E ; X ; Y,Z)...

View answer
How long is the number in this base?
0 votes

Core Maude, 107 bytes mod B is pr NAT . op f : Nat Nat -> Nat . vars N B : NzNat . eq f(N,B)= s f(N quo B,B). eq f(0,B)= 0 . endm The answer is obtained by reducing the f function with \$n\$ and \$...

View answer
Prime Factorization - but on the exponents too
0 votes

Core Maude, 283 bytes mod F is ex RAT *(sort Nat to N). op __ : N N -> N[id: 1]. op e : N N -> N[right id: 1]. vars A B C D : N . eq e(A,0)= 1 . op f : N -> N . eq f(A)= A,2,0 . op _,_,_ : N ...

View answer
Peter is a picky eater!
0 votes

Core Maude, 257 bytes fmod P is pr SORTABLE-LIST{Nat<}*(sort List{Nat<}to L). var L : L . var X N :[L]. op b : L -> Nat . op _,_ : L Nat -> Nat . eq b(L)= L,0 . eq L,N = d(sort(L),s N),s N ...

View answer
Fill in the Minesweeper clues
0 votes

C, 152 150 147 145 bytes i,j,r,c;f(B,R,C)char**B;{for(i=R*C;i--;)for(j=9;j--;){char*b=B[i/C]+i%C;r=i/C+j/3-1;c=i%C+j%3-1;r<0|c<0|r/R|c/C|*b&8||(*b=16|*b+(B[r][c]==42));}} Input is in the ...

View answer