ProjectRuler 算法练习之 位数组成字符串同样的整数
2024-08-23 19:52:12
Problem :
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
Implementation :
var sameDig = function f(n1,n2){ var strN1 = n1.toString();
var strN2 = n2.toString(); if(strN1.length != strN2.length) return false; var arr1 = new Array();
var arr2 = new Array(); for(var i = 0;i < strN1.length; i++){
arr1.push(strN1[i]);
arr2.push(strN2[i]);
} arr1.sort();
arr2.sort(); for(var i = 0;i < arr1.length; i++){ if(arr1[i]!=arr2[i]) return false;} return true; } for(var i = 1;i < 999999; i++){
if(sameDig(i,2*i) &&
sameDig(i,3*i) &&
sameDig(i,4*i) &&
sameDig(i,5*i) &&
sameDig(i,6*i)) {console.log(i); break;}
}
最新文章
- emoji表情 与 iconfont 一锅炖&#128514;
- IOS进阶之WKWebView
- 一个简单的c# 贪吃蛇程序
- wcf 同时支持webhttp 和 引用方式
- JSONP和CORS两种跨域方式的简单介绍和解决方案实例
- 如何为编程爱好者设计一款好玩的智能硬件(三)——该选什么样的MCU呢?
- 转载:设置html页面不让浏览器缓存的方法
- oracle 密码忘记 找回密码
- 如何学习一门新技术-iOS开发
- Windows中进程的内存结构
- 通过pull解析器操作安卓的xml
- (Problem 16)Power digit sum
- 基于node.js构建微服务中的mock服务
- Properties读取属性文件
- Database operations of Mysql
- python学习之时间处理
- Touch事件分发源码解析
- Ubuntu下修改CMake版本
- Delphi XE2 compiler performance
- sencha touch TabPanel 加入导航按钮(向左向右按钮) 以及Carousel插件(2014-11-7)