
Go语言习题集
全部题目引自Codewars
thinshootout
软件工匠
展开
-
Go语言实现Square sums (simple)
描述:Write function square_sums_row (or squareSumsRow/SquareSumsRow depending on language rules) that, given integer number N (in range 2…43), returns array of integers 1…N arranged in a way, so sum of...原创 2019-11-15 16:39:59 · 445 阅读 · 0 评论 -
Go语言实现The Clockwise Spiral
描述:Do you know how to make a spiral? Let’s test it!Classic definition: A spiral is a curve which emanates from a central point, getting progressively farther away as it revolves around the point.Yo...原创 2019-11-11 16:40:44 · 241 阅读 · 0 评论 -
Go语言实现Longest Common Subsequence
描述Write a function called LCS that accepts two sequences and returns the longest subsequence common to the passed in sequences.SubsequenceA subsequence is different from a substring. The terms of a...原创 2019-11-07 17:52:05 · 150 阅读 · 0 评论 -
Go语言实现Josephus Permutation
描述This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans du...原创 2019-11-07 15:30:10 · 155 阅读 · 0 评论 -
Go语言实现Best travel
描述John and Mary want to travel between a few towns A, B, C … Mary has on a sheet of paper a list of distances between these towns. ls = [50, 55, 57, 58, 60]. John is tired of driving and he says to M...原创 2019-11-07 11:29:57 · 420 阅读 · 0 评论 -
Go语言实现Is my friend cheating?
描述A friend of mine takes a sequence of numbers from 1 to n (where n > 0).Within that sequence, he chooses two numbers, a and b.He says that the product of a and b should be equal to the sum of a...原创 2019-11-06 11:26:41 · 246 阅读 · 0 评论 -
Go语言实现Pick peaks
描述In this kata, you will write a function that returns the positions and the values of the “peaks” (or local maxima) of a numeric array.For example, the array arr = [0, 1, 2, 5, 1, 0] has a peak at ...原创 2019-11-05 16:38:17 · 286 阅读 · 0 评论 -
Go语言实现Directions Reduction
描述Once upon a time, on a way through the old wild west,…… a man was given directions to go from one point to another. The directions were “NORTH”, “SOUTH”, “WEST”, “EAST”. Clearly “NORTH” and “SOUTH...原创 2019-11-04 18:02:46 · 327 阅读 · 0 评论 -
Go语言实现Valid Parentheses
描述Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return true if the string is valid, and false if it’s invali...原创 2019-11-04 16:53:13 · 174 阅读 · 0 评论 -
Go语言实现Union of Intervals
描述Write a function interval_insert which takes as inputa list myl of disjoint closed intervals with integer endpoints, sorted by increasing order of left endpointsan interval intervaland returns t...原创 2019-10-27 11:54:46 · 362 阅读 · 0 评论 -
Go语言实现Cartesian neighbors distance
描述In previous kata we have been searching for all the neighboring points in a Cartesian coordinate system. As we know each point in a coordinate system has eight neighboring points when we search it ...原创 2019-10-25 17:05:22 · 197 阅读 · 0 评论 -
Go语言实现Floating-point Approximation (I)
描述Consider the functionf: x -> sqrt(1 + x) - 1 at x = 1e-15.We get: f(x) = 4.44089209850062616e-16or something around that, depending on the language.This function involves the subtraction of ...原创 2019-10-23 16:31:57 · 208 阅读 · 0 评论 -
Go语言实现Catalog
描述You are given a small extract of a catalog:s =<prod><name>drill</name><prx>99</prx><qty>5</qty></prod><prod><name>hammer</name>&...原创 2019-10-21 19:31:17 · 258 阅读 · 0 评论 -
Go语言实现Irreducible Sum of Rationals
描述You will have a list of rationals in the formlst = [ [numer_1, denom_1] , … , [numer_n, denom_n] ]orlst = [ (numer_1, denom_1) , … , (numer_n, denom_n) ]where all numbers are positive integers....原创 2019-10-21 13:16:49 · 193 阅读 · 0 评论 -
Go语言实现Pyramid Array
描述Write a function that when given a number >= 0, returns an Array of ascending length subarrays.pyramid(0) => [ ]pyramid(1) => [ [1] ]pyramid(2) => [ [1], [1, 1] ]pyramid(3) => [ ...原创 2019-10-19 19:36:48 · 145 阅读 · 0 评论 -
Go语言实现Playing on a chessboard
描述With a friend we used to play the following game on a chessboard (8, rows, 8 columns). On the first row at the bottom we put numbers:1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9On row 2 (2nd row from t...原创 2019-10-19 10:38:04 · 490 阅读 · 0 评论 -
Go语言实现A disguised sequence (I)
描述Given u0 = 1, u1 = 2 and the relation 6unun+1-5unun+2+un+1un+2 = 0 calculate un for any integer n >= 0.#Examplesfcn(n) returns un: fcn(17) -> 131072, fcn(21) -> 2097152Remark: You can t...原创 2019-10-19 09:55:31 · 207 阅读 · 0 评论 -
Go语言实现Two Sum
描述Write a function that takes an array of numbers (integers for the tests) and a target number. It should find two different items in the array that, when added together, give the target value. The i...原创 2019-10-17 12:07:49 · 336 阅读 · 0 评论 -
Go语言实现Sum of odd numbers
描述Given the triangle of consecutive odd numbers:13 57 9 1113 15 17 1921 23 25 27 29…Calculate the row sums of this triangle from the row index (starting at index ...原创 2019-10-16 10:19:13 · 164 阅读 · 0 评论 -
Go语言实现Find the odd int
描述Given an array, find the int that appears an odd number of times.There will always be only one integer that appears an odd number of times.分析方法1:遍历数组,借助map保存已遍历过的数据的重复次数。最后遍历map,返回重复次数为奇数的键值。方法...原创 2019-10-15 17:35:36 · 313 阅读 · 0 评论 -
Go语言实现The Baum-Sweet sequence
描述The Baum–Sweet sequence is an infinite automatic sequence of 0s and 1s defined by the rule:bn = 1 if the binary representation of n contains no block of consecutive 0s of odd length;bn = 0 otherw...原创 2019-10-15 12:43:31 · 187 阅读 · 0 评论 -
Go语言实现Reversed Strings
题目引自 codewars:Complete the solution so that it reverses the string value passed into it.Solution(“world”) // returns “dlrow”分析错误实现:func Solution(word string) string { for i, j := 0, len(word) ...原创 2019-10-05 11:35:12 · 227 阅读 · 0 评论 -
Go语言实现Abbreviate a Two Word Name
题目引自codewars:Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.The output should be two capital letters with a dot seperating them....原创 2019-10-05 21:08:34 · 241 阅读 · 0 评论 -
Go语言实现To square(root) or not to square(root)
描述Write a method, that will get an integer array as parameter and will process every number from this array.Return a new array with processing every number of the input-array like this:If the numbe...原创 2019-10-06 12:15:00 · 353 阅读 · 0 评论 -
Go语言实现Growth of a Population
描述引自codewars:In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in...原创 2019-10-06 19:47:19 · 220 阅读 · 0 评论 -
Go语言实现Drying Potatoes
描述引自codewars:All we eat is water and dry matter.John bought potatoes: their weight is 100 kilograms. Potatoes contain water and dry matter.The water content is 99 percent of the total weight. He t...原创 2019-10-08 15:01:11 · 166 阅读 · 0 评论 -
Go语言实现Easy Line
描述In the drawing below we have a part of the Pascal’s triangle, lines are numbered from zero (top).We want to calculate the sum of the squares of the binomial coefficients on a given line with a fun...原创 2019-10-12 14:08:53 · 221 阅读 · 0 评论 -
Go语言实现Baby shark lyrics generator
描述Create a function, as short as possible, that returns this lyrics.Your code should be less than 300 characters. Watch out for the three points at the end of the song.Baby shark, doo doo doo doo d...原创 2019-10-13 19:30:41 · 226 阅读 · 0 评论 -
Go语言实现Floating-point Approximation (III)
描述Professor Chambouliard has just completed an experiment on gravitational waves. He measures their effects on small magnetic particles. This effect is very small and negative. In his first experimen...原创 2019-10-14 14:55:12 · 241 阅读 · 0 评论