Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 11490

The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.

0 votes

Nth Differences

Swift 4, 90 bytes func f(_ a:[Int])->Int{return a.contains{$0 != a[0]} ?f(zip(a, a.dropFirst()).map(-))+1:0} Alternative, closure-based implementation: var f: ((_ input: [Int]) -> Int)! f = {a in a.c …
Alexander's user avatar
  • 501
1 vote

A list of number modulus their indices in the list

Swift 4, 18 bytes zip(a,1...).map(%)
Alexander's user avatar
  • 501
0 votes

Normalize a Vector

Swift 4, 44 bytes {a in a.map{$0/sqrt(a.reduce(0){$0+$1*$1})}} Recalculates the vector norm for every component, but at least it's terse!
Alexander's user avatar
  • 501
1 vote

Get the best of two Arrays

Swift 4, 41 bytes {zip($0,$1).map{$0==$1 ?2*$0:max($0,$1)}} Test cases: let f: ([Float], [Float]) -> [Float] = {zip($0,$1).map{$0==$1 ?2*$0:max($0,$1)}} let testcases: [(inputA: [Float], inputB: …
Alexander's user avatar
  • 501
1 vote

Count Up, Replace, Repeat!

Swift 3, 58 Bytes Meant to run directly in the a playground, with n set to the input: var x=[n];for i in 0..<n{x=x.reduce([]){$0+[Int](1...$1)}} Ungolfed, with most short hand notation reverted: …
Alexander's user avatar
  • 501
1 vote

Fibonacci-orial

Swift, 68 Bytes func f(n:Int,_ a:Int=1,_ b:Int=1)->Int{return n<1 ?1:a*f(n-1,b,a+b)}
Alexander's user avatar
  • 501