Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Activity for user‭

Type On... Excerpt Status Date
Answer A: Juggler sequences
Scala, 78 67 64 bytes Saved 3 bytes thanks to Razetime ```scala Stream.iterate()(x=>math.pow(x,x%2+.5).toInt).takeWhile(>1):+1 ``` Try it in Scastie! ``` Stream.iterate() //Make an infinite list by repeatedly applying (x=> //the following function to the input math.pow(x...
(more)
about 3 years ago
Answer A: Golf a FRACTRAN interpreter
[APL (Dyalog Unicode)], 33 bytes {×x←⊃(2⌷⍵)(÷⍨(/⍨)0=|)⍺×1⌷⍵:x∇⍵⋄⍺} Try it online! The first case doesn't work because it gets really big, but the other two do. The input is taken on the left and the fractions are taken as a table on the right. ``` {×x←⊃(2⌷⍵)(÷⍨(/⍨)0=|)⍺×1⌷⍵:x...
(more)
about 3 years ago
Answer A: Make my number a set
[Haskell], 51 31 bytes Saved 20 bytes thanks to Hakerh400! data S=S[S] f i=S$map f[0..i-1] Try it online! `S` is a recursive data structure, because sets of varying element types can't be represented with simple lists in Haskell.
(more)
about 3 years ago
Answer A: Make my number a set
[APL (ngn/apl)], 6 bytes {∇¨⍳⍵} Try it online! Dyalog APL and dzaima/APL appear to not give empty vectors for `⍳0`, so I used ngn/APL. I don't know how to turn on boxing there, though, so there's extra processing code in the footer. ``` {∇¨⍳⍵} ⍵ ⍝ The input ⍳ ⍝ Mak...
(more)
about 3 years ago
Answer A: Length of a Sumac Sequence
[Scala], 83 bytes x=>x.init#::Stream.iterate(x)(x=>x++(x,x.tail).zipped.map(-))indexWhere(.last //List(t1, t2) a.k.a. the second partial sequence x.init //List(t1) a.k.a. the first partial sequence #:: //prepended to Stream //an infinite stream of partial sequences .iterate(x) ...
(more)
about 3 years ago
Answer A: Really Cool Numbers
[APL (Dyalog Unicode)], 30 29 bytes Saved 1 byte thanks to Razetime (could've saved 1 more with a tradfn, but I didn't feel like it) {∧/(0=1|+/÷≢)¨1↓¨g¨(g←∪⊢∨⍳)⍵} Try it online! This answer was incorrect before because it only checked if the number's proper divisors were cool,...
(more)
about 3 years ago
Answer A: Truthify an array
Scala 3, 68 bytes ```scala .zipWithIndex.flatMap(.zipWithIndex.filter(.1)map(.2)map .->) ``` Try it in Scastie! Takes a `List[List[Boolean]]`, returns a `List[(Int, Int)]`. This abuses underscores a bit (which is why Scala 3 is needed), but I'm proud of it. Explanation: ```scala .zipWithI...
(more)
about 3 years ago
Answer A: Beaver Code Decryption
APL(Dyalog Unicode), 34 29 bytes SBCS Saved 5 bytes thanks to Razetime! ``` {2>s←⌈2÷⍨≢⍵:⍵⋄,⍉↑∇¨s(↑,⍥⊂↓)⍵} ``` Try it on APLgolf! ``` {2>s←⌈2÷⍨≢⍵:⍵⋄,⍉↑∇¨s(↑,⍥⊂↓)⍵} { } ⍝ Define a dfn taking argument ⍵ s→ ⍝ s will be the size of on...
(more)
about 3 years ago
Answer A: Obligatory Quine Challenge
Scala 3, 80 bytes ```lang-scala @main def m={val s="@main def m={val s=%c%s%1$c;printf(s,34,s)}";printf(s,34,s)} ``` Try it in Scastie! The `printf` replaces `%c` and `%1$c` in string `s` with the quote character (34 in decimal), and replaces `%s` with the contents of `s`.
(more)
about 3 years ago
Answer A: Cumulative Counts
Scala 3, 50 44 bytes ```scala ? => ?.indices zip?map(?take +1 count .==) ``` Try it in Scastie! This is an annoying, stupid approach. The more elegant one using `inits` was much longer (`x=>x.inits.toSeq.reverse.tail zip x map( count .==)`). ```scala ? => //The input ?.indices //The ind...
(more)
about 3 years ago
Answer A: Cumulative Counts
[APL (Dyalog Unicode)], 11 7 bytes (SBCS) Razetime and rak1507 came up with 7 byte equivalents of my original dfn (this one's rak1507's). See their solutions below. +/¨⊢=,\ Try it online! ``` +/¨⊢=,\ ,\ ⍝ Prefixes of the list = ⍝ Compare every prefix ⊢ ⍝ to...
(more)
about 3 years ago
Answer A: Output 256 in many different ways
Scala (`-language:postfixOps`), 4 solutions 1. Just 256: ``` 256 ``` 2. Casting a character: ``` +'Ā' ``` The character `Ā` is 256 in decimal, and the unary `+` turns it into an `Int`. 3. Hashcode of a string: ``` ""## ``` There are two backspace characters in the string (\u0008...
(more)
about 3 years ago
Answer A: Solve Goldbach's Conjecture
[APL (Dyalog Unicode)], 32 bytes (SBCS) {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢∘.×)⍨1↓⍳⍵} Try it online! ``` {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢∘.×)⍨1↓⍳⍵} ⍳⍵ ⍝ Range from 1 to n 1↓ ⍝ Drop the 1st number (make 2 to n) (⊢∘.×)⍨ ...
(more)
about 3 years ago
Answer A: Tips for golfing in Scala
Making a function with `val` can be shorter than with a `def` If you're pattern matching, you can use Scala's special syntax and omit `match` when assigning an anonymous function to a `val`. As you can see, it's a lot shorter: ```scala val g:List[Int]=>Int={case h::t=>h+g(t)case =>0} def f(l:Li...
(more)
about 3 years ago
Question Tips for golfing in Scala
What general tips do you have for golfing in Scala? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Scala (e.g. "remove comments" is not an answer). This has been copied from a tips question on Code Golf SE.
(more)
about 3 years ago
Answer A: Word Set Square
Scala, 99 bytes ```scala s=>{val x=s+s.reverse s(0)+"\n"+x.tail.init.zipWithIndex.map{case(c,i)=>c+" "i+c+"\n"}.mkString+x} ``` Try it in Scastie!
(more)
about 3 years ago
Answer A: Reverse an ASCII string
Scala, 9 bytes ```scala .reverse ``` Try it in Scastie! Explanation: ``` .reverse //The function argument . //Call a method reverse //Reverse the string ```
(more)
about 3 years ago
Answer A: Partial Sums of Harmonic Series
[Scala], 55 bytes (Stream from 1 map 1.0./scanLeft.0)(+)indexWhere . Stream.from(1).map(1.0/).scanLeft(0.0)(+).indexWhere( >= n) ``` Explanation: ```scala ( Stream from 1 //Make an infinite list of integers, starting at 1 map 1.0./ //Find the reciprocal of each (d...
(more)
about 3 years ago