分享 challenge #1 - #6 update 06/03

oth · 发布于 2017年05月22日 · 最后由 dsh0416 回复于 2017年06月04日 · 2583 次阅读
1475
本帖已被设为精华帖!

前面的敌人, 看起来值得一战.
尊敬的朋友, 今天你健身了吗?

歧视有很多, 种族, 性别, 年龄, 地域, 学历, 健康, 性取向...
软件行业天然的抹平歧视
做熟练下面的几百 challenges, 就精通了编程语言基础
这里是编程职业生涯的起点

电梯 challenge #2
电梯 challenge #3
电梯 challenge #4
电梯 challenge #5
电梯 challenge #6

学习编程的方法有很多, 也因人而异, 有人适合看书, 有人适合看视频教程, 有人天生就很有天赋.

解决 challenges 是掌握编程语言的方法之一, 这种方法可以锻炼你的思维, 更加熟悉编程语言,

很多 challenges 都是在工作中产生的, 在你独自闯荡江湖之前, 需要掌握解决这些问题的方法.

www.reddit.com, 对标百度贴吧

是大洋对岸老百姓喜闻乐见的地方. 换句话说, 这些 challenges 并不是

去 flag 等 tops 公司所要考察的, 也不需要过人的智力和学历, 请有一点耐心和坚持.

题目源自 dailyprogrammer 我搬过来, 有时间我会写写

请在回帖里写下你的代码, 如果你想得到修改建议

这是最接近面试要求的方法
由于文化背景不同, 可以掠过那不熟悉的题目

Challenge 1 [easy]

Create a program that will ask the users name and username, age. have it tell them the information back, in the format
写一程序, 询问用户姓名, 年龄, username. 并返回这些信息, 如下:

Your name is ...,
you are ... years old,
your username is ...

have the program log this information in a file to be accessed later.
记录这些信息到一个 file 以备访问.

共收到 16 条回复
1475

easy

puts '>> Please input your name:'
name = gets.chomp
puts '>> Please input your age:'
age = gets.chomp
puts '>> Please input your username'
username = gets.chomp

puts ">> Your name is #{name}." + \
     " You are #{age} years old" + \
     " and username is #{username}"
1475 oth 量产型炮灰工程师 中提及了此贴 05月22日 20:57
1475

challenge 1 [intermediate]

create a program that will allow you to enter events organizable by hour.
新建一程序, 允许你输入 events , 并且可以按时间排序
There must be menu options of some form, and you must be able to easily edit, add, and delete events without directly changing the source code.
必须有一些表单的菜单选项,您必须能够轻松地编辑,添加和删除事件,而无需直接更改源代码
(note that by menu i dont necessarily mean gui. as long as you can easily access the different options and receive prompts and instructions telling you how to use the program, it will probably be fine)
(请注意,菜单不一定是 gui, 只要您可以轻松访问不同的选项,并收到提示和说明告, 诉您如何使用程序,这样体验会好很多)


根据上面描述, 在写程序之前, 要翻译成这样:

  1. Create a menu driven program
  2. Using the menu drive program allow a user to add/delete items
  3. The menu should be based on an events calendar where users enter the events by hour
  4. No events should be hard-coded.

这种逐条的语义翻译, 是一项必备技能, 拿到任务后第一件事情就是列1234..

一定要养成这个习惯

1475

challenge 1 hard

we all know the classic "guessing game" with higher or lower prompts.
经典的 “猜测游戏”具有 更高 或 更低 的提示
lets do a role reversal; you create a program that will guess numbers between 1-100, and respond appropriately based on whether users say that the number is too high or too low.
让角色逆转, 您将创建一个可以在1-100之间猜测数字的程序, 并根据用户是否认为数字太高或太低,进行适当的响应
Try to make a program that can guess your number based on user input and great code!
尝试制作这个程序,可以根据用户输入猜测你的数字!

0b45a6

这些还真是锻炼基本逻辑的题,推荐白板练习

8744
1475oth 回复

仔细看了题目发现,做反了,哭。。。

NUMBERS = (1..100).to_a
QUIT = 'q'

def make_a_guess(number, guess)
  if guess > number
    puts 'too high'
  elsif guess < number
    puts 'too low'
  end

  guess == number
end

def start_round(round)
  system "clear"
  puts "round #{round}"
  number = NUMBERS.shuffle!.first

  while true
    puts "please make a guess(1~100, quit: #{QUIT}):"

    guess = gets.chomp!

    return if guess == QUIT

    unless guess =~ /\A\d+\Z/
      puts 'oops! not a number'
      next
    end

    break if make_a_guess(number, guess.to_i)
  end

  start_round(round + 1)
end

start_round(1)

0b45a6
1475oth 回复

给个短小的解

puts 'The answer is ' + (1..100).to_a.bsearch { |x|
  print ">> Is it #{x}? [too high/too low/yes(default)]: "
  (input = gets.chomp) == 'too low' ? 1 : input == 'too high' ? -1 : 0
}.to_s
0b45a6
0b45a6dsh0416 回复

我还能写出一个不含分号一行解决的解。

puts 'The answer is ' + (1..100).to_a.bsearch { |x| (input = [(print ">> Is it #{x}? [too high/too low/yes(default)]: "), gets.chomp][1]) == 'too low' ? 1 : input == 'too high' ? -1 : 0 }.to_s
Db3f5c
a  = rand(0..100) 
b = -1
while (a != b)
    puts '>> Please input  number:'
    b = gets.chomp.to_i
    if b>a
        puts "too high"
    else
    end
    if b<a
        puts "too low"
    else
    end
end
16793
def guess_number down = 1, up = 100, current_number = nil
  current_number = rand(100) + 1 if current_number.nil?
  puts "I guess the number is #{current_number} [smaller/bigger/correct]"
  result = gets.chomp
  case result
  when 'bigger'
    up = current_number
    current_number = (down + current_number) / 2
  when 'smaller'
    down = current_number
    current_number = (up + current_number) / 2
  when 'correct'
    puts "The correct number is #{current_number}"
    return
  else
    puts 'Please enter the result of bigger or smaller'
  end
  guess_number down, up, current_number
end
11楼 已删除
1475

前面的敌人, 看起来值得一战.
尊敬的朋友, 今天你健身了吗?


challenge 2 easy

Hello, coders! An important part of programming is being able to apply your programs, so your challenge for today is to create a calculator application that has use in your life.

Hello, coders! 编程的一个重要部分是能够应用您的程序,所以您今天的挑战是创建一个在您的生活中使用的计算器。

It might be an interest calculator, or it might be something that you can use in the classroom.

它可能是一个利息计算器,或是可以在教室中使用的计算器。

For example, if you were in physics class, you might want to make a F = M * A calc.

例如,在物理课,你可能想要一个F = M * A 计算。


challenge 2 intermediate

create a short text adventure that will call the user by their name.

创建一个短文本冒险,将通过其名称呼叫用户。

The text adventure should use standard text adventure commands ("l, n, s, e, i, etc.").

文本冒险应使用标准文本冒险命令(“l,n,s,e,i”等)。

for extra credit, make sure the program doesn't fault, quit, glitch, fail, or loop no matter what is put in, even empty text or spaces. These will be tested rigorously!

为了额外的信用,请确保程序没有故障,退出,故障,失败或循环,无论放入什么,甚至空的文本或空格。 这些将被严格测试!

For super extra credit, code it in C


challenge 2 hard

Your mission is to create a stopwatch program. this program should have start, stop, and lap options, and it should write out to a file to be viewed later.

您的任务是创建一个秒表程序。 这个程序应该有 start,stop 和 lap 选项,它应该把结果写入一个文件以供将来查看


1107 jasl 将本帖设为了精华贴 05月24日 22:13
1475

天哪, 你真高!

challenge 3 easy

Welcome to cipher day! write a program that can encrypt texts with an alphabetical caesar cipher. This cipher can ignore numbers, symbols, and whitespace. 编写一个可以使用字母凯撒密码加密文本的程序,该密码可以忽略数字,符号和空格。 for extra credit, add a "decrypt" function to your program!


challenge 3 intermediate

Welcome to cipher day! Create a program that can take a piece of text and encrypt it with an alphabetical substitution cipher. This can ignore white space, numbers, and symbols.

创建一个程序,可以拿一段文本,并按字母顺序替换密码, 进行加密。 可以忽略空白,数字和符号。

for extra credit, make it encrypt whitespace, numbers, and symbols! for extra extra credit, decode someone elses cipher!


challenge 3 hard

Welcome to cipher day! For this challenge, you need to write a program that will take the scrambled words from this post, and compare them against THIS WORD LIST to unscramble them. For bonus points, sort the words by length when you are finished. Post your programs and/or subroutines!

需要编写一个程序,这个程序将从下面获取加密的单词,并将它们与这个 WORD LIST 进行比较来解读它们。 对于奖励,当完成时,按长度排序单词。 发布您的程序和/或子程序!

Here are your words to de-scramble:

mkeart
sleewa
edcudls
iragoge
usrlsle
nalraoci
nsdeuto
amrhat
inknsy
iferkna

提示:

结果是

mkeart unscrambled is market
sleewa unscrambled is weasel
edcudls unscrambled is cuddles
iragoge unscrambled is georgia
usrlsle unscrambled is russell
nalraoci unscrambled is carolina
nsdeuto unscrambled is notused
amrhat unscrambled is martha
inknsy unscrambled is skinny
iferkna unscrambled is frankie

考察 WORD LIST 中的内容

1475

challenge 4 easy

You're challenge for today is to create a random password generator!

你今天的挑战是创建一个随机密码生成器!

For extra credit, allow the user to specify the amount of passwords to generate.

对于额外的加分,允许用户指定生成的密码数量。

For even more extra credit, allow the user to specify the length of the strings he wants to generate!

对于更多的额外加分,允许用户指定要生成的字符串的长度!


challenge 4 intermediate

create a calculator program that will take an input, following normal calculator input (5*5+4) and give an answer (29). This calculator should use all four operators.

创建一个计算器程序,将按照正常的计算器输入(5 * 5 + 4)进行输入,并给出答案(29)。 这个计算器应该使用所有四个运算符。

For extra credit, add other operators (6(4+3), 3 ** 3, etc.)


challenge 4 hard

today, your challenge is to create a program that will take a series of numbers (5, 3, 15), and find how those numbers can add, subtract, multiply, or divide in various ways to relate to eachother.

今天,您的挑战是创建一个将采用一系列数字(5,3,15)的程序,并找出通过各种方式添加,减去,乘法或除法。

This string of numbers should result in 5 * 3 = 15, or 15 /3 = 5, or 15/5 = 3. When you are done, test your numbers with the following strings:

这个数字字符串应该得到结果 5 * 3 = 15 或 15/3 = 5 或 15/5 = 3 完成后,使用以下字符串测试您的数字:

4, 2, 8
6, 2, 12
6, 2, 3
9, 12, 108
4, 16, 64

For extra credit, have the program list all possible combinations.

或额外加分,使程序列出所有可能的组合。

for even more extra credit, allow the program to deal with strings of greater than three numbers. For example, an input of (3, 5, 5, 3) would be 3 * 5 = 15, 15/5 = 3. When you are finished, test them with the following strings.

为了更多的加分,允许程序处理大于三个数字的字符串。

2, 4, 6, 3
1, 1, 2, 3
4, 4, 3, 4
8, 4, 3, 6
9, 3, 1, 7
1475

challenge 5 easy

Your challenge for today is to create a program which is password protected, and wont open unless the correct user and password is given.

您今天的挑战是创建一个受密码保护的程序,除非提供正确的用户和密码,否则不会打开。

For extra credit, have the user and password in a seperate .txt file.

额外的加分,将用户和密码放在单独的.text文件中。

for even more extra credit, break into your own program :)


challenge 5 intermediate

Your challenge today is to write a program that can find the number of anagrams within a .txt file.

您今天的挑战是编写一个程序,可以找到 a.txt 文件中的字谜的数量。

For example, "snap" would be an anagram of "pans", and "skate" would be an anagram of "stake".


challenge 5 hard

Arrr, me mateys! Yer' challenge fer' today be a tough one.

It be gettin awfully borein' on the high seas, so yer' job be to create a pirate based fightin' game! This game oughter' be turn based, and you oughter' be able to pick yer attacks every turn.

The best game'll be winnin' some custom flair, and all the rest o' ya will be walkin the plank!


0b45a6
1475oth 回复

challenge 4 intermediate 对新手来说相当难,我给个大致思路吧。

方法一:扫描表达式,把所有 * / 都算了,然后重新扫描算 + -,遇到括号递归执行

方法二:处理成抽象语法树(AST)以支持更多符号的自由添加

challenge 3 hard 最快速的做法是字符排序然后哈希,复杂度可以做到 O(m+n) m 是 word list 的长度,n 是查询的数量。如果需要输出排序还需要加一个 O(n*p) p 是字符串的长度

1475

challenge 6 easy

You're challenge for today is to create a program that can calculate pi accurately to at least 30 decimal places.

你今天的挑战是创建一个可以精确计算 pi, 至少30位小数的程序。

Try not to cheat :)


challenge 6 intermediate

create a program that can remove all duplicate strings from a .txt. file. for example, "bdbdb" -> "bd"

创建一个可以从.txt中删除所有重复字符串的程序。 文件。 例如,“bdbdb” - >“bd”

remove duplicate substrings. Ex: aaajtestBlaBlatestBlaBla ---> aaajtestBlaBla

another example: aaatestBlaBlatestBlaBla aaathisBlaBlathisBlaBla aaathatBlaBlathatBlaBla aaagoodBlaBlagoodBlaBla aaagood1BlaBla123good1BlaBla123

output desired: aaatestBlaBla aaathisBlaBla aaathatBlaBla aaagoodBlaBla aaagood1BlaBla123


challenge 6 hard

create a AI that will play NIM

尼姆游戏(英语:Nim),又译为拈,是一种两个人玩的回合制数学战略游戏。游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家。当指定相应数量时,一堆这样的棋子称作一个尼姆堆。
斯普莱格(R.P.Sprague)和格隆第(P.M.Grundy)独立地证明了一切无偏博弈(从任何一个局势出发,双方可以采取完全相同的行动,也就是说棋盘上没有颜色的区分)都等价于一个特定大小的尼姆堆。但这里的尼姆堆包含的棋子数量可以是无穷的。事实上,它可以是任何序数。


0b45a6
1475oth 回复

Nim Game 的 AI 如果无关输赢的话那就是乱写也可以。因为 Nim Game 从一开始就可以证明是必赢或者必输的。所以一个好的 AI 可以在必输时直接投降,必赢时不会输。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册