Skip to main content
added 685 characters in body
Source Link

Scala, 219 bytes

Inspired by Titus' bash solution, not very Scala-like. Also, the colors are off and the "pixels" are not square.

object O{def main(a:Array[String])={val e="\u001B[";val(b,r,w,n,s)=(e+"44m",e+"41m",e+"47m",e+"0m\n"," "*7);val(x,y,z)=(s"$b$s$w $r  $w $b$s$s$n",s"$w$s $r  $w $s$s$n",s"$r${s*3}    $n");print(s"${x*7}$y$z$z$y${x*7}")}}`

ungolfed:

object O{
  def main(a:Array[String])={
    val e="\u001B["; // escape sequence for color codes
    val(b,r,w,n,s)=(
      e+"44m", // blue background
      e+"41m", // red background
      e+"47m", // white background
      e+"0m\n",// color off + newline
      " "*7);  // seven spaces
    val(x,y,z)=(
      s"$b$s$w $r  $w $b$s$s$n", // 7*blue,white,red,red,white,14*blue
      s"$w$s $r  $w $s$s$n",     // 8*white,2*red,15*white
      s"$r${s*3}    $n");        // 25*red3*7+4=25*red
    print(s"${x*7}$y$z$z$y${x*7}") // print the individual lines
  }
}

Idea: The program uses (bash) color escape sequences to set the background color on the console. It then draws a number of space characters in the respective background color. The image consists of 18 lines of 25 spaces; the first seven and the last seven lines represented by variable x, the two (completely red) middle lines by z, and y represents the two white-and-red lines above/below. To save bytes, variable s represents seven consecutive spaces; for smaller cases, the spaces are used literally (i.e. the four consecutive spaces in variable z are necessary).

Icelandic flag as output by terminal

Scala, 219 bytes

Inspired by Titus' bash solution, not very Scala-like.

object O{def main(a:Array[String])={val e="\u001B[";val(b,r,w,n,s)=(e+"44m",e+"41m",e+"47m",e+"0m\n"," "*7);val(x,y,z)=(s"$b$s$w $r  $w $b$s$s$n",s"$w$s $r  $w $s$s$n",s"$r${s*3}    $n");print(s"${x*7}$y$z$z$y${x*7}")}}`

ungolfed:

object O{
  def main(a:Array[String])={
    val e="\u001B["; // escape sequence for color codes
    val(b,r,w,n,s)=(
      e+"44m", // blue background
      e+"41m", // red background
      e+"47m", // white background
      e+"0m\n",// color off + newline
      " "*7);  // seven spaces
    val(x,y,z)=(
      s"$b$s$w $r  $w $b$s$s$n", // 7*blue,white,red,red,white,14*blue
      s"$w$s $r  $w $s$s$n",     // 8*white,2*red,15*white
      s"$r${s*3}    $n");        // 25*red
    print(s"${x*7}$y$z$z$y${x*7}") // print the individual lines
  }
}

Scala, 219 bytes

Inspired by Titus' bash solution, not very Scala-like. Also, the colors are off and the "pixels" are not square.

object O{def main(a:Array[String])={val e="\u001B[";val(b,r,w,n,s)=(e+"44m",e+"41m",e+"47m",e+"0m\n"," "*7);val(x,y,z)=(s"$b$s$w $r  $w $b$s$s$n",s"$w$s $r  $w $s$s$n",s"$r${s*3}    $n");print(s"${x*7}$y$z$z$y${x*7}")}}`

ungolfed:

object O{
  def main(a:Array[String])={
    val e="\u001B["; // escape sequence for color codes
    val(b,r,w,n,s)=(
      e+"44m", // blue background
      e+"41m", // red background
      e+"47m", // white background
      e+"0m\n",// color off + newline
      " "*7);  // seven spaces
    val(x,y,z)=(
      s"$b$s$w $r  $w $b$s$s$n", // 7*blue,white,red,red,white,14*blue
      s"$w$s $r  $w $s$s$n",     // 8*white,2*red,15*white
      s"$r${s*3}    $n");        // 3*7+4=25*red
    print(s"${x*7}$y$z$z$y${x*7}") // print the individual lines
  }
}

Idea: The program uses (bash) color escape sequences to set the background color on the console. It then draws a number of space characters in the respective background color. The image consists of 18 lines of 25 spaces; the first seven and the last seven lines represented by variable x, the two (completely red) middle lines by z, and y represents the two white-and-red lines above/below. To save bytes, variable s represents seven consecutive spaces; for smaller cases, the spaces are used literally (i.e. the four consecutive spaces in variable z are necessary).

Icelandic flag as output by terminal

Source Link

Scala, 219 bytes

Inspired by Titus' bash solution, not very Scala-like.

object O{def main(a:Array[String])={val e="\u001B[";val(b,r,w,n,s)=(e+"44m",e+"41m",e+"47m",e+"0m\n"," "*7);val(x,y,z)=(s"$b$s$w $r  $w $b$s$s$n",s"$w$s $r  $w $s$s$n",s"$r${s*3}    $n");print(s"${x*7}$y$z$z$y${x*7}")}}`

ungolfed:

object O{
  def main(a:Array[String])={
    val e="\u001B["; // escape sequence for color codes
    val(b,r,w,n,s)=(
      e+"44m", // blue background
      e+"41m", // red background
      e+"47m", // white background
      e+"0m\n",// color off + newline
      " "*7);  // seven spaces
    val(x,y,z)=(
      s"$b$s$w $r  $w $b$s$s$n", // 7*blue,white,red,red,white,14*blue
      s"$w$s $r  $w $s$s$n",     // 8*white,2*red,15*white
      s"$r${s*3}    $n");        // 25*red
    print(s"${x*7}$y$z$z$y${x*7}") // print the individual lines
  }
}