Skip to main content
Share Your Experience: Take the 2024 Developer Survey
13 votes

Compute the degree of a string

JavaScript (ES6), 38 bytes Straightforward formula Expects an array of ASCII codes. a=>a.map(t=c=>t=-~t-(a+4-[a=c])%3)|t/3 Try it online! JavaScript (ES6), ...
Arnauld's user avatar
  • 193k
7 votes

Compute the degree of a string

Cubical Agda, 1134 bytes Uses Agda 2.6.4.3, the cubical library 0.7 and the standard library 2.0. ...
Naïm Favier's user avatar
7 votes

Compute the degree of a string

Python 3.8 (pre-release), 50 bytes lambda a,*s:int(sum(-(a+~(a:=b))%3-1for b in s)/3) Try it online! -5 bytes thanks to Neil -5 bytes thanks to Albert.Lang Port ...
Jitse's user avatar
  • 7,246
5 votes

*Trivial* near-repdigit perfect powers

JavaScript (Node.js), 53 bytes n=>(c='14918149114891'[n%14]).padEnd(n/7*3+3.5-c/9,0) Try it online! -2 from Arnauld -1 from Tbw
l4m2's user avatar
  • 24.4k
5 votes

*Trivial* near-repdigit perfect powers

Pyth, 26 bytes KT#=*KTj*LKf!%lPK%T5j1489T Try it online! Outputs the infinite sequence. Explanation ...
CursorCoercer's user avatar
5 votes

Compute the degree of a string

Rust, 67 66 bytes |a|a[1..].iter().fold((0,a[0]%3),|(b,c),d|(b-(c+!d)%3-1,*d%3)).0/3 Attempt This Online! Now handles repeats
mousetail's user avatar
  • 12.6k
4 votes

Compute the degree of a string

Jelly, 12 bytes _ƝNA¡€ṠS÷3r` A monadic Link that accepts a list of the walked vertices' ASCII codes/byte values and yields a singleton list containing the net ...
Jonathan Allan's user avatar
4 votes

Compute the degree of a string

05AB1E, 13 11 bytes ÇÔ¥3%É·<O3÷ -2 bytes porting @LuisMendo's MATL answer, so make sure to upvote that answer as well! Input as a string. (If we're allowed to ...
Kevin Cruijssen's user avatar
3 votes

*Trivial* near-repdigit perfect powers

05AB1E, 25 20 bytes ∞¦°εŽ5×SDyÒgs5%ÖÏ*}˜ -5 bytes porting @CursorCoercer's Pyth answer, so make sure to upvote that answer as well! Outputs the infinite sequence. ...
Kevin Cruijssen's user avatar
3 votes

*Trivial* near-repdigit perfect powers

Charcoal, 37 bytes NθI…ΦE⊗θ×I§1489ιXχ⁺²÷ι⁴¬﹪⊖Lι⁻³↔⁻²﹪κ⁴θ Try it online! Link is to verbose version of code. Explanation: ...
Neil's user avatar
  • 171k
2 votes

*Trivial* near-repdigit perfect powers

APL+WIN, 46 bytes Prompts for number of terms: n↑1↓m[⍋m←∊((↑¨m)*3),((m←iר⊂2 3)*2),i←10*⍳n←⎕] Try it online! Thanks to Dyalog Classic
Graham's user avatar
  • 6,226
2 votes

How many partitions do I have?

Desmos, 53 52 bytes f(n)=g(n,n) g(n,m)=\{mn<1:0^{nn},g(n,m-1)+g(n-m,m)\} Try it on Desmos! Try it on Desmos! - Prettified Note that pasting this as-is will ...
fireflame241's user avatar
  • 16.3k
2 votes

*Trivial* near-repdigit perfect powers

TI-BASIC, 64 bytes Input T For(I,1,T ₁₀^(I→P 8P³→L₁(1+dim(L₁ augment(L₁,augment(seq(J²P²,J,2,3),{10P→L₁ End SortA(L₁ L₁(T This calculates the sequence, sorts it (...
Sylvester is on codidact.com's user avatar
2 votes

*Trivial* near-repdigit perfect powers

Vyxal 3, 17 bytes …ɾĖ:∥ᵛTd∥3*;²WfSi Try it Online! Uses the latest technology of arity grouping and properly implemented parallel apply. Ports my Vyxal 2 answer.
lyxal's user avatar
  • 33.5k
2 votes

*Trivial* near-repdigit perfect powers

Vyxal, 18 bytes ⇧ɾ↵:₌vTd:3e‟"²Wfsi Try it Online! A silly little answer. 1-indexed, outputs the nth item. Explained ...
lyxal's user avatar
  • 33.5k
2 votes

How far are you?

Ruby, 105 bytes ->z,p,q{a,b,c,d,e=(z<<p-q).flat_map{|j|(1i**j/=90r).rect} p Math.acos(m=a*c*e+b*d)*r=6371,(2-m*2)**0.5*r} 4 bytes saved thanks to Dingus. ...
Level River St's user avatar
2 votes

How far are you?

Jelly, 25 bytes I;°ḊÆS,ÆẠƲP€SÆAHÆSḤ,Ʋ×⁽ßx A dyadic Link that accepts the longitudes on the left and the latitudes, in the same order, on the right and yields the ...
Jonathan Allan's user avatar
2 votes

Compute the degree of a string

Google Sheets, 100 bytes ...
doubleunary's user avatar
  • 1,705
2 votes

Compute the degree of a string

MATL, 13 bytes dXzI\oEqsI/Zo Try it online! or verify all test cases. Explanation ...
Luis Mendo's user avatar
  • 105k
1 vote

Compute the degree of a string

05AB1E, 9 bytes Ç¥>3%<O3÷ Attempt This Online! ...
alephalpha's user avatar
  • 48.2k
1 vote

Compute the degree of a string

Charcoal, 22 bytes ﹪%d∕ΣEΦθκ⊖﹪⊕⁻℅ι℅§θ곦³ Try it online! Link is to verbose version of code. Explanation: ...
Neil's user avatar
  • 171k
1 vote

How far are you?

Charcoal, 66 bytes ⊞θ⁻⊟θ⊟θ≔ΣE⪪.imag.real⁵ΠE…θ⁺²κUV⁺IXI1j∕λ⁹⁰ιθI×⁶³⁷¹⟦▷math.acosθ₂⁻²⊗θ Attempt This Online! Link is to verbose version of code. Takes input as an ...
Neil's user avatar
  • 171k
1 vote

*Trivial* near-repdigit perfect powers

Perl 5 -Mbigint -p, 71 bytes $_=(sort{(log$a)-log$b}map{$z=10**$_,4*$z**2,9*$z**2,8*$z**3}1..$_)[$_] Try it online! Takes <...
Xcali's user avatar
  • 15.2k
1 vote

*Trivial* near-repdigit perfect powers

Python 3, 110 bytes n=int(input());k=lambda x,y:[x*(10**y)**i for i in range(1,n+1)];print(sorted(k(1,1)+k(4,2)+k(8,3)+k(9,2))[n]) Try it online! This answer is a ...
None1's user avatar
  • 931
1 vote

The Euclidean Algorithm (for finding the greatest common divisor)

C(gcc), 74 bytes g(a,b){b?printf("%d=(%d*%d)+%d\n",a,b,a/b,a%b),g(b,a%b):printf("%d\n",a);} code test: ...
Rosario's user avatar
  • 341
1 vote

The Euclidean Algorithm (for finding the greatest common divisor)

R, 90 82 bytes -8 bytes golfed by pajonk `?`=\(a,b)`if`(a<b,b?a,{cat(a,'= (',b,"*",a%/%b,') +',x<-a%%b,' ');`if`(x,b?x,b)}) Attempt This Online!
int 21h -- Glory to Ukraine --'s user avatar
1 vote

Infer pluses and minuses

T-SQL, 3378 bytes I saw this a few days ago, and was thinking of languages I could use to solve this problem. Ended up deciding to write the entire thing in a query on data.stackexchange.com because I ...
CrSb0001's user avatar
  • 391
1 vote

The Game of Cat And Mice | With Matrices

Python3, 287 bytes ...
Ajax1234's user avatar
  • 7,231
1 vote

The inverse Collatz Conjecture

Acc!!, 76 bytes Count i while N { i } Count i while _ { Write 49)*(_ Write 9 (_*3+1)/6^(_%2) Try it online! Intput and Output are both in unary
Mukundan314's user avatar
1 vote

The inverse Collatz Conjecture

Vyxal 3, 11 bytes э:ḃ[v½|Tꜝ}Ŀ Try it Online! Explanation ...
DLosc's user avatar
  • 39.7k

Only top scored, non community-wiki answers of a minimum length are eligible