A list of integers is a sawtooth list if no two adjacent elements of the list are the same, and if it contains no decreasing sequences longer than two.
The following lists are sawtooth lists:
1,2,3,4 1,2,3,4,1,2,3,4,1,2,3,4 1,2,1,2,3,4,2 4,6,7,8,9,8,9,10,1,2,1,3 7,6 1 5,4,7
The following lists are not sawtooth lists:
1,2,3,4,3,2,1 1,1 1,2,3,4,4,5 5,4,3,6,7 6,7,5,6,3,3
Write a program prints "Yes" if a list is a sawtooth list, and "No" otherwise.
Assumptions: The list will contain at least one number.
A palendromic square is a square number which is the same when its digits are reversed. For example 1, 4, 121 are palendromic squares, but 64 is not because it is different when reversed (i.e. 46).
Write a program which lists the first 15 palendromic squares.
Assumptions: The first palendromic square is 1. Numbers ending in 0 are not palendromic.
The black score of two lists of integers is the number of places where the two lists have the same element. You may enter the lists in whatever format you wish.
For example the black score of [1,9,3,8] [3,9,1,8] is 2, since 9 and 8 are in the same position in both lists.
Similarly the lists [1,1,4,4] [1,2,3,4] have a black score of 2, and the lists [1,2,3,4] [4,3,2,1] have a black score of 0.
The white score of two lists of integers is the number of times the lists have an element in common but not in the same position. Don't count elements twice, and don't count elements that would be counted in the black score.
For example the white score of [1,2,3,4] [1,2,5,3] is 1, since 3 occurs in both lists in different positions.
Similarly the following pairs of lists have the white score given. Read each example carefully to see what is meant by double counting.
[1,2,3,4] and [5,5,1,1] have a white score of 1 [1,2,3,4,5] and [1,1,1,1,1] have a white score of 0 [1,1,4,4] and [4,4,1,1] have a white score of 4 [1,1,4] and [4,4,1] have a white score of 2 [1,1,1,4] and [3,3,3,1] have a white score of 1
Write a program which prints the white score and the black score for two lists of integers. You may enter the lists in any format you wish. You may assume the two lists are of the same length. The lists will have less than 25 elements.
Sim is played on a board with six points, labelled A .. F, arranged in a roughly circular pattern. Two players (Red and Blue) alternate turns. Red always starts. On each player's turn they draw a line between two points not yet joined by a line. The line is coloured with their own colour. The first player to complete a triangle in their own colour wins.
Write a program which reads a sequence of moves and then prints a status message. The status message should be:
The format of the moves provided to the program will be a sequence of letter pairs, one per line, representing the moves. Below are two examples:
AB AD BC CA EB DC FA TriangleAB AD BC CA EB FB No Triangle
The first example represents the game with a red line joining A to B, a blue line joining A to D, a red line joining C to B, and so on. After the moves the game has a blue triangle.
An extra 4 bonus marks for printing the status message "Can Win" if the game is not yet over, and the player whose turn it is to draw next can complete a triangle in their colour with that line. For example:
AB AD BC CA EB Can Win
After 5 moves it is Blue's turn and they can win with DC, so the status is "Can Win".
Restrictions: Input letters will be uppercase. No more than one line may connect any two points. No further moves are made once a game is won.
Assumptions: The input will comply with the restrictions, that is, you don't have to deal with invalid input. The pair of letters representing a line may appear in either order in the input. E.g. DB and BD are both valid and represent the same line.
We can represent jigsaw pieces by rectangular grids of characters, with dots representing empty space, and uppercase letters representing solid regions. For example:
..A.. .AAA. AAAAA ..BBB. .BBB.. BBB... .CC .CC
represent a triangular piece, a trapezium, and a square.
Write a program which reads a sequence of pieces and fits them into an 6x6 grid with no overlapping solid regions. Your program should then print out the 6x6 grid. E.g.
CC.... CCBBB. .BBB.. BBBA.. ..AAA. .AAAAA
Restrictions: Input pieces will consist only of uppercase letters and full stops. The grids representing the input pieces will have a height and width of no more than 6 characters. Pieces cannot be rotated or reflected.
Assumptions: The input will comply with the restrictions, that is, you don't have to deal with invalid input. The grids representing the input pieces might not all be the same size. There will be no more than six pieces. There will be at least one way of arranging the pieces to fit in the 6x6 grid.
Write a program to display the pattern of creases formed by folding a rectangular piece of paper.
Folds can be Horizontal or Vertical, and either positive or negative.
Suppose you are holding a piece of paper in front of you as though you were reading it. To give it a positive horizontal fold (denoted by H+) bring the bottom half of the paper towards you.
To give it a negative horizontal fold (denoted by H-) move the bottom half of the paper away from you.
To give it a positive (or negative) vertical fold (denoted by V+ or V- respectively) bring the right half of the paper towards (or away from) you.
For example, the sequence of folds: H+ V+ produces the following pattern of creases when unfolded:
# # ####### o o
where # denotes in downwards crease, and o an upwards crease. Similarly the sequence: H+ V+ H+ V- produces:
o # # o # # ########ooooooo # # o # # o ############### o o # o o # oooooooo####### # o o # o o
Write a program which takes in a series of folds and produces output in the format above.
The sequence of tribonacci numbers starts as follows:
1,1,1,3,5,9,17,31,57,105, ..
After the first three numbers each number is the sum of the previous three. eg 1+1+1=3, 1+1+3=5.
Find the last 4 digits of the 1000th tribonacci number (it's a big number).