Coding Challenges Booklet FULL
Coding Challenges Booklet FULL
Accredited
Teacher guide
COMPUTER SCIENCE
For first teaching in 2020
Contents
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
www.ocr.org.uk/computerscience
Contents
Factorial Finder 5 Data Entry 9
Speed Tracker 5 Simple Life Calculator 9
Thief! 5 Fibbing 9
Classification 6 Hack-proof 10
Fruit Machine 6 Ordering 10
Unit Converter (temperature, currency, volume) 6 Truth or not! 10
Credit Card Validator 6 Word Subtraction 10
Arithmetic test 6 Name that Number 11
Happy Numbers 6 Item Merge 11
Number Names 7 Year Addition 11
Regex Query Tool 7 Forwards and Backwards 11
Quiz Maker 7 Code it up Mor- 11
2 © OCR 2020
Contents
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
3 © OCR 2020
Introduction
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
Introduction
These coding challenges provide real world problems for teachers and students to help develop
their coding skills.
For GCSE: responses only need command line interfaces, and focus on using the programming
techniques contained within the current specification.
For A Level: any solutions should have a graphical use interface created for it. Use of OOP
methodologies is to be encouraged, as many problems lend themselves to a class system.
This is an active document and likely to receive regular updates with challenges throughout the
lifetime of the specification.
We do not publish solutions, as there are many ways in which these problems could be solved.
Discussions regarding approaches are beneficial at a cohort/class level to encourage candidate’s
realisation that each problem has many unique solutions that will fulfill the success criteria that
have been identified. Where we do provide a solution - it should be used for discussion and
comment, rather than being taken as ‘the only and/or best way to solve the challenge’.
4 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
1 Factorial Finder
The Factorial of a positive integer, n, is defined as the product of the sequence n, n-1, n-2, ...1 and the factorial of zero, 0, is defined as being 1. Solve this using both loops
and recursion.
2 Speed Tracker
Create a program that takes a time for a car going past a speed camera, the time going past the next one and the distance between them to calculate the average speed for
the car in mph. The cameras are one mile apart.
Extensions:
1. Speed cameras know the timings of each car going past, through number plate recognition. Valid number plates are two letters, two numbers and three letters afterwards,
for example XX77 787. Produce a part of the program that checks whether a number plate matches the given pattern. Tell the user either way.
2. Create a program for creating a file of details for vehicles exceeding the speed limit set for a section of road. You will need to create a suitable file with test data, including
randomised number plates and times. You will then use the code you’ve already written to process this list to determine who is breaking the speed limit (70mph) and who
has invalid number plates.
5 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
3 Thief!
A thief has managed to find out the four digits for an online PIN code, but doesn’t know the correct sequence needed to hack into the account.
Design and write a program that displays all the possible combinations for any four numerical digits entered by the user. The program should avoid displaying the same
combination more than once.
4 Classification
A simple classification system asks a series of Yes/No questions in order to work out what type of animal is being looked at.
These systems can often be drawn using a “tree” structure. Carry out some simple research on classification trees, then write a program to help the user decide
between the following:
horse, cow, sheep, pig, dog, cat, lion, tiger, whale, dolphin, seal, penguin, ostrich, sparrow, spider, ant, bee, wasp, termite, octopus,
squid Is there a better way to do this than using 101 IF...ELSE...END IFs?
Develop your classification system for your own area of interest: pop bands; pokemon; cars; footballers; teachers; diseases etc.
5 Fruit Machine
Write a program to simulate a Fruit Machine that displays three symbols at random from Cherry, Bell, Lemon, Orange, Star, Skull.
The player starts with £1 credit, with each go costing 20p. If the Fruit Machine “rolls” two of the same symbol, the user wins 50p. The player wins £1 for three of the
same and £5 for 3 Bells. The player loses £1 if two skulls are rolled and all of his/her money if three skulls are rolled. The player can choose to quit with the winnings
after each roll or keep playing until there is no money left.
6 Unit Converter (temp, currency, volume)
Converts various units between one another. The user enters the type of unit being entered, the type of unit they want to convert to and then the value. The program
will then make the conversion.
7 Credit Card Validator
Takes in a credit card number from a common credit card vendor (Visa, MasterCard, American Express, Discoverer) and validates it to make sure that it is a valid number
(look into how credit cards use a checksum).
6 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
8 Arithmetic test
A primary school teacher wants a computer program to test the basic arithmetic skills of her students. Generate random questions (2 numbers only) consisting of addition,
subtraction, multiplication and division.
The system should ask the student’s name and then ask ten questions. The program should feed back if the answers are correct or not, and then generate a final
score at the end.
Extensions:
1. Extend your program so that it stores the results somewhere. The teacher has three classes, so you need to enable the program to distinguish between them.
2. The teacher wants to be able to log student performance in these tests. The teacher would like the program to store the last three scores for each student and to be
able to output the results in alphabetical order with the student’s highest score first out of the three.
9 Happy Numbers
A happy number is defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops
endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers.
Display an example of your output here. Find the first eight happy numbers.
10 Number Names
Show how to spell out a number in English. You can use a pre-existing implementation or make your own, but you should support inputs up to at least one million (or the
maximum value of your language’s default bounded integer type, if that’s less).
Extensions:
1. Create support for inputs other than positive integers (like zero, negative integers, and floating-point numbers).
7 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
13 Caesar Cipher
Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates the letters of the alphabet (A to Z). The encoding replaces each
letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts “HI” to “JK”, but key 20 encrypts “HI” to “BC”.
14 Events calendar
Create a menu driven program that allows the user to add or delete events from a list of dates and timings, just like a calendar. The program should warn you if any of the events
overlap when entering them.
Extensions:
1. Make it so that none of the events are hard-coded into the program
15 Pangrams
”The quick brown fox jumps over the lazy dog”; note how all 26 English-language letters are used in the sentence.
Your goal is to implement a program that takes a series of strings (one per line) and prints either True (the given string is a pangram), or False if it is not.
16 Kaprekar
Determine whether a number is a Kaprekar number or not. See http://mathworld.wolfram.com/KaprekarNumber.html for more information.
17 Number Table
Write a program that takes a symbol (+,-,* or /) and a natural number (>0) and makes a table like below for the operation from 0 to
+ | 0 1 2 3 4
------------------0
| 0 1 2 3 4
1 | 1 2 3 4 5
2 | 2 3 4 5 6
3 | 3 4 5 6 7
4 | 4 5 6 7 8
8 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
18 Years in a Range
Write a program to count the number years in a range that has a repeated digit.
For example, 2012 has a repeated digit, but 2013 does not.
19 Logic Gate
Write a program that will give the students the answer to logic gate questions
For example:
Result = 1
It should work for the logic gates OR, AND, XOR, NAND and NOR
20 Palindromes
Write a program that checks if a string entered by the user is a palindrome. A palindrome is a word that reads the same forwards as backwards like “racecar”
21 Data Entry
Create a program that retrieves the membership details for a Rock Climbing Club. The program should take a range of details and then repeat them back, with headings, for
confirmation. Once confirmed, the program stores these details; else it clears them and allows a new input.
Extensions:
9 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
Extensions:
1. Use a an option menu so that the user can use more than one calculation before the program closes
23 Fibbing
Create a program that will calculate the Fibonacci Sequence to 10 places.
Extensions:
24 Hack-proof
Create a program that will only open a text document if the correct password is entered. The user should choose the username and password first and it should also verify
the password before allowing it.
Extensions:
2. Create a random password that contains at least a lowercase, uppercase and special character of at least 8 characters in length
10 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
25 Ordering
Create a program that allows entry of 10 numbers and then sorts them into ascending or descending order, based on user input.
Extension:
1. The user can input a word or string, and it arranges the string into alphabetical order. E.g. My Rabbit would be shown as “abbimty “. (Punctuation placement is not
essential) 2. Repeat Extension 1, but include the sentence structure
26 Truth or not
Create a program that would take the number of inputs in a logic circuit and works out the number of output lines are needed for the truth table. Have it draw the truth table
on screen, using Columns for Inputs (A, B, C etc) and rows for the 1’s and 0’s.
Extension:
27 Word Subtraction
Create a program that takes two strings/words. Then then converts this to an ASCII value and subtracts the values from each other.
Extension:
1. Also add a function that removes any characters in the second word that occur in the first word. E.g. Fish and Tin, would return “Fsh” and “Tn”
Extensions:
1. Can you develop your program so that only words in the dictionary are allowed?
11 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
29 Item Merge
Create a program that will compare two shopping lists from “Week A” and “Week B”. It will return any unique items contained on the list.
Extension:
2. Develop this to 4 Weeks of shopping an highlight the top 3 most popular items
30 Year Addition
Create a program that accepts a year in the format ####, e.g. 2015. The program then adds each digit of the year together and outputs the answer. E.g. 2015 becomes the
output 8.
Extension:
1. Develop this so that the user can guess an integer value. If the MOD division is “0” they score a point, if it isn’t they can guess again, up to 3 attempts in total
31 Forwards and Backwards
Create a program that is able to detect if an input is the same as the reverse of the same input – i.e. a Palindrome
32 Code it up
Create a program that adds 25 to the value of each character of a string that a user enters. This new string should be saved and output.
Extension:
1. Develop your program to include a conversion from a ‘coded’ string back to a normal string
2. Develop your program to allow the user to enter the number they want the string coded by (e.g. 12)
3. Develop your program to then decode a string, based on the coded value that the end user enters
33 Mor-se Coding
Create a program that allows you to enter a string and encode it into Morse code, using ‘ . ‘ and ‘ - ‘ notation. Spaces between words should be replaced with the “|” (pipe)
character.
Use a normal space for gaps between each character.
Extension:
12 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
1. Develop your program to translate from Morse to alphanumeric, using the standards above
34 What’s the day?
Design a program to take 3 inputs, one for day, one for month and one for year. Get your program to validate if this is an actual day, and, if it is, output the day of the week it is!
35 Game of Chance
A user can bet on any number from 0 to 30. If it’s an even number they 2x their money back. If it’s a multiple of 10 they get 3x their money back. If it’s a prime number
they get 5x their money back. If the number is below 5 they get a 2x bonus.
Create a program that allows the user to guess a number. A random number is generated. If the guess == the random number then the user wins and gets a pay-out.
Combinations of the win scenarios should be catered for.. e.g. 20 wins 2 x 3 bonus = 6x their money.
Extension:
1. Develop your program to allow a user to enter the amount they want to place for that bet, and work out the resulting pay-out
2. Develop your program to store the user’s current balance and stop them from betting if they have no money left
3. Develop your program to finally incorporate validation so that they cannot enter into a negative about of cash ever, and that a bet should be between 1 and 10 units of
currency
36 Triangulate
Create a program that accepts 3 sides of a triangle. It then works out if these sides form a triangle, and if so, what type of triangle (e.g. Scalene, Isosceles, Right-Angle….)
Extension:
1. Develop your program to allow 2 sides of a triangle and an angle, to work out the length of the missing side
13 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
37 Fizz Buzz
Create a program that replicates the famous game Fizz Buzz. The program will take an input, e.g. 20, and then print out the list of Fizz Buzz up to and including that number,
where:
• Any multiple of 3 is replaced by the word ‘Fizz’
• Any multiple of 5 is replaced by the word ‘Buzz’
• Any multiple of both 3 and 5 is replaced by the word ‘FizzBuzz’ Extension:
38 Sing Along
Create a program that prints the lyrics to the song ‘10 green bottles’ in as few lines of code as possible.
Extension:
1. Develop this program so that you can enter any starting number and it will count down from there
Extension:
1. Develop your program to allow Character input as well, and these come before the integers, and are listed in reverse alphabetical order
40 Base of Numbers
Create a program that converts a denary number into its hexadecimal equivalent.
Extension:
1. Allow the user to specify the base that they want to convert the number into, using an integer, e.g. 16 for Hexadecimal
14 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
41 Prime Factorisation
Have the user enter a number and find all Prime Factors (if there are any) and display them.
Extension:
• Have the program find prime numbers until the user chooses to stop asking for the next one.
42 Tilers mate
Have the user enter the Width and Length of the floor and have the program calculate the total cost of tiles it would take to cover a floor plan using a cost entered by the user
(per tile or metre2).
Extension:
• Have the programme offer different types of tiles with different costs and tell the user the cost.
• Have the programme take into account the cost of grout and labour to give a customer a quote with and without VAT.
Extension:
44 Sudoku
Have the program solve a Sudoku (https://en.wikipedia.org/wiki/Sudoku).
15 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
47 Happy Numbers =)
A happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process
until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers,
while those that do not end in 1 are unhappy numbers. Have the programme find the first 8 happy numbers.
48 Reverse it
Have the programme allow a user to enter some text and then the programme will reverse it and print it back to the screen.
Extension:
• Have the programme count the vowels and consonants and print these to screen.
• Have the programme check if the text is a palindrome (it is the same forwards as it is backwards e.g “racecar” or “hannah”).
49 Fireworks
Make an animation of a firework display, with rockets, Catherine wheels etc.
Extension:
• Let the user specify the number, colour, timing and location of fireworks.
16 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
50 Mandelbrot Set
Draw a Mandelbrot set (http://mathworld.wolfram.com/MandelbrotSet.html).
Extension:
• In colour
• With an animation
• Allow the user to zoom in
51 Text-speak converter
Set up a text-speak to English dictionary and have the program convert input from text-speak to English. (“lol” to “laugh out loud” etc)
Extension:
53 Mortgage Calculator
Have the programme calculate the monthly payments of a fixed term mortgage over given Nth terms at a given interest rate. Also figure out how long it will take the user to
pay back the loan. Extension:
• Add an option for users to select the compounding interval (Monthly, Weekly, Daily, Continually).
• Add in functionality to deal with over payments at a given % each month.
17 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
54 Dear Diary
Have the programme allow people to add comments or write diary entries. It should add timestamps to all entries. Could also be made into a shout box
(https://en.wikipedia.org/wiki/Shoutbox).
Extension:
55 Secret Ciphers
Have the programme encrypt messages using one of the following ciphers:
• Vigenere
• Vernan
• Ceasar
Extension:
• Create separate functions for each Cipher and allow the user to choose which one to use.
56 Page Scraper
Have the programme connect to a site and pulls out all the links, or images, and save them to a list.
Extension:
18 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
Extension:
Extension:
• Add an inventory system so you must collect a key to get through a certain door etc.
Extension:
• Freeze a region
19 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
Your name is (blank), you are (blank) years old, and you are in form (blank).
Extension:
Extension:
63 I like Pi
Have the programme calculate pi to at least 30 decimal places.
64 Galaxy song
Use graphics and random functions to draw an imaginary night sky filled with stars.
Extension:
65 Spam filter
Take a list of dishes from a menu and add “spam” to them. See https://en.wikipedia.org/wiki/Spam_(Monty_Python).
Extension:
• Experiment with adding spam at the beginning, end and all places in-between
20 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
66 Silly walks
Draw a random walk where each step of equal length is either up, down, right or left with equal probability. See https://en.wikipedia.org/wiki/Random_walk.
Extension:
68 Semaphore
Have the user enter some text and make an animation of it converted into semaphore (https://en.wikipedia.org/wiki/Flag_semaphore).
69 Beautiful soup
Use the BeautifulSoup and requests Python packages to print out a list of all the article titles on the BBC News (http://www.bbc.co.uk/news)
Randomly generate a 4-digit number. Ask the user to guess a 4-digit number. For every digit that the user guessed correctly in the correct place, they have a “mouse”. For every
digit the user guessed correctly in the wrong place is a “man” Every time the user makes a guess, tell them how many “mice” and “men” they have.
Once the user guesses the correct number, the game is over. Keep track of the number of guesses the user makes throughout the game and tell the user at the end.
Extension:
• Deal with “mice” and “mouse” and “man” and “men ” properly.
71 Goldbach
Goldbach’s conjecture says that every positive even number greater than 2 is the sum of two prime numbers. Example: 28 = 5 + 23. It is one of the most famous facts in number
theory that has not been proved to be correct in the general case. It has been numerically confirmed up to very large.
Write a predicate to find the two prime numbers that sum up to a given even integer.
21 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
72 Lists
Create a list containing all integers within a given range. Insert an element at a given position into a list. Extract a given number of randomly selected elements from a list
and create a list of lists. Sort the list of lists according to the length of sublists.
73 Travel club
A group of people are member of a travel club. The group shares expenses equally but it is not practical to share every expense as they happen, so all expenses are collated
(such as taxis, train tickets etc) after the trip and the member cost is shared to within 1% between the group. Create a programme that computes the net cost from a list of
expenses and works out the minimum amount of money that must change hands in order for everybody to have paid the same amount (within 1%).
22 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
23 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
74 Checkmate checker
Create a programme that checks whether a King is in check in a given chess game configuration.
Movement examples are shown below, grey pieces indicate the positions where the piece can capture another piece:
There will be an arbitrary number of board configurations in the input, each consisting of eight lines of eight characters each. A ``.’’ denotes an empty square, while upper- and
lowercase letters represent the pieces as defined above. There will be no invalid characters and no configurations where both kings are in check. You must read until you find an
empty board consisting only of ``.’’ characters, which should not be processed. There will be an empty line between each pair of board configurations. All boards, except for the
empty one, will contain exactly one white king and one black king.
For each board configuration read you must output one of the following answers:
75 String permutation
Given two strings x and y, print the longest string a of letters such that there is a permutation of a that is a subsequence of x and there is a permutation of a that is a
subsequence of y.
24 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
89261670696623633820136378418383684178734361726757
28112879812849979408065481931592621691275889832738
44274228917432520321923589422876796487670272189318
47451445736001306439091167216856844588711603153276
70386486105843025439939619828917593665686757934951
62176457141856560629502157223196586755079324193331
64906352462741904929101432445813822663347944758178
92575867718337217661963751590579239728245598838407
58203565325359399008402633568948830189458628227828
80181199384826282014278194139940567587151170094390
35398664372827112653829987240784473053190104293586
86515506006295864861532075273371959191420517255829
71693888707715466499115593487603532921714970056938
54370070576826684624621495650076471787294438377604
53282654108756828443191190634694037855217779295145
36123272525000296071075082563815656710885258350721
45876576172410976447339110607218265236877223636045
17423706905851860660448207621209813287860733969412
25 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
26 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
81142660418086830619328460811191061556940512689692
51934325451728388641918047049293215058642563049483
62467221648435076201727918039944693004732956340691
15732444386908125794514089057706229429197107928209
55037687525678773091862540744969844508330393682126
18336384825330154686196124348767681297534375946515
80386287592878490201521685554828717201219257766954
78182833757993103614740356856449095527097864797581
16726320100436897842553539920931837441497806860984
48403098129077791799088218795327364475675590848030
87086987551392711854517078544161852424320693150332
59959406895756536782107074926966537676326235447210
69793950679652694742597709739166693763042633987085
41052684708299085211399427365734116182760315001271
65378607361501080857009149939512557028198746004375
35829035317434717326932123578154982629742552737307
94953759765105305946966067683156574377167401875275
88902802571733229619176668713819931811048770190271
25267680276078003013678680992525463401061632866526
36270218540497705585629946580636237993140746255962
24074486908231174977792365466257246923322810917141
91430288197103288597806669760892938638285025333403
34413065578016127815921815005561868836468420090470
23053081172816430487623791969842487255036638784583
11487696932154902810424020138335124462181441773470
63783299490636259666498587618221225225512486764533
67720186971698544312419572409913959008952310058822
27 © OCR 2020
95548255300263520781532296796249481641953868218774
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
28 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
76085327132285723110424803456124867697064507995236
37774242535411291684276865538926205024910326572967
23701913275725675285653248258265463092207058596522
29798860272258331913126375147341994889534765745501
18495701454879288984856827726077713721403798879715
38298203783031473527721580348144513491373226651381
34829543829199918180278916522431027392251122869539
40957953066405232632538044100059654939159879593635
29746152185502371307642255121183693803580388584903
41698116222072977186158236678424689157993532961922
62467957194401269043877107275048102390895523597457
23189706772547915061505504953922979530901129967519
86188088225875314529584099251203829009407770775672
11306739708304724483816533873502340845647058077308
82959174767140363198008187129011875491310547126581
97623331044818386269515456334926366572897563400500
42846280183517070527831839425882145521227251250327
55121603546981200581762165212827652751691296897789
32238195734329339946437501907836945765883352399886
75506164965184775180738168837861091527357929701337
62177842752192623401942399639168044983993173312731
32924185707147349566916674687634660915035914677504
99518671430235219628894890102423325116913619626622
73267460800591547471830798392868535206946944540724
76841822524674417161514036427982273348055556214818
97142617910342598647204516893989422179826088076852
87783646182799346313767754307809363333018982642090
29 © OCR 2020
10848802521674670883215120185883543223812876952786
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
30 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
71329612474782464538636993009049310363619763878039
62184073572399794223406235393808339651327408011116
66627891981488087797941876876144230030984490851411
60661826293682836764744779239180335110989069790714
85786944089552990653640447425576083659976645795096
66024396409905389607120198219976047599490197230297
64913982680032973156037120041377903785566085089252
16730939319872750275468906903707539413042652315011
94809377245048795150954100921645863754710598436791
78639167021187492431995700641917969777599028300699
15368713711936614952811305876380278410754449733078
40789923115535562561142322423255033685442488917353
44889911501440648020369068063960672322193204149535
41503128880339536053299340368006977710650566631954
81234880673210146739058568557934581403627822703280
82616570773948327592232845941706525094512325230608
22918802058777319719839450180888072429661980811197
77158542502016545090413245809786882778948721859617
72107838435069186155435662884062257473692284509516
20849603980134001723930671666823555245252804609722
53503534226472524250874054075591789781264330331690
31 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
77 Fib on a chi
The Fibonacci sequence is defined by the recurrence relation:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144
The 12th term, F12, is the first term to contain three digits.
What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
78 2 fiddy
It is possible to make £2.50 in the following way:
Write a programme that works out all the different ways £2.50 can be made using any number of coins.
32 © OCR 2020
A Level and GCSE (9-1) Computer Science Code Challenges Booklet
79 Printer problems
A printing shop runs 16 batches (jobs) every week and each batch requires a sheet of
special colour-proofing paper of size A5.
Every Monday morning, the foreman opens a new envelope, containing a large sheet of
the special paper with size A1.
He proceeds to cut it in half, thus getting two sheets of size A2. Then he cuts one of them
in half to get two sheets of size A3 and so on until he obtains the A5-size sheet needed for
the first batch of the week.
At the beginning of each subsequent batch, he takes from the envelope one sheet of
paper at random. If it is of size A5, he uses it. If it is larger, he repeats the ‘cut-in-half’
procedure until he has what he needs and any remaining sheets are always placed back
in the envelope.
80 Happy Hopper
A sequence of n > 0 integers is called a happy hopper if the absolute values of the differences between successive elements take on all possible values 1 through n - 1. E.g 1 4 2
3 is a happy hopper because the absolute differences are 3, 2, and 1, respectively. The definition implies that any sequence of a single integer is a happy hopper. Write a
program to determine whether each of a number of sequences is a happy hopper.
V Variables
Null object http://rosettacode.org/wiki/Variables
http://rosettacode.org/wiki/Null_object
O Variadic
Optionalfunction
parameters http://rosettacode.org/wiki/Variadic_function
http://rosettacode.org/wiki/Optional_parameters
Did you know?
OCR Resources: the small print
Would you prefer a Word OCR is part of Cambridge Assessment, a department of the University of
Cambridge. For staff training purposes and as part of our quality
OCR’s resources are provided to support the delivery of OCR
qualifications, but in no way constitute an endorsed teaching version? assurance programme your call may be recorded or monitored.