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 »
Challenges

Post History

77%
+5 −0
Challenges Coat of Many Colours

Scala, 119 bytes Saved 26 bytes after porting Moshi's solution! _ 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...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#7: Post edited by user avatar user‭ · 2021-08-31T00:19:43Z (about 3 years ago)
  • # Scala, <s>145</s> 130 bytes
  • Saved 15 bytes after looking at [Moshi](https://codegolf.codidact.com/users/53196)'s [solution](https://codegolf.codidact.com/posts/283376/283383#answer-283383)!
  • ```scala
  • _ sortBy("d,ll,ee,ow,ar,ack,h,ac,b,iv,ol,w,la,ld,o,uv,ea,im,l,se,ur,m,s,e,r,i,n,a,u"split ","indexWhere _.substring(2).startsWith)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/n8cyjLAVRjy3wAso4yQTrQ)
  • It turns out that after dropping the first 2 letters, the first 2 letters after that (and in some cases 1 or 3) are enough to identify colors.
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index where
  • _.substring(2) //The current string with the 1st 2 chars removed
  • .startsWith //Starts with that color prefix
  • )
  • ```
  • # Scala, 119 bytes
  • Saved 26 bytes after porting [Moshi](https://codegolf.codidact.com/users/53196)'s [solution](https://codegolf.codidact.com/posts/283376/283383#answer-283383)!
  • ```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, <s>145</s> 130 bytes
  • Saved 15 bytes after looking at [Moshi](https://codegolf.codidact.com/users/53196)'s [solution](https://codegolf.codidact.com/posts/283376/283383#answer-283383)!
  • ```scala
  • _ sortBy("d,ll,ee,ow,ar,ack,h,ac,b,iv,ol,w,la,ld,o,uv,ea,im,l,se,ur,m,s,e,r,i,n,a,u"split ","indexWhere _.substring(2).startsWith)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/n8cyjLAVRjy3wAso4yQTrQ)
  • It turns out that after dropping the first 2 letters, the first 2 letters after that (and in some cases 1 or 3) are enough to identify colors.
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index where
  • _.substring(2) //The current string with the 1st 2 chars removed
  • .startsWith //Starts with that color prefix
  • )
  • ```
#6: Post edited by user avatar user‭ · 2021-08-31T00:08:45Z (about 3 years ago)
  • # Scala, 145 bytes
  • ```scala
  • _ sortBy("d,ll,ee,ow,ar,ack,hr,ach,b,iv,ol,wn,la,ld,oco,uve,eam,im,lv,se,ur,m,ss,ey,rp,it,nk,an,ue"split ","indexWhere _.substring(2).startsWith)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/lNNNJjFhRo2XLVVrBNWhxA)
  • It turns out that after dropping the first 2 letters, the first 2 letters after that (and in some cases 1 or 3) are enough to identify colors.
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index where
  • _.substring(2) //The current string with the 1st 2 chars removed
  • .startsWith //Starts with that color prefix
  • )
  • ```
  • # Scala, <s>145</s> 130 bytes
  • Saved 15 bytes after looking at [Moshi](https://codegolf.codidact.com/users/53196)'s [solution](https://codegolf.codidact.com/posts/283376/283383#answer-283383)!
  • ```scala
  • _ sortBy("d,ll,ee,ow,ar,ack,h,ac,b,iv,ol,w,la,ld,o,uv,ea,im,l,se,ur,m,s,e,r,i,n,a,u"split ","indexWhere _.substring(2).startsWith)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/n8cyjLAVRjy3wAso4yQTrQ)
  • It turns out that after dropping the first 2 letters, the first 2 letters after that (and in some cases 1 or 3) are enough to identify colors.
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index where
  • _.substring(2) //The current string with the 1st 2 chars removed
  • .startsWith //Starts with that color prefix
  • )
  • ```
#5: Post edited by user avatar user‭ · 2021-08-13T23:22:12Z (over 3 years ago)
  • # Scala, 145 bytes
  • ```scala
  • _ sortBy("d,ll,ee,ow,ar,ack,hr,ach,b,iv,ol,wn,la,ld,oco,uve,eam,im,lv,se,ur,m,ss,ey,rp,it,nk,an,ue"split ","indexWhere _.substring(2).startsWith)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/lNNNJjFhRo2XLVVrBNWhxA)
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index where
  • _.substring(2) //The current string with the 1st 2 chars removed
  • .startsWith //Starts with that color prefix
  • )
  • ```
  • # Scala, 145 bytes
  • ```scala
  • _ sortBy("d,ll,ee,ow,ar,ack,hr,ach,b,iv,ol,wn,la,ld,oco,uve,eam,im,lv,se,ur,m,ss,ey,rp,it,nk,an,ue"split ","indexWhere _.substring(2).startsWith)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/lNNNJjFhRo2XLVVrBNWhxA)
  • It turns out that after dropping the first 2 letters, the first 2 letters after that (and in some cases 1 or 3) are enough to identify colors.
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index where
  • _.substring(2) //The current string with the 1st 2 chars removed
  • .startsWith //Starts with that color prefix
  • )
  • ```
#4: Post edited by user avatar user‭ · 2021-08-13T23:21:07Z (over 3 years ago)
  • # Scala, 171 bytes
  • ```scala
  • _ sortBy("d,llow,een,own,arlet,ack,hre,ach,by,ive,olet,wn,lac,ld,ocolate,uve,eam,imson,lver,se,ure,mon,sset,ey,rple,ite,nk,ange,ue".split(",")indexWhere _.substring(2).==)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/agliQBgdRTGjkJcOvDLRaQ)
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index of
  • _.substring(2).== //The current string with the 1st 2 chars removed
  • )
  • ```
  • # Scala, 145 bytes
  • ```scala
  • _ sortBy("d,ll,ee,ow,ar,ack,hr,ach,b,iv,ol,wn,la,ld,oco,uve,eam,im,lv,se,ur,m,ss,ey,rp,it,nk,an,ue"split ","indexWhere _.substring(2).startsWith)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/lNNNJjFhRo2XLVVrBNWhxA)
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index where
  • _.substring(2) //The current string with the 1st 2 chars removed
  • .startsWith //Starts with that color prefix
  • )
  • ```
#3: Post edited by user avatar user‭ · 2021-08-13T23:09:46Z (over 3 years ago)
  • # Scala, 171 bytes
  • ```scala
  • _ sortBy("d,llow,een,own,arlet,ack,hre,ach,by,ive,olet,wn,lac,ld,ocolate,uve,eam,imson,lver,se,ure,mon,sset,ey,rple,ite,nk,ange,ue".split(",")indexWhere _.substring(2).==)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/agliQBgdRTGjkJcOvDLRaQ)
  • Explanation coming soon.
  • # Scala, 171 bytes
  • ```scala
  • _ sortBy("d,llow,een,own,arlet,ack,hre,ach,by,ive,olet,wn,lac,ld,ocolate,uve,eam,imson,lver,se,ure,mon,sset,ey,rple,ite,nk,ange,ue".split(",")indexWhere _.substring(2).==)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/agliQBgdRTGjkJcOvDLRaQ)
  • ```scala
  • _ sortBy( //Sort the input by this function:
  • "..." //Take the comma separated string of colors
  • .split(",") //Split on commas
  • indexWhere //And find the index of
  • _.substring(2).== //The current string with the 1st 2 chars removed
  • )
  • ```
#2: Post edited by user avatar user‭ · 2021-08-13T23:07:41Z (over 3 years ago)
  • # Scala, 198 bytes
  • ```scala
  • "red,yellow,green,brown,scarlet,black,ochre,peach,ruby,olive,violet,fawn,lilac,gold,chocolate,mauve,cream,crimson,silver,rose,azure,lemon,russet,grey,purple,white,pink,orange,blue" split ","filter _
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/r6aoA9GAQGW2dzZCBpkgxw)
  • Very simple.
  • # Scala, 171 bytes
  • ```scala
  • _ sortBy("d,llow,een,own,arlet,ack,hre,ach,by,ive,olet,wn,lac,ld,ocolate,uve,eam,imson,lver,se,ure,mon,sset,ey,rple,ite,nk,ange,ue".split(",")indexWhere _.substring(2).==)
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/agliQBgdRTGjkJcOvDLRaQ)
  • Explanation coming soon.
#1: Initial revision by user avatar user‭ · 2021-08-13T22:59:20Z (over 3 years ago)
# Scala, 198 bytes

```scala
"red,yellow,green,brown,scarlet,black,ochre,peach,ruby,olive,violet,fawn,lilac,gold,chocolate,mauve,cream,crimson,silver,rose,azure,lemon,russet,grey,purple,white,pink,orange,blue" split ","filter _
```
[Try it in Scastie!](https://scastie.scala-lang.org/r6aoA9GAQGW2dzZCBpkgxw)

Very simple.