Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package newcodewarsgen;
- import java.math.BigInteger;
- import java.util.stream.Collectors;
- import java.util.stream.LongStream;
- /**
- *
- * @author Dazai Osamu
- */
- public class PositionOfDigitalStringMySolution {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // try {
- // BufferedWriter out = new BufferedWriter(new FileWriter("numberfuck.txt"));
- // out.write(generateNum("53635")); //Replace with the string
- // //you are trying to write
- // out.close();
- // }
- // catch (IOException e)
- // {
- // System.out.println("Exception "+e);
- //
- // }
- System.out.println(findPosition("229"));
- // System.out.println(BigInteger.valueOf(187).xor(BigInteger.valueOf(991)));
- // System.out.println(BigInteger.valueOf(6).xor(BigInteger.valueOf(4)));
- }
- // public static String generateNum(String s){
- // while(!num.contains(s)){
- // num+=start.toString();
- // start= start.add(BigInteger.ONE);
- // }
- // return num;
- // }
- public static long findPosition(final String s) {
- BigInteger start = new BigInteger("13");
- String num = "123456789101112";
- Long index = 0L;
- System.out.println("The Num: "+s);
- if(!num.contains(s)){
- if (Long.valueOf(s).compareTo(Long.valueOf("12345678913"))>=0) {
- num = "12345678913";
- index=generateIndex(num);
- return index+((Long.valueOf(s)-Long.valueOf(num))*num.length());
- }else if(Long.valueOf(s).compareTo(Long.valueOf("1234567892"))>=0){
- num = "1234567892";
- index=generateIndex(num);
- return index+((Long.valueOf(s)-Long.valueOf(num))*num.length());
- }else if(Long.valueOf(s).compareTo(Long.valueOf("123456790"))>=0){
- num = "123456790";
- index=generateIndex(num);
- return index+((Long.valueOf(s)-Long.valueOf(num))*num.length());
- }
- }
- while(!num.contains(s)){
- // System.out.println("Num: "+num);
- num +=start.toString();
- start = start.add(BigInteger.ONE);
- }
- return num.indexOf(s)+index;
- }
- public static Long generateIndex(String num){
- return Long.parseLong(LongStream.generate(()->9).limit(num.length()).mapToObj(String::valueOf).collect(Collectors.joining("")));
- }
- public static BigInteger newStart(String num){
- return new BigInteger(num).add(BigInteger.ONE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement