create a new practice
choose your exercise
I'd like to contribute
a new exercise
100 doors
12 Days of Xmas
ABC Problem
Align Columns
Anagrams
Array Shuffle
Balanced Parentheses
Best Shuffle
Bowling Game
Calc Stats
Closest To Zero
Combined Number
Count Coins
Counter Strings
Diff Selector
Diversion
Eight Queens
Filename Range
Fisher-Yates Shuffle
Five Weekends
Fizz Buzz
Fizz Buzz Plus
Friday 13th
Game of Life
Gray Code
Group Neighbours
Haiku Review
Harry Potter
ISBN
Knight's Tour
LCD Digits
Leap Years
Levenshtein Distance
Longest Common Prefix
Magic Square
Mars Rover
Mine Field
Mine Sweeper
Monty Hall
Number Chains
Number Names
Phone Numbers
Poker Hands
Prime Factors
Print Diamond
Recently Used List
Remove Duplicates
Reordering
Reverse Roman
Reversi
Roman Numerals
Saddle Points
Tennis
Tiny Maze
Unsplice
Vending Machine
Wonderland Number
Word Wrap
Yatzy
Yatzy Cutdown
Zeckendorf Number
100 doors in a row are all initially closed. You make 100 passes by the doors. The first time through, you visit every door and toggle the door (if the door is closed, you open it; if it is open, you close it). The second time you only visit every 2nd door (door #2, #4, #6, ...). The third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door. Question: What state are the doors in after the last pass? Which are open, which are closed? [Source http://rosettacode.org]
Write the smallest program that outputs the lyrics of the Xmas carol The Twelve Days of Xmas. You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion. The lyrics are as follows: On the first day of Christmas My true love gave to me: A partridge in a pear tree. On the second day of Christmas My true love gave to me: Two turtle doves and A partridge in a pear tree. On the third day of Christmas My true love gave to me: Three french hens Two turtle doves and A partridge in a pear tree. On the fourth day of Christmas My true love gave to me: Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the fifth day of Christmas My true love gave to me: Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the sixth day of Christmas, My true love gave to me: Six geese a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the seventh day of Christmas, My true love gave to me: Seven swans a-swimming Six geese a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the eighth day of Christmas, My true love gave to me: Eight maids a-milking Seven swans a-swimming Six geese a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the ninth day of Christmas, My true love gave to me: Nine ladies dancing Eight maids a-milking Seven swans a-swimming Six geese a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the tenth day of Christmas, My true love gave to me: Ten lords a-leaping Nine ladies dancing Eight maids a-milking Seven swans a-swimming Six geese a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the eleventh day of Christmas, My true love gave to me: Eleven pipers piping Ten lords a-leaping Nine ladies dancing Eight maids a-milking Seven swans a-swimming Six geese a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. On the twelfth day of Christmas, My true love gave to me: Twelve drummers drumming Eleven pipers piping Ten lords a-leaping Nine ladies dancing Eight maids a-milking Seven swans a-swimming Six geese a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree. [Source https://rosettacode.org]
You are given a collection of ABC blocks (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple: 1. Once a letter on a block is used that block cannot be used again 2. The function should be case-insensitive 3. Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True [Source https://rosettacode.org/wiki/ABC_Problem]
Given a text file of many lines, where fields within a line are delineated by a single 'dollar' character, write a program that aligns each column of fields by ensuring that words in each column are separated by at least one space. For Example: Given$a$text$file$of$many$lines,$where$fields$within$a$line$ are$delineated$by$a$single$'dollar'$character,$write$a$program that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$ column$are$separated$by$at$least$one$space. Notes: - The example input texts lines may, or may not, have trailing dollar characters. - Lines may, or may not, contain the same number of fields. - All columns should share the same alignment. - Consecutive space characters produced adjacent to the end of lines are insignificant for the purposes of the task. - Assume output text will be viewed in a mono-spaced font on a plain text editor or basic terminal. - The minimum space between columns should be computed from the text and not hard-coded. [Source https://rosettacode.org]
Write a program to generate all potential anagrams of an input string. For example, the potential anagrams of "biro" are biro bior brio broi boir bori ibro ibor irbo irob iobr iorb rbio rboi ribo riob roib robi obir obri oibr oirb orbi orib
Write a program to shuffle an array. Start by writing a function which will accept two integer arguments (min,max) and generate a random integer between min and max where: o) min is an inclusive lower bound o) max is an exclusive upper bound For example (1,7) should generate random integers from {1,2,3,4,5,6} suitable for a dice roll. How will you test this? Use this function to write shuffle: Iterate through the array and for each element[i] generate a random integer (min=r,max=array.size) swap the integers at indexes i and r The shuffle function o) does not mutate the array argument o) returns an array o) the returned array is randomly shuffled! o) the returned array is a permutation of the array argument
Write a program to determine if the parentheses (), the brackets [], and the braces {}, in a string are balanced. For example: {{)(}} is not balanced because ) comes before ( ({)} is not balanced because ) is not balanced between {} and similarly the { is not balanced between () [({})] is balanced {}([]) is balanced {()}[[{}]] is balanced
Task Shuffle the characters of a string in such a way that as many of the character values are in a different position as possible. Display the result as follows: original string, shuffled string, (score) The score gives the number of positions whose character value did not change. Example tree, eetr, (0) Test cases abracadabra seesaw elk grrrrrr up a [Source https://rosettacode.org/wiki/Best_shuffle]
Write a program to score a game of Ten-Pin Bowling. Input: string (described below) representing a bowling game Output: integer score The scoring rules: Each game, or "line" of bowling, includes ten turns, or "frames" for the bowler. In each frame, the bowler gets up to two tries to knock down all ten pins. If the first ball in a frame knocks down all ten pins, this is called a "strike". The frame is over. The score for the frame is ten plus the total of the pins knocked down in the next two balls. If the second ball in a frame knocks down all ten pins, this is called a "spare". The frame is over. The score for the frame is ten plus the number of pins knocked down in the next ball. If, after both balls, there is still at least one of the ten pins standing the score for that frame is simply the total number of pins knocked down in those two balls. If you get a spare in the last (10th) frame you get one more bonus ball. If you get a strike in the last (10th) frame you get two more bonus balls. These bonus throws are taken as part of the same turn. If a bonus ball knocks down all the pins, the process does not repeat. The bonus balls are only used to calculate the score of the final frame. The game score is the total of all frame scores. Examples: X indicates a strike / indicates a spare - indicates a miss | indicates a frame boundary The characters after the || indicate bonus balls X|X|X|X|X|X|X|X|X|X||XX Ten strikes on the first ball of all ten frames. Two bonus balls, both strikes. Score for each frame == 10 + score for next two balls == 10 + 10 + 10 == 30 Total score == 10 frames x 30 == 300 9-|9-|9-|9-|9-|9-|9-|9-|9-|9-|| Nine pins hit on the first ball of all ten frames. Second ball of each frame misses last remaining pin. No bonus balls. Score for each frame == 9 Total score == 10 frames x 9 == 90 5/|5/|5/|5/|5/|5/|5/|5/|5/|5/||5 Five pins on the first ball of all ten frames. Second ball of each frame hits all five remaining pins, a spare. One bonus ball, hits five pins. Score for each frame == 10 + score for next one ball == 10 + 5 == 15 Total score == 10 frames x 15 == 150 X|7/|9-|X|-8|8/|-6|X|X|X||81 Total score == 167
Your task is to process a sequence of integer numbers to determine the following statistics: o) minimum value o) maximum value o) number of elements in the sequence o) average value For example: [6, 9, 15, -2, 92, 11] o) minimum value = -2 o) maximum value = 92 o) number of elements in the sequence = 6 o) average value = 21.833333
Given a list of integers find the closest to zero. If there is a tie, choose the positive value.
Write a function accepting a list of non negative integers, and returning their largest possible combined number as a string. For example given [50, 2, 1, 9] it returns "95021" (9 + 50 + 2 + 1) given [5, 50, 56] it returns "56550" (56 + 5 + 50) given [420, 42, 423] it returns "42423420" (42 + 423 + 420) Source [https://blog.svpino.com/about]
There are four types of common coins in US currency: o) quarters (25 cents) o) dimes (10 cents) o) nickels (5 cents) o) pennies (1 cent) There are 6 ways to make change for 15 cents: o) A dime and a nickel; o) A dime and 5 pennies; o) 3 nickels; o) 2 nickels and 5 pennies; o) A nickel and 10 pennies; o) 15 pennies. How many ways are there to make change for a dollar using these common coins? (1 dollar = 100 cents). [Source http://rosettacode.org]
James Bach, [describes](http://www.satisfice.com/blog/archives/22) counter strings as follows: "A counterstring is a graduated string of arbitrary length. No matter where you are in the string, you always know the character position. This comes in handy when you are pasting huge strings into fields and they get truncated at a certain point. You want to know how many characters that is." The string always ends in an asterisk and any number in a string denotes the position of the succeeding asterisk. Length 5: *3*5* Length 10: *3*5*7*10* Length 35: 2*4*6*8*11*14*17*20*23*26*29*32*35* Your task is to write a program that takes a non-negative integer number and creates a counterstring of that length.
When reviewing a traffic-light, cyber-dojo uses a function to select one of the files. Your task is to write this selection function. The function has two parameters: o) previous-filename; a string the filename of the previously viewed traffic-light o) diffs; an array diff data, one per file. The function returns the index of the selected diff (in diffs) according to the following cascading rules: Rule 1: If any diff is for a changed, previous-filename, select it. Rule 2: If any diff is for a changed, non .txt file, select one with the (possibly equal) largest change-count. Rule 3: If any diff is for an identically renamed, non .txt file, select one with the (possibly equal) largest same-count. Rule 4: If any diff is for an empty, created, non .txt file, select one. Rule 5: If any diff is for an empty, deleted, non .txt file, select one. Rule 6: If any diff is for a changed, .txt file, select one with the (possibly equal) largest change-count. Rule 7: If any diff is for an identically renamed, .txt file, select one with the (possibly equal) largest same-count. Rule 8: If any diff is for the (unchanged) previous-filename, select it. Rule 9: Select the diff whose filename is 'cyber-dojo.sh' Note: o) 'changed' means 'change-count' is greater than zero. o) 'change-count' means the sum of the added line-count and the deleted line-count. o) a diff for 'cyber-dojo.sh' will always exist. The diff data for each file is in JSON format. For example: { "type": "changed", "old_filename": "hiker.h", "new_filename": "hiker.h", "line_counts: { "added":4, "deleted":3, "same":27 } } o) "type" is a string One of ["deleted","created","renamed","unchanged","changed"] o) "old_filename" is a string o) "new_filename" is a string if "type" is "deleted" "old_filename" will be the filename "new_filename" will be null if type is "created" "old_filename" will be null "new_filename" will be the filename if type is "renamed" "old_filename" will be the old filename "new_filename" will be the new (different) filename if "type" is "unchanged" "old_filename" will be the filename "new_filename" will be the (same) filename (neither the file's content nor its name has changed) if "type" is "changed" "old_filename" will be the filename "new_filename" will be the (same) filename (the file's content has changed, but not its name) o) "line_counts" if "type" is "deleted" "added" is zero "same" is zero "deleted" was the number of lines in the deleted file (zero if the deleted file was empty) if "type" is "created" "deleted" is zero "same" is zero "added" is the number of lines in the created file (zero if the created file was empty) if "type" is "renamed" "added" is the number of added lines "deleted" is the number of deleted lines "same" is the number of unchanged lines (for an identical rename, "added" and "deleted" will both be zero) if "type" is "unchanged" "added" is zero "deleted" is zero "same" is the number of lines in the unchanged file if "type" is "changed" "added" is the number of added lines "deleted" is the number of deleted lines "same" is the number of unchanged lines. ("added" or "deleted" or both will be non-zero)
Think of binary numbers: sequences of 0's and 1's. How many n-digit binary numbers are there that don't have two adjacent 1 bits? For example, for three-digit numbers, Five of the possible eight combinations meet the criteria: 000, 001, 010, 011, 100, 101, 110, 111. What is the number for sequences of length 4, 5, 10, n? Having worked out the pattern, there's a second part to the question: can you prove why that relationship exists? (Source http://codekata.pragprog.com, Code Kata Fifteen -- A Diversion)
Place eight chess queens on an 8x8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. [source: http://en.wikipedia.org/wiki/Eight_queens_puzzle]
When you rename a file, cyber-dojo tries to be helpful and selects only the part of the filename it thinks you will want to change. Your task is to write a function that is given a string filename and which returns a pair of integers specifying the start and end indexes (into the filename) of the selected range. First, it assumes you will want to keep the extension. Eg "hiker.cpp" ==> "hiker" is selected. "diamond.h" ==> "diamond" is selected. Second, if the filename includes the word "tests", "test", "spec", or "step" (case insensitive) it assumes you will want to keep those too, together with any 'separator' characters (dot, underscore, hyphen). Eg "HikerTest.js" ==> "Hiker" is selected. "Diamond_Spec.feature" => "Diamond" is selected. "fizz.buzz-tests.js" => "fizz.buzz" is selected. Third, if the filename is in a dir/ it assumes you will also want to keep that. Eg "test/FizzBuzz_test.exs" => "FizzBuzz" is selected. "src/test/Roman.spec.re" => "Roman" is selected. Here is a JSON data structure you can use in your tests. { "src/Hiker_spec.re": [4,9], "test/hiker_test.exs": [5,10], "wibble/test/hiker_spec.rb": [12,17], "hiker_steps.rb": [0,5], "hiker_spec.rb": [0,5], "test_hiker.rb": [5,10], "test_hiker.py": [5,10], "test_hiker.sh": [5,10], "tests_hiker.sh": [6,11], "test_hiker.coffee": [5,10], "hiker_spec.coffee": [0,5], "hikerTest.chpl": [0,5], "hiker.tests.c": [0,5], "hiker_tests.c": [0,5], "hiker_test.c": [0,5], "hiker_Test.c": [0,5], "HikerTests.cpp": [0,5], "hikerTests.cpp": [0,5], "HikerTest.cs": [0,5], "HikerTest.java": [0,5], "DiamondTest.kt": [0,7], "HikerTest.php": [0,5], "hikerTest.js": [0,5], "hiker-test.js": [0,5], "hiker-spec.js": [0,5], "hiker.test.js": [0,5], "hiker.tests.ts": [0,5], "hiker_tests.erl": [0,5], "hiker_test.clj": [0,5], "fizzBuzz_test.d": [0,8], "hiker_test.go": [0,5], "hiker.tests.R": [0,5], "hikertests.swift": [0,5], "HikerSpec.groovy": [0,5], "hikerSpec.feature": [0,5], "hiker.feature": [0,5], "hiker.fun": [0,5], "hiker.t": [0,5], "hiker.plt": [0,5], "hiker": [0,5], };
The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence. In plain terms, the algorithm shuffles the sequence. The algorithm effectively puts all the elements into a hat; it continually determines the next element by randomly drawing an element from the hat until no elements remain. The algorithm produces an unbiased permutation: every permutation is equally likely. -- To shuffle an array a of n elements (indices 0..n-1): for i from n−1 downto 1 do j ← random integer such that 0 ≤ j ≤ i exchange a[j] and a[i] Task: Implement and test this algorithm. [Source https://en.wikipedia.org/wiki/Fisher-Yates_shuffle]
The month of October in 2010 has five Fridays, five Saturdays, and five Sundays. Task 1. Write a program to show all months that have this same characteristic of five full weekends from the year 1900 through 2100 (Gregorian calendar). 2. Show the number of months with this property (there should be 201). 3. Show at least the first and last five dates, in order. Extra credit Count and/or show all of the years which do not have at least one five-weekend month (there should be 29). [Source https://rosettacode.org/wiki/Five_weekends]
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Sample output: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz ... etc up to 100
Write a program that prints the numbers from 1 to 100, but... numbers that are exact multiples of 3, or that contain 3, must print a string containing "Fizz" For example 9 -> "...Fizz..." For example 31 -> "...Fizz..." numbers that are exact multiples of 5, or that contain 5, must print a string containing "Buzz" For example 10 -> "...Buzz..." For example 52 -> "...Buzz..."
Write a program to show that the 13th day of the month falls more often on a Friday than any other day of the week. The 1st of January 1973 was a Monday. You should aim at producing the clearest possible program, not the fastest. [source: BCPL the language and its compiler by Martin Richards and Colin Whitby-Strevens]
Your task is to write a program to calculate the next generation of Conway's game of life, given any starting position. You start with a two dimensional grid of cells, where each cell is either alive or dead. The grid is finite, and no life can exist off the edges. When calculating the next generation of the grid, follow these four rules: 1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation. 2. Any live cell with more than three live neighbours dies, as if by overcrowding. 3. Any live cell with two or three live neighbours lives on to the next generation. 4. Any dead cell with exactly three live neighbours becomes a live cell. See example/1 and example/2
Create functions to encode a number to and decode a number from Gray code. Display the normal binary representations, Gray code representations, and decoded Gray code values for all 5-bit binary numbers (0-31 inclusive, leading 0's not necessary). There are many possible Gray codes. The following encodes what is called "binary reflected Gray code." Encoding (MSB is bit 0, b is binary, g is Gray code): if b[i-1] = 1 g[i] = not b[i] else g[i] = b[i] Decoding (MSB is bit 0, b is binary, g is Gray code): b[0] = g[0] for other bits: b[i] = g[i] xor b[i-1] [Source http://rosettacode.org]
When doing a cyber-dojo group exercise, you can review the files from any active avatar in the group! The [<] button moves you to the previous avatar. The [>] button moves you to the next avatar. The previous/next ordering is based on the avatar's indexes, which have a range of [0..64) 0==alligator 1==antelope ... 62==wolf 63==zebra Your task is to implement a function called groupNeighbours() which is passed two arguments: o) the current avatar's id (String) o) data for all the avatars (Hash) For example: groupNeighbours("Q55b8b", { "15": { id:"EEJSkR", events:[0,1,2] }, // 15==fox "3": { id:"w34rd5", events:[0] }, // 2==bear "23": { id:"Q55b8b", events:[0,1,2,3] }, // 23==jellyfish "44": { id:"REf1t7", events:[0,1,2,3,4] }, // 44==rhino }) The function must return three pieces of data: o) the id of the previous avatar o) the avatar-index matching the id (1st arg) o) the id of the next avatar 0) The keys of the Hash are Strings not Integers. 1) The Hash always contains an entry whose id matches the 1st arg. 2) If there is no previous avatar, return an empty string. For example groupNeighbours("2z4449", { "36": { id:"2z4449", events:[0,1,2,3] }, // 36==parrot "49": { id:"s86eR4", events:[0,1,2,3,4,5] }, // 49==snake }) returns [ "", 36, "s86eR4" ] 3) If there is no next avatar, return an empty string. For example groupNeighbours("s86eR4", { "36": { id:"2z4449", events:[0,1,2,3] }, // 36==parrot "49": { id:"s86eR4", events:[0,1,2,3,4,5] }, // 49==snake }) returns [ "2z4449", 49, "" ] 4) Ignore inactive avatars - whose events array has less than 2 entries. For example: groupNeighbours("Q55b8b", { "15": { id:"EEJSkR", events:[0,1,2] }, // 15==fox "3": { id:"w34rd5", events:[0] }, // 3==bear (inactive) "23": { id:"Q55b8b", events:[0,1,2,3] }, // 23==jellyfish "44": { id:"REf1t7", events:[0,1,2,3,4] }, // 44==rhino }) returns [ "EEJSkR", 23, "REf1t7" ] not [ "w34rd5", 23, "REf1t7" ] 5) Return the avatar-index as an integer. For example [ "EEJSkR", 23, "REf1t7" ] not [ "EEJSkR", "23", "REf1t7" ]
Haiku is an ancient form of Japanese poetry. A haiku is a three-line poem with seventeen syllables, where the first line must contain five syllables, the second line must contain seven syllables, and the third line must contain five syllables. The lines do not have to rhyme. Here is an example, where slashes separate the lines: Computer programs/The bugs try to eat my code/I must not let them. You must write a program that will review a haiku and check that each line contains the correct number of syllables. Input The input contains one or more lines, each of which contains a single haiku. A haiku will contain at least three words, and words will be separated by either a single space or a slash ('/'). Slashes also separate the three lines of a haiku, so each haiku will contain exactly two slashes. (The three lines of the haiku will be contained within one physical line of the file.) A haiku will contain only lowercase letters ('a'-'z'), forward slashes ('/'), and spaces, and will be no more than 200 characters long (not counting the end-of-line characters). Each haiku is guaranteed to contain three lines, and each line will contain at least one word. Your job is to determine whether each line has the correct number of syllables (5/7/5). For the purposes of this problem, every contiguous sequence of one or more vowels counts as one syllable, where the vowels are a, e, i, o, u, and y. Every word will contain at least one syllable. (Note that this method of counting syllables does not always agree with English conventions. In the second example below, your program must consider the word 'code' to have two syllables because the 'o' and the 'e' are not consecutive. However, in English the 'e' is silent and so 'code' actually has only one syllable.) Output For each haiku, output a comma-separated single line that contains the number of syllables in each haiku, together with the letter Y if it is a haiku, or N if it is not a haiku (see below). Sample Input happy purple frog/eating bugs in the marshes/get indigestion computer programs/the bugs try to eat my code/i will not let them Sample Output 5,7,5,Yes 5,8,5,No [Source: http://uva.onlinejudge.org/]
To try and encourage more sales of the 5 different Harry Potter books they sell, a bookshop has decided to offer discounts of multiple-book purchases. One copy of any of the five books costs 8 EUR. If, however, you buy two different books, you get a 5% discount on those two books. If you buy 3 different books, you get a 10% discount. If you buy 4 different books, you get a 20% discount. If you go the whole hog, and buy all 5, you get a huge 25% discount. Note that if you buy, say, four books, of which 3 are different titles, you get a 10% discount on the 3 that form part of a set, but the fourth book still costs 8 EUR. Your mission is to write a piece of code to calculate the price of any conceivable shopping basket (containing only Harry Potter books), giving as big a discount as possible. For example, how much does this basket of books cost? 2 copies of the first book 2 copies of the second book 2 copies of the third book 1 copy of the fourth book 1 copy of the fifth book One way of group these 8 books is: 1 group of 5 --> 25% discount (1st,2nd,3rd,4th,5th) +1 group of 3 --> 10% discount (1st,2nd,3rd) This would give a total of 5 books at a 25% discount +3 books at a 10% discount Giving 5 x (8 - 2.00) == 5 x 6.00 == 30.00 +3 x (8 - 0.80) == 3 x 7.20 == 21.60 For a total of 51.60 However, a different way to group these 8 books is: 1 group of 4 books --> 20% discount (1st,2nd,3rd,4th) +1 group of 4 books --> 20% discount (1st,2nd,3rd,5th) This would give a total of 4 books at a 20% discount +4 books at a 20% discount Giving 4 x (8-1.60) == 4 x 6.40 == 25.60 +4 x (8-1.60) == 4 x 6.40 == 25.60 For a total of 51.20 And 51.20 is the price with the biggest discount.
ISBN - International Standard Book Number ----------------------------------------- There are two ISBN standards: ISBN-10 and ISBN-13. Support for ISBN-13 is essential, whereas support for ISBN-10 is optional. Here are some valid examples of each: ISBN-10: 0471958697 0 471 60695 2 0-470-84525-2 0-321-14653-0 ISBN-13: 9780470059029 978 0 471 48648 0 978-0596809485 978-0-13-149505-0 978-0-262-13472-9 ISBN-10 is made up of 9 digits plus a check digit (which may be 'X') and ISBN-13 is made up of 12 digits plus a check digit. Spaces and hyphens may be included in a code, but are not significant. This means that 9780471486480 is equivalent to 978-0-471-48648-0 and 978 0 471 48648 0. The check digit for ISBN-10 is calculated by multiplying each digit by its position (i.e., 1 x 1st digit, 2 x 2nd digit, etc.), summing these products together and taking modulo 11 of the result (with 'X' being used if the result is 10). The check digit for ISBN-13 is calculated by multiplying each digit alternately by 1 or 3 (i.e., 1 x 1st digit, 3 x 2nd digit, 1 x 3rd digit, 3 x 4th digit, etc.), summing these products together, taking modulo 10 of the result and subtracting this value from 10, and then taking the modulo 10 of the result again to produce a single digit. Basic task: Create a function that takes a string and returns true if that is a valid ISBN-13 and false otherwise. Advanced task: Also return true if the string is a valid ISBN-10.
Task Problem: you have a standard 8x8 chessboard, empty but for a single knight on some square. Your task is to emit a series of legal knight moves that result in the knight visiting every square on the chessboard exactly once. Note that it is not a requirement that the tour be "closed"; that is, the knight need not end within a single move of its start position. Input: starting square Output: move sequence All input/output is to use Algebraic Notation. See https://en.wikipedia.org/wiki/Algebraic_notation_(chess) [Source https://rosettacode.org/wiki/Knight's_tour]
Your task is to create an LCD string representation of an integer value using a 3x3 grid of space, underscore, and pipe characters for each digit. Each digit is shown below (using a dot instead of a space) ._. ... ._. ._. ... ._. ._. ._. ._. ._. |.| ..| ._| ._| |_| |_. |_. ..| |_| |_| |_| ..| |_. ._| ..| ._| |_| ..| |_| ..| Example: 910 ._. ... ._. |_| ..| |.| ..| ..| |_|
Write a function that returns true or false depending on whether its input integer is a leap year or not. A leap year is defined as one that is divisible by 4, but is not otherwise divisible by 100 unless it is also divisible by 400. For example, 2001 is a typical common year and 1996 is a typical leap year, whereas 1900 is an atypical common year and 2000 is an atypical leap year.
In information theory and computer science, the Levenshtein distance is a metric for measuring the amount of difference between two sequences (i.e. an edit distance). The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character. Examples: The Levenshtein distance between "kitten" and "sitting" is 3, since the following three edits change one into the other, and there isn't a way to do it with fewer than three edits: kitten sitten (substitution of 'k' with 's') sitten sittin (substitution of 'e' with 'i') sittin sitting (insert 'g' at the end). The Levenshtein distance between "rosettacode", "raisethysword" is 8. Note: The distance between two strings is same as that when both strings are reversed. Task: Implements a Levenshtein distance function, or uses a library function. Show the Levenshtein distance between "kitten" and "sitting". [Source https://rosettacode.org]
You task is to find the length of the longest common prefix from a set of strings. There are two variations: Variation 1. Find the length of longest common prefix across ALL strings in the set. For example: { "new", "next" } ==> 2 { "newest", "new", "newly" } ==> 3 { "pond", "pod", "new", "newest" } ==> 0 Variation 2. Find the length of longest common prefix across ANY two or more strings in the set. For example: { "pond", "newest" } ==> 0 { "new", "night" } ==> 1 { "newest", "new", "newly" } ==> 3 { "pond", "pod", "new", "newest" } ==> 3
This puzzle comes from Lewis Carroll. The magic part is when the values on a square are arranged so that adding them up in any direction results in a constant sum. You have the following values: 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 You need to arrange them in a 3 x 3 matrix so that: o) The sums of numbers in each row = magic number o) The sums of numbers in each column = magic number o) The sums of numbers in each diagonal = magic number Source: https://github.com/gigasquid/wonderland-clojure-katas
The instructions for this exercise can be found here https://code.google.com/archive/p/marsrovertechchallenge/
A field of N x M squares is represented by N lines of exactly M characters each. o) The character '*' represents a mine. o) The character '.' represents no-mine. Example input (a 3 x 4 mine-field of 12 squares, 2 of which are mines) 3 4 *... ..*. .... Your task is to write a program to accept this input and produce as output a hint-field of identical dimensions where each square is a * for a mine or the number of adjacent mine-squares if the square does not contain a mine. Example output (for the above input) *211 12*1 0111
Your task is to create a mine-sweeper style game. You start at the bottom of an 8x8 grid with 5 lives. You must move to the top whilst trying to avoid the hidden mines. You move up/down/left/right each turn. If you step on a mine: o) the mine is revealed and shown as '*' o) you lose a life o) you do not move into the mine's square o) the mine remains explosive Your current position is shown as 'O' Squares you have previously stepped on are shown as 'o' If you reach the top of the grid you win and the game ends. If you run out of lives you lose and the game ends. If you attempt to move off the grid: o) you stay in the same square o) you do not lose a life A parameter holds the likelihood each square contains a mine: o) this parameter ranges from 0 (inclusive) to 1 (exclusive) o) a value of 0 means no square contains a mine o) a value of 0.5 means a 50% chance any square is mined o) reject generated grids with no mine-free path to the top o) in other words, each game must be winnable Your initial starting position at the bottom: o) is randomly chosen o) does not contain a mine
Suppose you're on a game show and you're given the choice of three doors. Behind one door is a car; behind the others, goats. The car and the goats were placed randomly behind the doors before the show. The rules of the game show are as follows: After you have chosen a door, the door remains closed for the time being. The game show host, Monty Hall, who knows what is behind the doors, now has to open one of the two remaining doors, and the door he opens must have a goat behind it. If both remaining doors have goats behind them, he chooses one randomly. After Monty Hall opens a door with a goat, he will ask you to decide whether you want to stay with your first choice or to switch to the last remaining door. For example: Imagine that you chose Door 1 and the host opens Door 3, which has a goat. He then asks you "Do you want to switch to Door Number 2?" Is it to your advantage to change your choice? Note that the player may initially choose any of the three doors (not just Door 1), that the host opens a different door revealing a goat (not necessarily Door 3), and that he gives the player a second choice between the two remaining unopened doors. Simulate at least a thousand games using three doors for each strategy and show the results in such a way as to make it easy to compare the effects of each strategy. [Source http://rosettacode.org]
Given a number, we can form a number chain by 1) arranging its digits in descending order 2) arranging its digits in ascending order 3) subtracting the number obtained in (2) from the number obtained (1) to form a new number 4) and repeat these steps unless the new number has already appeared in the chain Note that 0 is a permitted digit. The number of distinct numbers in the chain is the length of the chain. You are to write a program that reads numbers and outputs the number chain and the length of that chain for each number read. Input and Output ---------------- The input consists of a positive number, less than 10^9. The output consists of the number chain generated by the input number, followed by its lengths exactly in the format indicated below. Example-1 --------- Input 123456789 Output Original number was 123456789 987654321 - 123456789 = 864197532 987654321 - 123456789 = 864197532 Chain length 2 Example-2 --------- Input 1234 Output Original number was 1234 4321 - 1234 = 3087 8730 - 378 = 8352 8532 - 2358 = 6174 7641 - 1467 = 6174 Chain length 4 Example-3 --------- Input 444 Output Original number was 444 444 - 444 = 0 0 - 0 = 0 Chain length 2 [Source: http://uva.onlinejudge.org/]
Spell out a number. For example o) 99 --> ninety nine o) 300 --> three hundred o) 310 --> three hundred and ten o) 1501 --> one thousand, five hundred and one o) 12609 --> twelve thousand, six hundred and nine o) 512607 --> five hundred and twelve thousand, six hundred and seven o) 43112603 --> forty three million, one hundred and twelve thousand, six hundred and three [Source http://rosettacode.org]
Given a list of phone numbers, determine if it is consistent. In a consistent phone list no number is a prefix of another. For example: o) Bob 91 12 54 26 o) Alice 97 625 992 o) Emergency 911 In this case, it is not possible to call Bob because the phone exchange would direct your call to the emergency line as soon as you dialled the first three digits of Bob's phone number. So this list would not be consistent.
A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or spades (denoted C, D, H, and S in the input data). Each card also has a value which is one of 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, ace (denoted 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A). For scoring purposes, the suits are unordered while the values are ordered as given above, with 2 being the lowest and ace the highest value. A poker hand consists of 5 cards dealt from the deck. Poker hands are ranked by the following partial order from lowest to highest. High Card: Hands which do not fit any higher category are ranked by the value of their highest card. If the highest cards have the same value, the hands are ranked by the next highest, and so on. Pair: 2 of the 5 cards in the hand have the same value. Hands which both contain a pair are ranked by the value of the cards forming the pair. If these values are the same, the hands are ranked by the values of the cards not forming the pair, in decreasing order. Two Pairs: The hand contains 2 different pairs. Hands which both contain 2 pairs are ranked by the value of their highest pair. Hands with the same highest pair are ranked by the value of their other pair. If these values are the same the hands are ranked by the value of the remaining card. Three of a Kind: Three of the cards in the hand have the same value. Hands which both contain three of a kind are ranked by the value of the 3 cards. Straight: Hand contains 5 cards with consecutive values. Hands which both contain a straight are ranked by their highest card. Flush: Hand contains 5 cards of the same suit. Hands which are both flushes are ranked using the rules for High Card. Full House: 3 cards of the same value, with the remaining 2 cards forming a pair. Ranked by the value of the 3 cards. Four of a kind: 4 cards with the same value. Ranked by the value of the 4 cards. Straight flush: 5 cards of the same suit with consecutive values. Ranked by the highest card in the hand. Your job is to rank pairs of poker hands and to indicate which, if either, has a higher rank. Examples: Input: Black: 2H 3D 5S 9C KD White: 2C 3H 4S 8C AH Output: White wins - high card: Ace Input: Black: 2H 4S 4C 2D 4H White: 2S 8S AS QS 3S Output: Black wins - full house Input: Black: 2H 3D 5S 9C KD White: 2C 3H 4S 8C KH Output: Black wins - high card: 9 Input: Black: 2H 3D 5S 9C KD White: 2D 3H 5C 9S KH Output: Tie
Factorize a positive integer number into its prime factors. For example: o) 2 -> [2] o) 3 -> [3] o) 4 -> [2,2] o) 6 -> [2,3] o) 9 -> [3,3] o) 12 -> [2,2,3] o) 15 -> [3,5]
Given a letter print a diamond starting with 'A' with the supplied letter at the widest point. This is the print diamond for 'E'. ....A.... ...B.B... ..C...C.. .D.....D. E.......E .D.....D. ..C...C.. ...B.B... ....A.... This is the print diamond for 'C'. ..A.. .B.B. C...C .B.B. ..A.. This is the print diamond for 'A'. A Note: These examples use dots in place of spaces only for readability. Your diamond must contain spaces where there are dots.
Develop a recently-used-list class to hold strings uniquely in Last-In-First-Out order. o) A recently-used-list is initially empty. o) The most recently added item is first, the least recently added item is last. o) Items can be looked up by index, which counts from zero. o) Items in the list are unique, so duplicate insertions are moved rather than added. Optional extras o) Null insertions (empty strings) are not allowed. o) A bounded capacity can be specified at construction, so there is an upper limit to the number of items contained, with the least recently added items dropped on overflow.
Define a function RemoveDuplicate(nlist) to remove duplicate elements from list. Here are some examples: [] -> [] [1,2] -> [1,2] [1,1,2,2,3,3] -> [1,2,3] Author: Ramya V, KGISL
Given a sequence of characters your task is to reorder them as follows: Move a range of elements from one position to another, preserving their order and the order of the other elements. e.g. Given the sequence { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' } moving the range of elements starting at element[1] (B) and ending at element[3] (D) to the position before element[8] (I) will give { 'A', 'E', 'F', 'G', 'H', 'B', 'C', 'D', 'I', 'J' }
Given a Roman number as a string (eg "XX") determine its integer value (eg 20). You cannot write numerals like IM for 999. Wikipedia states "Modern Roman numerals are written by expressing each digit separately starting with the leftmost digit and skipping any digit with a value of zero." Examples: "I" -> 1 "II" -> 2 "III" -> 3 "IV" -> 4 "V" -> 5 "VI" -> 6 "VII" -> 7 "VIII" -> 8 "IX" -> 9 "X" -> 10 "XX" -> 20 "XXX" -> 30 "XL" -> 40 "L" -> 50 "LX" -> 60 "LXX" -> 70 "LXXX" -> 80 "XC" -> 90 "C" -> 100 "CC" -> 200 "CCC" -> 300 "CD" -> 400 "D" -> 500 "DC" -> 600 "DCC" -> 700 "DCCC" -> 800 "CM" -> 900 "M" -> 1000 "MM" -> 2000 "MMM" -> 3000 "MMMM" -> 4000 "MCMXC" -> 1990 ("M" -> 1000 + "CM" -> 900 + "XC" -> 90) "MMVIII" -> 2008 ("MM" -> 2000 + "VIII" -> 8) "XCIX" -> 99 ("XC" -> 90 + "IX" -> 9) "XLVII" -> 47 ("XL" -> 40 + "VII" -> 7)
Reversi is a board game for two players. The board contains 8x8 squares. The players place Black or White counters onto the board, one counter per square. More information can be found on Wikipedia en.wikipedia.org/wiki/Reversi?. Your task is to write a program that takes a current board position together with information about whose turn it is, and returns a list of the legal moves for that player. A move is only legal if it results in at least one of the opponent's counters being flipped. Example input: (the final B indicates it is Black's turn) ........ ........ ........ ...BW... ...WB... ........ ........ ........ B Example output: (each zero indicates a legal move for Black) ........ ........ ....0... ...BW0.. ..0WB... ...0.... ........ ........ B
Given a positive integer number (eg 42) determine its Roman numeral representation as a String (eg "XLII"). You cannot write numerals like IM for 999. Wikipedia states "Modern Roman numerals are written by expressing each arabic digit separately, starting with the leftmost digit, and skipping any digit with a value of zero." For example: 1990 -> "MCMXC" (1000 -> "M" + 900 -> "CM" + 90 -> "XC") 2008 -> "MMVIII" (2000 -> "MM" + 8 -> "VIII") 99 -> "XCIX" (90 -> "XC" + 9 -> "IX") 47 -> "XLVII" (40 -> "XL" + 7 -> "VII") The 'digits' are as follows: "I" -> 1 "II" -> 2 "III" -> 3 "IV" -> 4 "V" -> 5 "VI" -> 6 "VII" -> 7 "VIII" -> 8 "IX" -> 9 "X" -> 10 "XX" -> 20 "XXX" -> 30 "XL" -> 40 "L" -> 50 "LX" -> 60 "LXX" -> 70 "LXXX" -> 80 "XC" -> 90 "C" -> 100 "CC" -> 200 "CCC" -> 300 "CD" -> 400 "D" -> 500 "DC" -> 600 "DCC" -> 700 "DCCC" -> 800 "CM" -> 900 "M" -> 1000 "MM" -> 2000 "MMM" -> 3000 "MMMM" -> 4000
Write a program to search for the "saddle points" in a 5 by 5 array of integers. A saddle point is a cell whose value is greater than or equal to any in its row, and less than or equal to any in its column. There may be more than one saddle point in the array. Print out the coordinates of any saddle points your program finds. Print out "No saddle points" if there are none. [source: http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html]
You task is to implement a tennis scoring program. Summary of tennis scoring: 1. A game is won by the first player to have won at least four points in total and at least two points more than the opponent. 2. The running score of each game is described in a manner peculiar to tennis: scores from zero to three points are described as "love", "fifteen", "thirty", and "forty" respectively. 3. If at least three points have been scored by each player, and the scores are equal, the score is "deuce". 4. If at least three points have been scored by each side and a player has one more point than his opponent, the score of the game is "advantage" for the player in the lead. [source http://en.wikipedia.org/wiki/Tennis#Scoring]
Alice found herself very tiny and wandering around Wonderland. Even the grass around her seemed like a maze. This is a tiny maze solver. A maze is represented by a matrix [[:S 0 1] [1 0 1] [1 0 :E]] S : start of the maze E : end of the maze 1 : This is a wall that you cannot pass through 0 : A free space that you can move through. The goal is the get to the end of the maze. A solved maze will have a :x in the start, the path, and the end of the maze, like this. [[:x :x 1] [1 :x 1] [1 :x :x]] Source: https://github.com/gigasquid/wonderland-clojure-katas
Given a string, strip all occurences of consecutively occuring backslash and newline characters. For example, assuming that: "\\" represents '\' and "\n" represents '\n' "ab\\\ncd\\\nef" --> "abcdef" (two stripped out) "abc\\\ndef" --> "abcdef" (one stripped out) "abc\n\\def" --> unchanged (wrong order) "abc\\def" --> unchanged (no \n) "abc\ndef" --> unchanged (no \) "abcdef" --> unchanged
Vending Machine Kata ==================== In this exercise you will build the brains of a vending machine. It will accept money, make change, maintain inventory, and dispense products. All the things that you might expect a vending machine to accomplish. The point of this kata to to provide a larger than trivial exercise that can be used to practice TDD. A significant portion of the effort will be in determining what tests should be written and, more importantly, written next. Features ======== Accept Coins ------------ _As a vendor_ _I want a vending machine that accepts coins_ _So that I can collect money from the customer_ The vending machine will accept valid coins (nickels, dimes, and quarters) and reject invalid ones (pennies). When a valid coin is inserted the amount of the coin will be added to the current amount and the display will be updated. When there are no coins inserted, the machine displays INSERT COIN. Rejected coins are placed in the coin return. NOTE: The temptation here will be to create Coin objects that know their value. However, this is not how a real vending machine works. Instead, it identifies coins by their weight and size and then assigns a value to what was inserted. You will need to do something similar. This can be simulated using strings, constants, enums, symbols, or something of that nature. Select Product -------------- _As a vendor_ _I want customers to select products_ _So that I can give them an incentive to put money in the machine_ There are three products: cola for $1.00, chips for $0.50, and candy for $0.65. When the respective button is pressed and enough money has been inserted, the product is dispensed and the machine displays THANK YOU. If the display is checked again, it will display INSERT COIN and the current amount will be set to $0.00. If there is not enough money inserted then the machine displays PRICE and the price of the item and subsequent checks of the display will display either INSERT COIN or the current amount as appropriate. Make Change ----------- _As a vendor_ _I want customers to receive correct change_ _So that they will use the vending machine again_ When a product is selected that costs less than the amount of money in the machine, then the remaining amount is placed in the coin return. Return Coins ------------ _As a customer_ _I want to have my money returned_ _So that I can change my mind about buying stuff from the vending machine_ When the return coins button is pressed, the money the customer has placed in the machine is returned and the display shows INSERT COIN. Sold Out -------- _As a customer_ _I want to be told when the item I have selected is not available_ _So that I can select another item_ When the item selected by the customer is out of stock, the machine displays SOLD OUT. If the display is checked again, it will display the amount of money remaining in the machine or INSERT COIN if there is no money in the machine. Exact Change Only ----------------- _As a customer_ _I want to be told when exact change is required_ _So that I can determine if I can buy something with the money I have before inserting it_ When the machine is not able to make change with the money in the machine for any of the items that it sells, it will display EXACT CHANGE ONLY instead of INSERT COIN.
You must find a way to generate the wonderland number. It has six digits. If you multiply it by 2,3,4,5, or 6, the resulting number has all the same digits in at as the original number. The only difference is the position that they are in. Source: https://github.com/gigasquid/wonderland-clojure-katas
Your task is to write a function that takes two arguments, a string and an integer width. The function returns the string, but with line breaks inserted at just the right places to make sure that no line is longer than the column number. You try to break lines at word boundaries. Like a word processor, break the line by replacing the last space in a line with a newline.
The game of yatzy is a simple dice game. Each player rolls five six-sided dice. The player places the roll in a category, such as ones, twos, fives, pair, two pairs etc (see below). If the roll is compatible with the category, the player gets a score for the roll according to the rules. If the roll is not compatible with the category, the player scores zero for the roll. For example, if a player rolls 5,6,5,5,2 and scores the dice in the fives category they would score 15 (three fives). Your task is to score a GIVEN roll in a GIVEN category. You do NOT have to program the random dice rolling. You do NOT have to program re-rolls (as in the real game). You do NOT play by letting the computer choose the highest scoring category for a given roll. Yatzy Categories and Scoring Rules ================================== Chance: The player scores the sum of all dice, no matter what they read. For example, 1,1,3,3,6 placed on "chance" scores 14 (1+1+3+3+6) 4,5,5,6,1 placed on "chance" scores 21 (4+5+5+6+1) Yatzy: If all dice have the same number, the player scores 50 points. For example, 1,1,1,1,1 placed on "yatzy" scores 50 5,5,5,5,5 placed on "yatzy" scores 50 1,1,1,2,1 placed on "yatzy" scores 0 Ones, Twos, Threes, Fours, Fives, Sixes: The player scores the sum of the dice that reads one, two, three, four, five or six, respectively. For example, 1,1,2,4,4 placed on "fours" scores 8 (4+4) 2,3,2,5,1 placed on "twos" scores 4 (2+2) 3,3,3,4,5 placed on "ones" scores 0 Pair: If exactly two dice have the same value then the player scores the sum of the two highest matching dice. For example, when placed on "pair" 3,3,3,4,4 scores 8 (4+4) 1,1,6,2,6 scores 12 (6+6) 3,3,3,4,1 scores 0 3,3,3,3,1 scores 0 Two pairs: If exactly two dice have the same value and exactly two dice have a different value then the player scores the sum of these four dice. For example, when placed on "two pairs" 1,1,2,3,3 scores 8 (1+1+3+3) 1,1,2,3,4 scores 0 1,1,2,2,2 scores 0 Three of a kind: If there are exactly three dice with the same number then the player scores the sum of these dice. For example, when placed on "three of a kind" 3,3,3,4,5 scores 9 (3+3+3) 3,3,4,5,6 scores 0 3,3,3,3,1 scores 0 Four of a kind: If there are exactly four dice with the same number then the player scores the sum of these dice. For example, when placed on "four of a kind" 2,2,2,2,5 scores 8 (2+2+2+2) 2,2,2,5,5 scores 0 2,2,2,2,2 scores 0 Small straight: When placed on "small straight", if the dice read 1,2,3,4,5, the player scores 15 (the sum of all the dice). Large straight: When placed on "large straight", if the dice read 2,3,4,5,6, the player scores 20 (the sum of all the dice). Full house: If the dice are two of a kind and three of a different kind then the player scores the sum of all five dice. For example, when placed on "full house" 1,1,2,2,2 scores 8 (1+1+2+2+2) 2,2,3,3,4 scores 0 4,4,4,4,4 scores 0
The game of yatzy is a simple dice game. Each player rolls five six-sided dice. The player places the roll in a category, such as one-pair, two-pair, small-straight etc (see below). If the roll is compatible with the category, the player gets a score for the roll according to the rules. If the roll is not compatible with the category, the player scores zero for the roll. For example, if a player rolls 5,6,5,6,2 and scores the dice in the two-pairs category they would score 22 (5+5+6+6). Your task is to score a GIVEN roll in a GIVEN category. You do NOT have to program the random dice rolling. You do NOT have to program re-rolls (as in the real game). You do NOT play by letting the computer choose the highest scoring category for a given roll. Yatzy Categories and Scoring Rules ================================== Yatzy: If all dice have the same number, the player scores 50 points, otherwise 0. For example, 1,1,1,1,1 placed on "yatzy" scores 50 5,5,5,5,5 placed on "yatzy" scores 50 1,1,1,2,1 placed on "yatzy" scores 0 Pair: If exactly two dice have the same value then the player scores the sum of the two highest matching dice. For example, when placed on "pair" 3,3,3,4,4 scores 8 (4+4) 1,1,6,2,6 scores 12 (6+6) 3,3,3,4,1 scores 0 3,3,3,3,1 scores 0 Two pairs: If exactly two dice have the same value and exactly two dice have a different value then the player scores the sum of these four dice. For example, when placed on "two pairs" 1,1,2,3,3 scores 8 (1+1+3+3) 1,1,2,3,4 scores 0 1,1,2,2,2 scores 0 Three of a kind: If there are exactly three dice with the same number then the player scores the sum of these dice. For example, when placed on "three of a kind" 3,3,3,4,5 scores 9 (3+3+3) 3,3,4,5,6 scores 0 3,3,3,3,1 scores 0 Four of a kind: If there are exactly four dice with the same number then the player scores the sum of these dice. For example, when placed on "four of a kind" 2,2,2,2,5 scores 8 (2+2+2+2) 2,2,2,5,5 scores 0 2,2,2,2,2 scores 0 Small straight: When placed on "small straight", if the dice read 1,2,3,4,5, the player scores 15 (the sum of all the dice). Large straight: When placed on "large straight", if the dice read 2,3,4,5,6, the player scores 20 (the sum of all the dice). Full house: If the dice are two of a kind and three of a different kind then the player scores the sum of all five dice. For example, when placed on "full house" 1,1,2,2,2 scores 8 (1+1+2+2+2) 2,2,3,3,4 scores 0 4,4,4,4,4 scores 0
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, 5, 8, 13. The decimal number eleven can be written as 0*13 + 1*8 + 0*5 + 1*3 + 0*2 + 0*1 or 010100 in positional notation where the columns represent multiplication by a particular member of the sequence. Leading zeroes are dropped so that eleven decimal becomes 10100. 10100 is not the only way to make eleven from the Fibonacci numbers however; 0*13 + 1*8 + 0*5 + 0*3 + 1*2 + 1*1 or 010011 would also represent decimal 11. For a true Zeckendorf number there is the added restriction that no two consecutive Fibonacci numbers can be used which leads to the former unique solution. Your task is to generate and show here a table of the Zeckendorf number representations of the decimal numbers zero to twenty, in order. [Source http://rosettacode.org]