Skip to main content
Saved 30 (!) bytes by using a lambda
Source Link
Copper
  • 4k
  • 1
  • 14
  • 29

Nim, 134 126 115 108108 78 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=lc[x=>lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int]

Defines thean anonymous procedure g, which requires the input passed in as a double-nested sequence and outputs as a 3-element array. The procedure can only be used as an argument to another procedure; to test, use the following wrapper:

import math,future
import strutils
proc test(x: seq[seq[int]] -> seq[int]) =
 echo x(#[ Insert your input here ]#)
test(x=>lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int])

A Nim sequence is an array with @ in front, like @[1, 2, 3]. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]

Nim, 134 126 115 108 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int]

Defines the procedure g, which requires the input passed in as a double-nested sequence and outputs as a 3-element array.

A Nim sequence is an array with @ in front, like @[1, 2, 3]. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]

Nim, 134 126 115 108 78 bytes

import math,future
x=>lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int]

Defines an anonymous procedure, which requires the input passed in as a double-nested sequence and outputs as a 3-element array. The procedure can only be used as an argument to another procedure; to test, use the following wrapper:

import math,future
import strutils
proc test(x: seq[seq[int]] -> seq[int]) =
 echo x(#[ Insert your input here ]#)
test(x=>lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int])

A Nim sequence is an array with @ in front, like @[1, 2, 3]. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]
Saved 7 bytes
Source Link
Copper
  • 4k
  • 1
  • 14
  • 29

Nim, 134 126 115115 108 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=result=lc[seq[int]=lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int]

Defines the procedure g, which requires the input passed in as a double-nested sequence and outputs as a 3-element array.

A Nim sequence is an array with @ in front, like @[1, 2, 3]. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]

Nim, 134 126 115 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=result=lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int]

Defines the procedure g, which requires the input passed in as a double-nested sequence and outputs as a 3-element array.

A Nim sequence is an array with @ in front, like @[1, 2, 3]. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]

Nim, 134 126 115 108 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int]

Defines the procedure g, which requires the input passed in as a double-nested sequence and outputs as a 3-element array.

A Nim sequence is an array with @ in front, like @[1, 2, 3]. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]
Saved 11 bytes
Source Link
Copper
  • 4k
  • 1
  • 14
  • 29

Nim, 134 126126 115 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=result=lc[round(sumseq[int]=result=lc[(lc[x[j][i]|(j<-0..7),int]).float/8sum+4).int|shr 3|(i<-0..2),int]

Defines the procedure g, which requires the input passed in as a double-nested sequence (aand outputs as a 3-element array.

A Nim sequence is an array with a @ in front, e.g.like @[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0@[1,0 2,0]] 3]) and outputs as a 3-element array. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]

Nim, 134 126 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=result=lc[round(sum(lc[x[j][i]|(j<-0..7),int]).float/8).int|(i<-0..2),int]

Defines the procedure g, which requires the input passed in as a double-nested sequence (a sequence is an array with a @ in front, e.g. @[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]) and outputs as a 3-element array.

Nim, 134 126 115 bytes

import math,future
proc g(x:seq[seq[int]]):seq[int]=result=lc[(lc[x[j][i]|(j<-0..7),int].sum+4)shr 3|(i<-0..2),int]

Defines the procedure g, which requires the input passed in as a double-nested sequence and outputs as a 3-element array.

A Nim sequence is an array with @ in front, like @[1, 2, 3]. An input to this procedure could therefore be:

@[@[0,0,0],@[255,255,255],@[0,0,0],@[255,255,255],@[255,255,255],@[0,0,0],@[255,255,255],@[0,0,0]]
Golf some more
Source Link
Copper
  • 4k
  • 1
  • 14
  • 29
Loading
Source Link
Copper
  • 4k
  • 1
  • 14
  • 29
Loading