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

66%
+2 −0
Challenges In The Jailhouse Now

Scala, 90 89 88 bytes Saved 2 bytes thanks to Shaggy n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x<n)"╠╬╣"else"╚╩╝";s(0)+(""+s(1))*(n-3)+s(2)} Try it in Scastie! I feel like there'...

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

Answer
#4: Post edited by user avatar user‭ · 2021-08-24T16:19:52Z (over 2 years ago)
  • # Scala, <s>90 89</s> 88 bytes
  • Saved 2 byte thanks to Shaggy
  • ```scala
  • n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x<n)"╠╬╣"else"╚╩╝";s(0)+(""+s(1))*(n-3)+s(2)}
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/FoJw50KbQpm7MXkGnGeauw)
  • I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.
  • ```scala
  • n => //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 the inner parts
  • else"╚╩╝"; //For the bottom
  • s(0)+(""+s(1))*(n-3)+s(2)} //Repeat the inner part n-3 times
  • ```
  • # Scala, <s>90 89</s> 88 bytes
  • Saved 2 bytes thanks to Shaggy
  • ```scala
  • n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x<n)"╠╬╣"else"╚╩╝";s(0)+(""+s(1))*(n-3)+s(2)}
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/FoJw50KbQpm7MXkGnGeauw)
  • I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.
  • ```scala
  • n => //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 the inner parts
  • else"╚╩╝"; //For the bottom
  • s(0)+(""+s(1))*(n-3)+s(2)} //Repeat the inner part n-3 times
  • ```
#3: Post edited by user avatar user‭ · 2021-08-24T16:19:41Z (over 2 years ago)
  • # Scala, <s>90</s> 89 bytes
  • Saved 1 byte thanks to Shaggy
  • ```scala
  • n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x==n)"╚╩╝"else"╠╬╣";s(0)+(""+s(1))*(n-3)+s(2)}
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/Y4kI63eCS8ev2atIcmZkww)
  • I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.
  • ```scala
  • n => //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 the bottom
  • else"╠╬╣"; //For the inner parts
  • s(0)+(""+s(1))*(n-3)+s(2)} //Repeat the inner part n-3 times
  • ```
  • # Scala, <s>90 89</s> 88 bytes
  • Saved 2 byte thanks to Shaggy
  • ```scala
  • n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x<n)"╠╬╣"else"╚╩╝";s(0)+(""+s(1))*(n-3)+s(2)}
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/FoJw50KbQpm7MXkGnGeauw)
  • I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.
  • ```scala
  • n => //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 the inner parts
  • else"╚╩╝"; //For the bottom
  • s(0)+(""+s(1))*(n-3)+s(2)} //Repeat the inner part n-3 times
  • ```
#2: Post edited by user avatar user‭ · 2021-08-24T15:43:04Z (over 2 years ago)
  • # Scala, 90 bytes
  • ```scala
  • n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x==n)"╚╩╝"else "╠╬╣";s(0)+(""+s(1))*(n-3)+s(2)}
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/5CIZZy8hQverVAEawS0l5g)
  • I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.
  • # Scala, <s>90</s> 89 bytes
  • Saved 1 byte thanks to Shaggy
  • ```scala
  • n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x==n)"╚╩╝"else"╠╬╣";s(0)+(""+s(1))*(n-3)+s(2)}
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/Y4kI63eCS8ev2atIcmZkww)
  • I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.
  • ```scala
  • n => //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 the bottom
  • else"╠╬╣"; //For the inner parts
  • s(0)+(""+s(1))*(n-3)+s(2)} //Repeat the inner part n-3 times
  • ```
#1: Initial revision by user avatar user‭ · 2021-08-24T15:18:39Z (over 2 years ago)
# Scala, 90 bytes

```scala
n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x==n)"╚╩╝"else "╠╬╣";s(0)+(""+s(1))*(n-3)+s(2)}
```
[Try it in Scastie!](https://scastie.scala-lang.org/5CIZZy8hQverVAEawS0l5g)

I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.