7 kyu

Coloured Triangles

4,926 of 11,218Avanta

Description:

If you finish this kata, you can try Insane Coloured Triangles by Bubbler, which is a much harder version of this one.

A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containing one fewer colour than the last, are generated by considering the two touching colours in the previous row. If these colours are identical, the same colour is used in the new row. If they are different, the missing colour is used in the new row. This is continued until the final row, with only a single colour, is generated.

The different possibilities are:

Colour here:        G G        B G        R G        B R
Becomes colour:      G          R          B          G

With a bigger example:

R R G B R G B B
 R B R G B R B
  G G B R G G
   G R G B G
    B B R R
     B G R
      R B
       G

You will be given the first row of the triangle as a string and its your job to return the final colour which would appear in the bottom row as a string. In the case of the example above, you would the given RRGBRGBB you should return G.

  • The input string will only contain the uppercase letters R, G, B and there will be at least one letter so you do not have to test for invalid input.
  • If you are only given one colour as the input, return that colour.

Adapted from the 2017 British Informatics Olympiad

Logic
Strings
Algorithms

Stats:

CreatedDec 4, 2017
PublishedDec 4, 2017
Warriors Trained19634
Total Skips415
Total Code Submissions38492
Total Times Completed11218
Python Completions4926
JavaScript Completions3534
Java Completions1551
CoffeeScript Completions15
Julia Completions18
Scala Completions89
Ruby Completions257
Haskell Completions199
Rust Completions188
Nim Completions15
C++ Completions448
C Completions183
NASM Completions8
Go Completions130
D Completions5
Total Stars421
% of votes with a positive feedback rating94% of 1522
Total "Very Satisfied" Votes1352
Total "Somewhat Satisfied" Votes143
Total "Not Satisfied" Votes27
Total Rank Assessments3
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Avanta Avatar
  • electricdusk Avatar
  • kersson Avatar
  • anter69 Avatar
  • dinglemouse Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • JorgeVS Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • metagn Avatar
  • metalim Avatar
  • fredc Avatar
  • hobovsky Avatar
  • uniapi Avatar
  • stellartux Avatar
  • zLuki Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad