54
Convert hexadecimal numbers to their decimal representation Solve English peg solitaire with backtracking (backtracking) Compare chemical elements with the abstract data type Comparable (interfaces) Implement the periodic table of the chemical elements by loading the elements values from a file Design and implement chemical elements (objects) Convert a given number of bytes into a representation with metric units (flow control) Calculate the electrical resistance of a wire (data types and expressions Convert 16 bit Unicode into UTF-8 (data types and expressions) Find the smalles distance between two neighbouring numbers in an array (arrays) Find the digit sum of a sequence of digits (arrays) Winning strategy for Roulette (flow control) Design and implement rational numbers (objects) Find the day of the week of a given date (flow control) Generate Sudokus (backtracking), 2 Design and implement a queue (interfaces) Implement natural mergesort (sorting) Implement Newton's method (searching) Design and implement polynomials (objects)

Java Challenges

Embed Size (px)

DESCRIPTION

java challenges

Citation preview

Convert hexadecimal numbers to their decimal representation Solve English peg solitaire with backtracking (backtracking)

Compare chemical elements with the abstract data type Comparable (interfaces) Implement the periodic table of the chemical elements by loading the elements values from a file Design and implement chemical elements (objects) Convert a given number of bytes into a representation with metric units (flow control) Calculate the electrical resistance of a wire (data types and expressions Convert 16 bit Unicode into UTF-8 (data types and expressions) Find the smalles distance between two neighbouring numbers in an array (arrays) Find the digit sum of a sequence of digits (arrays) Winning strategy for Roulette (flow control)

Design and implement rational numbers (objects) Find the day of the week of a given date (flow control) Generate Sudokus (backtracking), 2 Design and implement a queue (interfaces) Implement natural mergesort (sorting) Implement Newton's method (searching) Design and implement polynomials (objects) Implement bottom-up mergesort (sorting) Implement Shell sort (sorting) Implement Euclids algorithm recursivly (recursion) Find zeros of continueous functions (searching Design and implement a class for wind speed (objects) Implement a simple calculator (recursion) Check for anagrams (arrays), 2 Calculate (german) grades for an examination (flow control) Sort three numbers (flow control) Print out the multiplication table for 1 to 10 (flow control) Give a boolean expression for the definition of a metropolis (data types and expressions)

algorithm: Add the root node to an empty queue while the queue is not empty: Get a node from the queue Print the item in the node if node.left is not null: add it to the queue if node.right is not null: add it to the queue

Write a subroutine that implements this algorithm, and write a program to test the subroutine. Note that you will need a queue of TreeNodes, so you will need to write a class to represent such queues.

program:he characters +, *, and - will be used for the union, intersection, and difference operations. The user of the program will type in lines of input containing two sets, separated by an operator. The program should perform the operation and print the resulting set. Here are some examples:

Input Output ------------------------- ------------------- [1, 2, 3] + [3, 5, 7] [1, 2, 3, 5, 7] [10,9,8,7] * [2,4,6,8] [8] [ 5, 10, 15, 20 ] - [ 0, 10, 20 ] [5, 15]

programs:

1Add all the natural numbers below one thousand that are multiples of 3 or 5.

2By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

3Find the largest prime factor of a composite number.

4Find the largest palindrome made from the product of two 3-digit numbers.

5What is the smallest number divisible by each of the numbers 1 to 20?

6What is the difference between the sum of the squares and the square of the sums?

7Find the 10001st prime.

8Discover the largest product of five consecutive digits in the 1000-digit number.

9Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.

10Calculate the sum of all the primes below two million.

11What is the greatest product of four adjacent numbers on the same straight line in the 20 by 20 grid?

12What is the value of the first triangle number to have over five hundred divisors?

13Find the first ten digits of the sum of one-hundred 50-digit numbers.

14Find the longest sequence using a starting number under one million.

15Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?

16What is the sum of the digits of the number 21000?

17How many letters would be needed to write all the numbers in words from 1 to 1000?

18Find the maximum sum travelling from the top of the triangle to the base.

19How many Sundays fell on the first of the month during the twentieth century?

20Find the sum of digits in 100!

21Evaluate the sum of all amicable pairs under 10000.

22What is the total of all the name scores in the file of first names?

23Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

24What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

25What is the first term in the Fibonacci sequence to contain 1000 digits?

26Find the value of d < 1000 for which 1/d contains the longest recurring cycle.

27Find a quadratic formula that produces the maximum number of primes for consecutive values of n.

28What is the sum of both diagonals in a 1001 by 1001 spiral?

29How many distinct terms are in the sequence generated by ab for 2 = a = 100 and 2 = b = 100?

30Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

31Investigating combinations of English currency denominations.

32Find the sum of all numbers that can be written as pandigital products.

33Discover all the fractions with an unorthodox cancelling method.

34Find the sum of all numbers which are equal to the sum of the factorial of their digits.

35How many circular primes are there below one million?

36Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2.

37Find the sum of all eleven primes that are both truncatable from left to right and right to left.

38What is the largest 1 to 9 pandigital that can be formed by multiplying a fixed number by 1, 2, 3, ... ?

39If p is the perimeter of a right angle triangle, {a, b, c}, which value, for p = 1000, has the most solutions?

40Finding the nth digit of the fractional part of the irrational number.

41What is the largest n-digit pandigital prime that exists?

42How many triangle words does the list of common English words contain?

43Find the sum of all pandigital numbers with an unusual sub-string divisibility property.

44Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

45After 40755, what is the next triangle number that is also pentagonal and hexagonal?

46What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

47Find the first four consecutive integers to have four distinct primes factors.

48Find the last ten digits of 11 + 22 + ... + 10001000.

49Find arithmetic sequences, made of prime terms, whose four digits are permutations of each other.

50Which prime, below one-million, can be written as the sum of the most consecutive primes?

51Find the smallest prime which, by changing the same part of the number, can form eight different primes.

52Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order.

53How many values of C(n,r), for 1 = n = 100, exceed one-million?

54How many hands did player one win in the game of poker?

55How many Lychrel numbers are there below ten-thousand?

56Considering natural numbers of the form, ab, finding the maximum digital sum.

57Investigate the expansion of the continued fraction for the square root of two.

58Investigate the number of primes that lie on the diagonals of the spiral grid.

59Using a brute force attack, can you decrypt the cipher using XOR encryption?

60Find a set of five primes for which any two primes concatenate to produce another prime.

61Find the sum of the only set of six 4-digit figurate numbers with a cyclic property.

62Find the smallest cube for which exactly five permutations of its digits are cube.

63How many n-digit positive integers exist which are also an nth power?

64How many continued fractions for N = 10000 have an odd period?

65Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.

66Investigate the Diophantine equation x2 - Dy2 = 1.

67Using an efficient algorithm find the maximal sum in the triangle?

68What is the maximum 16-digit string for a "magic" 5-gon ring?

69Find the value of n = 1,000,000 for which n/f(n) is a maximum.

70Investigate values of n for which f(n) is a permutation of n.

71Listing reduced proper fractions in ascending order of size.

72How many elements would be contained in the set of reduced proper fractions for d = 1,000,000?

73How many fractions lie between 1/3 and 1/2 in a sorted set of reduced proper fractions?

74Determine the number of factorial chains that contain exactly sixty non-repeating terms.

75Find the number of different lengths of wire that can form a right angle triangle in only one way.

76How many different ways can one hundred be written as a sum of at least two positive integers?

77What is the first value which can be written as the sum of primes in over five thousand different ways?

78Investigating the number of ways in which coins can be separated into piles.

79By analysing a user's login attempts, can you determine the secret numeric passcode?

80Calculating the digital sum of the decimal digits of irrational square roots.

81Find the minimal path sum from the top left to the bottom right by moving right and down.

82Find the minimal path sum from the left column to the right column.

83Find the minimal path sum from the top left to the bottom right by moving left, right, up, and down.

84In the game, Monopoly, find the three most popular squares when using two 4-sided dice.

85Investigating the number of rectangles in a rectangular grid.

86Exploring the shortest path from one corner of a cuboid to another.

87Investigating numbers that can be expressed as the sum of a prime square, cube, and fourth power?

88Exploring minimal product-sum numbers for sets of different sizes.

89Develop a method to express Roman numerals in minimal form.

90An unexpected way of using two cubes to make a square.

91Find the number of right angle triangles in the quadrant.

92Investigating a square digits number chain with a surprising property.

93Using four distinct digits and the rules of arithmetic, find the longest sequence of target numbers.

94Investigating almost equilateral triangles with integral sides and area.

95Find the smallest member of the longest amicable chain with no element exceeding one million.

96Devise an algorithm for solving Su Doku puzzles.

97Find the last ten digits of the non-Mersenne prime: 28433 27830457 + 1.

98Investigating words, and their anagrams, which can represent square numbers.

99Which base/exponent pair in the file has the greatest numerical value?

100Finding the number of blue discs for which there is 50% chance of taking two blue.

101Investigate the optimum polynomial function to model the first k terms of a given sequence.

102For how many triangles in the text file does the interior contain the origin?

103Investigating sets with a special subset sum property.

104Finding Fibonacci numbers for which the first and last nine digits are pandigital.

105Find the sum of the special sum sets in the file.

106Find the minimum number of comparisons needed to identify special sum sets.

107Determining the most efficient way to connect the network.

108Solving the Diophantine equation 1/x + 1/y = 1/n.

109How many distinct ways can a player checkout in the game of darts with a score of less than 100?

110Find an efficient algorithm to analyse the number of solutions of the equation 1/x + 1/y = 1/n.

111Search for 10-digit primes containing the maximum number of repeated digits.

112Investigating the density of "bouncy" numbers.

113How many numbers below a googol (10100) are not "bouncy"?

114Investigating the number of ways to fill a row with separated blocks that are at least three units long.

115Finding a generalisation for the number of ways to fill a row with separated blocks.

116Investigating the number of ways of replacing square tiles with one of three coloured tiles.

117Investigating the number of ways of tiling a row using different-sized tiles.

118Exploring the number of ways in which sets containing prime elements can be made.

119Investigating the numbers which are equal to sum of their digits raised to some power.

120Finding the maximum remainder when (a - 1)n + (a + 1)n is divided by a2.

121Investigate the game of chance involving coloured discs.

122Finding the most efficient exponentiation method.

123Determining the remainder when (pn - 1)n + (pn + 1)n is divided by pn2.

124Determining the kth element of the sorted radical function.

125Finding square sums that are palindromic.

126Exploring the number of cubes required to cover every visible face on a cuboid.

127Investigating the number of abc-hits below a given limit.

128Which tiles in the hexagonal arrangement have prime differences with neighbours?

129Investigating minimal repunits that divide by n.

130Finding composite values, n, for which n-1 is divisible by the length of the smallest repunits that divide it.

131Determining primes, p, for which n3 + n2p is a perfect cube.

132Determining the first forty prime factors of a very large repunit.

133Investigating which primes will never divide a repunit containing 10n digits.

134Finding the smallest positive integer related to any pair of consecutive primes.

135Determining the number of solutions of the equation x2 - y2 - z2 = n.

136Discover when the equation x2 - y2 - z2 = n has a unique solution.

137Determining the value of infinite polynomial series for which the coefficients are Fibonacci numbers.

138Investigating isosceles triangle for which the height and base length differ by one.

139Finding Pythagorean triangles which allow the square on the hypotenuse to be tiled.

140Investigating the value of infinite polynomial series for which the coefficients are a linear second order recurrence relation.

141Investigating progressive numbers, n, which are also square.

142Perfect Square Collection

143Investigating the Torricelli point of a triangle

144Investigating multiple reflections of a laser beam.

145How many reversible numbers are there below one-billion?

146Investigating a Prime Pattern

147Rectangles in cross-hatched grids

148Exploring Pascal's triangle.

149Searching for a maximum-sum subsequence.

150Searching a triangular array for a sub-triangle having minimum-sum.

151Paper sheets of standard sizes: an expected-value problem.

152Writing 1/2 as a sum of inverse squares

153Investigating Gaussian Integers

154Exploring Pascal's pyramid.

155Counting Capacitor Circuits.

156Counting Digits

157Solving the diophantine equation 1/a+1/b= p/10n

158Exploring strings for which only one character comes lexicographically after its neighbour to the left.

159Digital root sums of factorisations.

160Factorial trailing digits

161Triominoes

162Hexadecimal numbers

163Cross-hatched triangles

164Numbers for which no three consecutive digits have a sum greater than a given value.

165Intersections

166Criss Cross

167Investigating Ulam sequences

168Number Rotations

169Exploring the number of different ways a number can be expressed as a sum of powers of 2.

170Find the largest 0 to 9 pandigital that can be formed by concatenating products.

171Finding numbers for which the sum of the squares of the digits is a square.

172Investigating numbers with few repeated digits.

173Using up to one million tiles how many different "hollow" square laminae can be formed?

174Counting the number of "hollow" square laminae that can form one, two, three, ... distinct arrangements.

175Fractions involving the number of different ways a number can be expressed as a sum of powers of 2.

176Rectangular triangles that share a cathetus.

177Integer angled Quadrilaterals.

178Step Numbers

179Consecutive positive divisors

180Rational zeros of a function of three variables.

181Investigating in how many ways objects of two different colours can be grouped.

182RSA encryption

183Maximum product of parts

184Triangles containing the origin.

185Number Mind

186Connectedness of a network.

187Semiprimes

188The hyperexponentiation of a number

189Tri-colouring a triangular grid

190Maximising a weighted product

191Prize Strings

192Best Approximations

193Squarefree Numbers

194Coloured Configurations

195Inscribed circles of triangles with one angle of 60 degrees

196Prime triplets

197Investigating the behaviour of a recursively defined sequence

198Ambiguous Numbers

199Iterative Circle Packing

200Find the 200th prime-proof sqube containing the contiguous sub-string "200"

201Subsets with a unique sum1040202Laserbeam1213203Squarefree Binomial Coefficients4409204Generalised Hamming Numbers3617205Dice Game6897206Concealed Square9893207Integer partition equations2445208Robot Walks859209Circular Logic1280210Obtuse Angled Triangles848211Divisor Square Sum1802212Combined Volume of Cuboids747213Flea Circus1103214Totient Chains2533215Crack-free Walls1847216Investigating the primality of numbers of the form 2n2-11943217Balanced Numbers751218Perfect right-angled triangles1485219Skew-cost coding777220Heighway Dragon1292221Alexandrian Integers1030222Sphere Packing1080223Almost right-angled triangles I705224Almost right-angled triangles II602225Tribonacci non-divisors2133226A Scoop of Blancmange948227The Chase987228Minkowski Sums745229Four Representations using Squares744230Fibonacci Words1576231The prime factorisation of binomial coefficients2694232The Race887233Lattice points on a circle812234Semidivisible numbers1803235An Arithmetic Geometric sequence2728236Luxury Hampers535237Tours on a 4 x n playing board803238Infinite string tour560239Twenty-two Foolish Primes946240Top Dice1146241Perfection Quotients506242Odd Triplets575243Resilience3195244Sliders693245Coresilience464246Tangents to an ellipse466247Squares under a hyperbola796248Numbers for which Eulers totient function equals 13!655249Prime Subset Sums1148250250250

251Cardano Triplets671252Convex Holes516253Tidying up526254Sums of Digit Factorials542255Rounded Square Roots512256Tatami-Free Rooms432257Angular Bisectors398258A lagged Fibonacci sequence722259Reachable Numbers727260Stone Game688261Pivotal Square Sums395262Mountain Range.440263An engineers' dream come true565264Triangle Centres374265Binary Circles2031266Pseudo Square Root787267Billionaire1457268Counting numbers with at least four distinct prime factors less than 100712269Polynomials with at least one integer root403270Cutting Squares409271Modular Cubes, part 11027272Modular Cubes, part 2459273Sum of Squares675274Divisibility Multipliers782275Balanced Sculptures390276Primitive Triangles559277A Modified Collatz sequence1495278Linear Combinations of Semiprimes517279Triangles with integral sides and an integral angle 401280Ant and seeds530281Pizza Toppings475282The Ackermann function523283Integer sided triangles for which the area/perimeter ratio is integral.402284Steady Squares656285Pythagorean odds619286Scoring probabilities952287Quadtree encoding (a simple compression algorithm)715288An enormous factorial607289Eulerian Cycles330290Digital Signature531291Panaitopol Primes632292Pythagorean Polygons373293Pseudo-Fortunate Numbers1137294Sum of digits - experience #23472295Lenticular holes331296Angular Bisector and Tangent357297Zeckendorf Representation1336298Selective Amnesia396299Three similar triangles397300Protein folding

301Nim2186302Strong Achilles Numbers392303Multiples with small digits1592304Primonacci875305Reflexive Position383306Paper-strip Game560307Chip Defects701308An amazing Prime-generating Automaton432309Integer Ladders406310Nim Square483311Biclinic Integral Quadrilaterals280312Cyclic paths on Sierpinski graphs 432313Sliding game603314The Mouse on the Moon303315Digital root clocks1084316Numbers in decimal expansions355317Firecracker9823182011 nines445319Bounded Sequences249320Factorials divisible by a huge integer384321Swapping Counters711322Binomial coefficients divisible by 10270323Bitwise-OR operations on random integers1221324Building a tower340325Stone Game II300326Modulo Summations301327Rooms of Doom534328Lowest-cost Search242329Prime Frog862330Euler's Number287331Cross flips221332Spherical triangles327333Special partitions491334Spilling the beans270335Gathering the beans267336Maximix Arrangements655337Totient Stairstep Sequences272338Cutting Rectangular Grid Paper220339Peredur fab Efrawg306340Crazy Function412341Golomb's self-describing sequence464342The totient of a square is a cube388343Fractional Sequences677344Silver dollar game143345Matrix Sum1406346Strong Repunits1004347Largest integer divisible by two primes994348Sum of a square and a cube867349Langton's ant736350Constraining the least greatest and the greatest least

351Hexagonal orchards895352Blood tests308353Risky moon252354Distances in a bee's honeycomb 199355Maximal coprime subset292356Largest roots of cubic polynomials280357Prime generating integers1747358Cyclic numbers621359Hilbert's New Hotel568360Scary Sphere354361Subsequence of Thue-Morse sequence140362Squarefree factors251363Bzier Curves442364Comfortable distance331365A huge binomial coefficient436366Stone Game III302367bozo sort213368A Kempner-like series301369Badugi 267370Geometric triangles 285371Licence plates532372Pencils of rays256373Circumscribed Circles226374Maximum Integer Partition Product 313375Minimum of subsequences366376Nontransitive sets of dice165377Sum of digits, experience 13307378Triangle Triples328379Least common multiple count230380Amazing Mazes!262381(prime-k) factorial1041382Generating polygons204383Divisibility comparison between factorials262384Rudin-Shapiro sequence212385Ellipses inside triangles163386Maximum length of an antichain313387Harshad Numbers743388Distinct Lines262389Platonic Dice527390Triangles with non rational sides and integral area332391Hopping Game152392Enmeshed unit circle248393Migrating ants287394Eating pie220395Pythagorean tree268396Weak Goodstein sequence234397Triangle on parabola115398Cutting rope167399Squarefree Fibonacci Numbers225400Fibonacci tree game

401Sum of squares of divisors355402Integer-valued polynomials95403Lattice points enclosed by parabola and line