全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1443 1
2014-08-15
Some digits look (nearly) the same when turned upside-down (0, 1, 8).
Two more come in a pair, each being the other turned upside down (6,
9). The rest (2, 3, 4, 5, 7) don't look like digits when turned upside down.
Some years look the same when turned upside-down. For example, 1691
is unchanged if turned upside down. (Note that turning a year upside
down means turning the digits upside down and reverseing their order.)

Write an R function that can be used to test whether positive integers
are unchanged when turned upside-down. The function should have the
following form.
invertible =
function(n) {
...
}
Given a vector of positive integers, the function should return a vector
of logicals that indicate whether the values look the same when turned
upside-down.
Here is how the function should appear in action.
> invertible(c(1, 96, 99, 123, 1691))
[1] TRUE TRUE FALSE FALSE TRUE

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-8-15 10:59:51
Hints: Positive integers, a and b, will be part of a triple whenever the
square root of a^2 + b^2 is an integer. You will need try all combinations
of a and b less than or equal to p 1000 and check whether a < b and that
sqrt(a^2 + b^2) is an integer less than or equal to 1000. Sequence generation,
repetition and subsetting may prove useful.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群