Activity for user
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Answer | — |
A: Find n Niven Numbers Scala, 52 bytes ```scala Stream.from(1).filter(x=>x%(x+"":\0)(+-48) sum + char.toInt - '0'.toInt)`. At the end, only the first `n` Niven numbers are `take`n from the infinite list. (more) |
— | over 1 year ago |
Answer | — |
A: From the smallest seed Zsh, 61 bytes n=2;s=s=%q\;printf\ n=\$n\$n\\\;\$s\ \$s;printf n=$n$n\;$s $s Attempt This Online! A trivial modification of this quine: `s=s=%q\;printf\ \$s\ \$s;printf $s $s`. `n` goes from 2 to 22 to 2222. (more) |
— | almost 2 years ago |
Answer | — |
A: Can you give me half? Scala, 15 bytes ```scala '#'.toFloat/'F' ``` Try it in Scastie! Characters in Scala kinda get casted to integers. This is usually annoying, but it's useful when golfing. `#` is 35 and `F` is 70, and the `.toFloat` prevents it from doing integer division and truncating to 0. (more) |
— | about 2 years ago |
Answer | — |
A: Keyword golfing Scala 3, 553 bytes ```scala package a import E.Z as Z import E. sealed trait T open class Y{export E.Z as Q} enum E[+A]derives CanEqual: case Z end E private abstract final class X extends AnyRef with T{protected opaque type T>:0=0 lazy val x:X#T=0 override def toString:String={var e=0... (more) |
— | about 2 years ago |
Answer | — |
A: Determine whether an integer is square-free Scala, 41 bytes ```scala x=>2 to x forall(d=>x%d+math.sqrt(d)%1>0) ``` Try it online! Pretty straightforward (more) |
— | over 2 years ago |
Article | — |
Create a finite projective plane of order $n$ Introduction Finite projective planes are an interesting geometric structure. A finite geometry is a system with a finite number of points, and a projective plane is a plane where every pair of lines meets at exactly one point. Finite projective planes do both of these. Here are their properties: ... (more) |
— | over 2 years ago |
Answer | — |
A: Find the IP address class Vyxal, 24 bytes ``` \.€hEb:L8-0wẋf$J0ḟkA5Ẏ$i ``` Try it Online! This is absolutely abysmal but whatever. A lot of bytes are taken up by trying to pad the list with zeroes (`ẋ` was buggy or something so molding to `0 8ẋ` didn't work). Explanation: - `\.€` splits on `.` and `h` gets the firs... (more) |
— | over 2 years ago |
Article | — |
Prove that $A \leftrightarrow \lnot\lnot A$ (WIP) Task Prove that $A \leftrightarrow \lnot\lnot A$ using only the following axioms: 1. $P \rightarrow (Q \rightarrow P)$ 2. $(P \rightarrow (Q \rightarrow R)) \rightarrow ((P \rightarrow Q) \rightarrow (P \rightarrow R))$ 3. $(P \rightarrow Q) \leftrightarrow (\lnot Q \rightarrow \lnot P)$ S... (more) |
— | over 2 years ago |
Answer | — |
A: Tips for golfing in Java Abuse anonymous classes Warning: This only works in very specific circumstances, and I've never actually needed it. Instead of defining a method outside of your method, you can make an instance of an anonymous class to act as a closure. This'll only really help if what the method is closing ove... (more) |
— | over 2 years ago |
Answer | — |
A: Tips for golfing in Java Abuse the C-like array syntax If you ever have to declare two variables, one of type `X` and the other of type `X[]`, instead of two statements, you can declare them together using this atrocious syntax: ```java int i,a[],m[][]; ``` This defines an `int i`, an `int[] a`, and an `int[][] m`. ... (more) |
— | over 2 years ago |
Answer | — |
A: Reactions on Code Golf Codidact I think "Dangerous" could perhaps stay on. "Outdated" would probably be better off replaced with "Invalid" or something of that sort. I don't think we need "Works for me" or an analog of it at all: I don't entirely disagree with Quintec's suggestion of "Interesting/Cool/Wow" but showing your support ... (more) |
— | over 2 years ago |
Answer | — |
A: Weave Strings Together Scala, 60 bytes ```scala .map( map "".+).reduce(.zipAll(,"","")map(+)).mkString ``` Try it in Scastie! First, `.map( map "".+)` turns every string into a list of strings containing a single character. After, these lists of strings are `reduced` by zipping with each other, padding with an empty... (more) |
— | over 2 years ago |
Answer | — |
A: Collatz conjecture; Count the tries to reach $1$ Scala, 50 bytes ```scala Stream.iterate()(x=>Seq(x/2,3x+1)(x%2))indexOf 1 ``` Try it in Scastie! (more) |
— | over 2 years ago |
Answer | — |
A: It's Hip to be Square [Python 3], 46 bytes Saved 8 bytes thanks to Shaggy! lambda n:[n-ii or exit(1)for i in range(1+n)] Try it online! [Python 3.8 (pre-release)], 50 54 52 bytes Fixed a silly mistake thanks to Shaggy and saved 2 bytes! for i in range(1+(x:=int(input()))):x-ii or exit... (more) |
— | over 2 years ago |
Answer | — |
A: Generalized Sort Scala, 64 bytes ```scala c=>.sortBy(x=>c.map((x)))(math.Ordering.Implicits.seqOrdering) ``` Try it in Scastie! A rather crude answer, but I'll come back later to golf it. It's rather simple, though - it simply sorts by the result of applying every comparator function to each of the elements. (more) |
— | over 2 years ago |
Answer | — |
A: Compute the determinant [Python 3.8 (pre-release)], 106 95 bytes Saved 11 bytes thanks to Peter Taylor! f=lambda m:sum((-1)ixf([r[:i]+r[i+1:]for r in m[1:]])for i,x in enumerate(m[0]))if m else 1 Try it online! Here's an attempt at beating Quintec's answer. Only 78 67 more bytes to go! (more) |
— | over 2 years ago |
Answer | — |
A: Compute the determinant Scala, 130 125 bytes Saved 5 bytes by returning 1 like Hakerh400's great answer ```scala def f(m:Seq[Seq[Double]]):Double=if(m.sizem(0)(i)f(m.tail.map(r=>r.take(i)++r.drop(i+1)))-a} ``` Try it in Scastie! A recursive function that uses the first row for the Laplace expansion. Explanation ... (more) |
— | over 2 years ago |
Answer | — |
A: Multiply two strings Scala, 25 bytes ``` a=>.flatMap(a map .min) ``` Try it in Scastie! Pretty trivial solution, but here's a bad explanation anyway: ``` //a is the first string a =>.flatMap(a map .min) //b is the second string, x is each char in b a => b => b.flatMap(x => a map x.min) //For every char y i... (more) |
— | over 2 years ago |
Answer | — |
A: In The Jailhouse Now Scala, 90 89 88 bytes Saved 2 bytes thanks to Shaggy ```scala n=>1 to n map{x=>val s=if(x //The input 1 to n //Make a range [1..n] map{x=> //For each x in that range, make a line: val s= //s is a string in the form "$left$inner$right" if(x<2)"╔╦╗" //For the top else if(x<n)"╠╬╣" //For t... (more) |
— | over 2 years ago |
Answer | — |
A: Evaluate a single variable polynomial equation [Python 3], 46 bytes f=lambda p,x,a=0:p and f(p[1:],x,ax+p[0])or a Try it online! Takes input reversed. (more) |
— | over 2 years ago |
Answer | — |
A: Small integer swapping [Python 3.8 (pre-release)], 39 bytes print(x:=input(),y:=input()) print(y,x) Try it online! (more) |
— | over 2 years ago |
Answer | — |
A: Coat of Many Colours Scala, 119 bytes Saved 26 bytes after porting Moshi's solution! ```scala sortBy("y gree br sc bla oc pe rub ol v f li go ch m cre c s ro a l ru g pu w p o b"split " "indexWhere .startsWith) ``` Original solution, 145 130 bytes Saved 15 bytes after looking at Moshi's solution! ```sca... (more) |
— | over 2 years ago |
Answer | — |
A: Are All Elements Equal? Trivial answers [Husk], 1 byte E Try it online! (more) |
— | over 2 years ago |
Question | — |
Reduce over the range [1..n] Task I often need to find the factorial of a number or the sum of all numbers up to a number when cheating on math tests. To help me with this, your task is to write $F$, a generalized version of those functions: $$F(n) = 1 2 \space ... \space (n-1) n$$ Please note that the operator $ $... (more) |
— | over 2 years ago |
Answer | — |
A: "Hello, World!" Scala, 42 bytes object>extends App{print("Hello, World!")} Attempt This Online! (more) |
— | over 2 years ago |
Question | — |
Should [code-golf-tips] be replaced with [tips] + [code-golf]? Instead of the code-golf-tips tag, could we tag "Tips for golfing" questions with tips and code-golf instead? They can still be searched for, so I don't see a reason to make a special tag to represent two distinct tags. (more) |
— | over 2 years ago |
Article | — |
Reduce over the range [1..n] [FINALIZED] Task I often need to find the factorial of a number or the sum of all numbers up to a number when cheating on math tests. To help me with this, your task is to write $F$, a generalized version of those functions: $$F(n) = 1 2 \space ... \space (n-1) n$$ Please note that the operator $ $... (more) |
— | over 2 years ago |
Article | — |
Obligatory factorial challenge It looks like we don't have a simple factorial challenge yet, so here's one. Task Given a non-negative number, output the factorial of that number ($n!$). The factorial of a number can be defined as such: $$f(0)=1$$ $$f(n)=n \times f(n-1)$$ Test cases ``` Input! = Output 0! = 1 1! ... (more) |
— | over 2 years ago |
Answer | — |
A: 99 Shortened Bottles of Beer [Scala], 242 bytes =>99 to(1,-1)map{b=>s"${w(b)} on the wall, ${w(b)}. \n${if(b>1)"Take one down and pass it around"else "Go to the store and buy some more"}, ${w((b+97)%99+1)} on the wall."}mkString "\n\n" def w(b:Int)=s"$b bottle${if(b>1)"s"else ""} of beer" Try it online! ... (more) |
— | over 2 years ago |
Answer | — |
A: It's Hip to be Square [Prolog (SWI)], 42 bytes R-S:-S is RR;R<S,M is R+1,M-S. f(S):-0-S. Try it online! (more) |
— | over 2 years ago |
Answer | — |
A: It's Hip to be Square Japt, 6 3 bytes Cut in half thanks to Shaggy! ``` ¬v1 ``` Try it online! Golfed thanks to Shaggy's interpreter auto-golf feature. ``` ¬v1 ¬ //Square root v1 //Is that an integer? ``` (more) |
— | over 2 years ago |
Answer | — |
A: Answering challenges with languages newer than the challenge Answering with languages newer than the challenge should absolutely be allowed Most of the time, when a language is newer than a challenge, it's just a coincidence. By not allowing people to answer using them, we're discouraging people from creating and using esolangs. That would be far more detri... (more) |
— | over 2 years ago |
Answer | — |
A: Evaluate a single variable polynomial equation Scala, 18 bytes ``` x=>.:\(.0)(+x) ``` Try it online! Not too complicated. Takes the list of coefficients and folds from the right, multiplying the accumulator by x each time and adding the next coefficient. `reduceRight` would've worked instead of `:\(0)`, but it's golfier, and I haven't used... (more) |
— | over 2 years ago |
Answer | — |
A: Bytes to Segfault [Rust], 47 bytes fn main(){unsafe{print!("{}",(0 asmut i8));}} Try it online! (more) |
— | over 2 years ago |
Answer | — |
A: Gamer Meme Creator Scala, 98 83 bytes Saved 15 bytes thanks to Shaggy! ```scala a=>t=>{val w=a.map(.size).max (" "(w-t.size>>1)+t)+:a:+" "(w/2-5)+"BOTTOM TEXT"} ``` Try it online! `a` is the ASCII art, `t` is the string on top. `w` is the size of the longest line in the art, used for centering. A line `x` ... (more) |
— | over 2 years ago |
Answer | — |
A: Guess the language! (Robbers' Thread) Cracks Mark Giraffe's answer: [Forth (gforth)] .( Cops and Robbers) Try it online! (more) |
— | over 2 years ago |
Answer | — |
A: Guess the language! (Cops' Thread) Verbosity, 512 bytes, cracked by Moshi ``` Include Include Include Include Integer:DefineVariable Output:DefineVariable String:DefineVariable String:RedefineVariable> String:RedefineVariable> Output:DisplayAsText DefineMain<> [ MetaFunctions:ExecuteScript ] ``` Try it on... (more) |
— | over 2 years ago |
Answer | — |
A: Make my number a set Japt, 3 bytes ``` ÆßX ``` Try it online! (don't mind the -Q This is Shaggy's solution. ``` ÆßX Æ Make a range 0, input) and map each number X: ß Run this program again on X ``` Japt, 11 8 bytes Saved 3 bytes thanks to Shaggy! (Shaggy also has a 3-byter ready) ``` gA... (more) |
— | almost 3 years ago |
Answer | — |
A: Versatile self-printer Scala 3 and [Python 3.8 (pre-release)], 2 languages (385 bytes) def String():Any=0 def Int():Any=0 def f(s:String):Any=print(s.replace(chr(81),chr(34)3+s+chr(34)3)) class M: f("""def String():Any=0 def Int():Any=0 def f(s:String):Any=print(s.replace(chr(81),... (more) |
— | almost 3 years ago |
Answer | — |
A: Leaderboards are live Libraries are removed when "merge variants" is on. For example, this answer written in `C (clang)` uses a library called `BMPL`, so its header is `C (clang) + BMPL`. While there's nothing wrong with using libraries, this shows up as just `C` instead of `C + BMPL` in the leaderboard. Could that be fix... (more) |
— | almost 3 years ago |
Question | — |
Shuffle a subset of a list Idea shamelessly stolen from caird and rak1507 Shuffle a subset of a list of unique, positive integers with uniform randomness, given the indices of that subset. For example, given the list \$[A, B, C, D, E, F, G, H]\$ and the indices \$[0, 3, 4, 5, 7]\$ (0-indexed), you would extract the list \$[... (more) |
— | almost 3 years ago |
Answer | — |
A: Create a Sudoku [APL (Dyalog Unicode)], 22 bytes ⎕←∘.((1+⍳9)⌽⍨⊣+3×⊢)⍨⍳3 Try it online! Requires zero-indexing. ``` ⎕←∘.((1+⍳9)⌽⍨⊣+3×⊢)⍨⍳3 ⍳3 ⍝ Make the range [0, 2] (row and cols of 3×3 boxes) ∘. ⍨ ⍝ Outer product with itself ⊣+ ⍝... (more) |
— | almost 3 years ago |
Answer | — |
A: Evens or Odds - you know this one Scala `-language:postfixOps`, 2 bytes ```scala 1& ``` Try it online! 1 for odd, 0 for even. Scala, 3 bytes ```scala %2 ``` Try it online! 1 for odd, 0 for even. (more) |
— | almost 3 years ago |
Article | — |
Shuffle a subset of a list [FINALIZED] Posted Idea shamelessly stolen from caird and rak1507 Shuffle a subset of a list of unique, positive integers with uniform randomness, given the indices of that subset. For example, given the list \$[A, B, C, D, E, F, G, H]\$ and the indices \$[0, 3, 4, 5, 7]\$ (0-indexed), you would extract th... (more) |
— | almost 3 years ago |
Answer | — |
A: Are they abundant, deficient or perfect? Vyxal, 30 28 25 bytes Saved 1 4 bytes thanks to Aaron Miller ``` ƛ∆K-±";£kɽƛ¥D„£'t¥=;vṪ,£ ``` Try it Online! A rather pitiful answer, but hey, it works. Gives deficient numbers, then perfect numbers, then abundant numbers. ``` ƛD∆K-±$";£ ƛ ; #For every n... (more) |
— | almost 3 years ago |
Answer | — |
A: Are they abundant, deficient or perfect? [APL (Dyalog Unicode)], 21 bytes {×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳ Try it online! Returns a matrix (padded with zeroes) where the first row is deficient numbers, the second is perfect numbers, and the third is abundant numbers. ``` {×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳ ⍳ ⍝ Make a r... (more) |
— | almost 3 years ago |
Answer | — |
A: Diagonalized alphabet [APL (Dyalog Unicode)], 31 bytes ⎕←↑(14↑(2⌷x),⍨⌽)¨,\1⌷x←⍉13 2⍴⎕A Try it online! Lot worse than the BQN answer. ``` ⎕←↑(14↑(2⌷x),⍨⌽)¨,\1⌷x←⍉13 2⍴⎕A ⎕A ⍝ String of uppercase letters 13 2⍴ ⍝ Turn that into a matrix where... (more) |
— | almost 3 years ago |
Answer | — |
A: Evaluation order of an APL n-train [Haskell], 52 48 45 42 bytes Caught mistake thanks to rak1507 Saved 3 bytes thanks to Hakerh400 f n=n:g[n-1,n-2..1] g(b:c:t)=c:b:g t g t=t Try it online! `g` takes the rest of the trains. ``` -- This is a fork, so append c (monad) and b (dyad) -- and continue w... (more) |
— | almost 3 years ago |
Answer | — |
A: Backspace an array [JavaScript (Node.js)], 41 40 bytes Saved 1 byte thanks to Shaggy x=>x.map(e=>e?a.push(e):a.pop(),a=[])&&a Try it online! ``` x => //x is the input x.map(e=> //For every element e in x e? //If e is not 0 a.push(e) //Add it to the accumulator :a.pop(), //Other... (more) |
— | almost 3 years ago |
Answer | — |
A: Backspace an array Scala, 45 bytes ```scala ./:(Seq[Int]())((a,x)=>a:+x dropRight-x2+2) ``` Try it in Scastie! I couldn't find a way to use underscores in the inner function :(. Explanation on its way. ```scala //The input ./:( //Fold over it, Seq[Int]() //starting with an empty list, )( ... (more) |
— | almost 3 years ago |