r/dailyprogrammer • u/Cosmologicon 2 3 • Mar 12 '18
[2018-03-12] Challenge #354 [Easy] Integer Complexity 1
Challenge
Given a number A, find the smallest possible value of B+C, if B*C = A. Here A, B, and C must all be positive integers. It's okay to use brute force by checking every possible value of B and C. You don't need to handle inputs larger than six digits. Post the return value for A = 345678 along with your solution.
For instance, given A = 12345 you should return 838. Here's why. There are four different ways to represent 12345 as the product of two positive integers:
12345 = 1*12345
12345 = 3*4115
12345 = 5*2469
12345 = 15*823
The sum of the two factors in each case is:
1*12345 => 1+12345 = 12346
3*4115 => 3+4115 = 4118
5*2469 => 5+2469 = 2474
15*823 => 15+823 = 838
The smallest sum of a pair of factors in this case is 838.
Examples
12 => 7
456 => 43
4567 => 4568
12345 => 838
The corresponding products are 12 = 3*4, 456 = 19*24, 4567 = 1*4567, and 12345 = 15*823.
Hint
Want to test whether one number divides evenly into another? This is most commonly done with the modulus operator (usually %), which gives you the remainder when you divide one number by another. If the modulus is 0, then there's no remainder and the numbers divide evenly. For instance, 12345 % 5 is 0, because 5 divides evenly into 12345.
Optional bonus 1
Handle larger inputs efficiently. You should be able to handle up to 12 digits or so in about a second (maybe a little longer depending on your programming language). Find the return value for 1234567891011.
Hint: how do you know when you can stop checking factors?
Optional bonus 2
Efficiently handle very large inputs whose prime factorization you are given. For instance, you should be able to get the answer for 6789101112131415161718192021 given that its prime factorization is:
6789101112131415161718192021 = 3*3*3*53*79*1667*20441*19646663*89705489
In this case, you can assume you're given a list of primes instead of the number itself. (To check your solution, the output for this input ends in 22.)
3
u/congratz_its_a_bunny Mar 12 '18 edited Mar 12 '18
Python
It can get the optional bonus 1 quickly (much less than a second)
given the product, the minimal sum will be the two factors closest to each other, which (for not perfect squares) are the factors closest on either side of the square root of the product, hence I start at the square root and go down.
gets the right answers for the 4 examples.
for bonus 1 it gives
Bonus 2 in reply
11
u/Gylergin Mar 12 '18
TI-Basic: Written on my TI-84+. Basic brute-force program that starts at sqrt(N) for a small optimization. It also outputs the amount of time the program runs in seconds.
Input:
12345
123456
12345678
Output:
The calculator can only store up to 14 digits in a single number, so very large numbers like bonus 2 won't run accurately. While the program could theoretically solve bonus 1, I won't bother running it since I imagine it will take more than 10 min.
7
u/porthos3 Mar 13 '18 edited Mar 13 '18
Clojure
Completes Bonus 1 in ~11ms.
Bonus 2
5
u/Digicrests Mar 13 '18
Really quick JavaScript solution, its pretty ugly.
5
u/MohamedElshazly Mar 22 '18
Python3
Would love feedback!!
4
u/zqvt Mar 12 '18
Clojure
using the
lococonstraint programming library=> (7 43 4568 838)4
u/TheoreticallySpooked Mar 13 '18
Node/JS.
No bonuses.
1
u/Bewelge Mar 12 '18 edited Mar 12 '18
Javascript
Measuring with console.time() it took
0.0068359375ms for 12345
9.715ms for 1234567891011
264.229ms for 6789101112131415161718192021Not quite sure what is asked in bonus 2,
it's already so quick with this solution.Edit: Too large number for JS. Does not work this way.
Might take another look at it later.
Edit concerning Bonus 2 :
Ed. 3: Ignore this approach. It's wrong :-)
Ed 4: Finally got it I believe. Still has the issue with the exact number being too large for Javascript to handle, but it doesn't throw the function off far enough to change the result. At least in this case.
Thanks for the challenge, stumbled upon this sub yesterday and this was fun :-)
1
u/zatoichi49 Mar 12 '18 edited Mar 12 '18
Method:
For each factor of n, add factor + n/factor to a set (stopping at sqrt(n) to avoid duplicate sum pairs). Return the min value in the set.
Python 3: with Bonus 1
Output:
3
u/pkoepke Mar 12 '18 edited Mar 12 '18
MUMPS aka M aka Caché. Did bonus 1, didn't do bonus 2. Both subroutines generate the same output: first one written clearly to be read by humans, then a one-liner written as MUMPS was written back when it was created when code size had actual performance implications.
Human-readable:
Idiomatic MUMPS:
Output:
3
u/coldsoletslightafire Mar 17 '18
C
3
u/Nihilist_T21 Mar 20 '18
C#
With bonus 1. First time submitting and very new at making things in C#. Comments appreciated.
Output
3
u/sonic260 Apr 19 '18
Java no bonus.
3
u/2kofawsome Jul 01 '18
python3.6
Here is what I used for normal and bonus 1, done in 0.537970781326294 seconds.
2
u/2SmoothForYou Mar 12 '18
Haskell
Bonus 1 Output
No Bonus 2 yet but I might do it later after school.
2
u/tet5uo Mar 12 '18 edited Mar 12 '18
I'm pretty rusty so just did the basic challenge in c#.
EDIT: Bonus 1 easy enough switching int to long;
And my return values:
2
u/Specter_Terrasbane Mar 12 '18 edited Mar 12 '18
Python 2
Testing
Output
2
u/drewfer Mar 12 '18 edited Mar 13 '18
Rust Simple solution.
EDIT: Little more rust-y on the trial factoring.
2
u/octolanceae Mar 12 '18
C++11
1st bonus included. Will do second bonus later tonight. Worst case senario, runs in sqrt(N) time if number is prime. Otherwise, less.
output
2
u/dig-up-stupid Mar 13 '18
Python 3, bonus 2. Was looking for a heuristic to guide search for the desired divisor but never got anywhere. Resorted to branch and bound with very minimal bounding, seems to save time by a factor of about 2 for some inputs at the cost of exponential-ish memory. Bigger savings from generating divisors uniquely instead of using the powerset, but still exponential. (Eg there are several ways of obtaining a 3 or 9 from the given factors, so since the powerset method generates all combinations, it generates duplicate divisors.)
2
u/Saytahri Mar 13 '18
Haskell with optional bonus 1.
Result: 345678 -> 3491.0 1234567891011 -> 2544788.0
2
u/Robo-Connery Mar 13 '18 edited Mar 13 '18
Solution in fortran with bonus 1:
output with bonus 1 in 3.6ms:
2
u/playnwin Mar 13 '18
PowerShell
Questionably does the bonus 1? It does it in 14.372 seconds, but I think I'm stopping at the most efficient point, so it may just be a Posh thing. If someone can do it faster, do tell.
2
u/ChaseNetwork Mar 14 '18 edited Mar 14 '18
C++ Bonus 1
Result:
2
u/TheoreticallySpooked Mar 14 '18 edited Mar 14 '18
CoffeeScript w/ Bonus 1
Output
2
u/IzukuDeku96 Mar 14 '18 edited Mar 14 '18
Python script v. 2.7
-------output------- "the best result for 12345 is 838" "the best result for 345678 is 3491"
2
u/M2Shawning Mar 16 '18
C++ w/ Bonus 1
2
u/comma_at Mar 16 '18 edited Mar 16 '18
freeforth
example output:
Freeforth is 32-bit and doesn't have bignums so I skipped the bonuses. The solution should run in reasonable time for bonus 1 though
2
u/[deleted] Mar 17 '18
I'm pretty new to this whole "programming" thing. I have taken a couple of beginner classes at Uni, but I know nothing beyond an introduction. I know nothing about algorithms, data structures, etc. I only know the syntax of MatLab (I took a python/Scheme/SQL class, but it was an introduction).
That being said, I searched and found no answers in MatLab, so:
MATLAB
2
u/dustinroepsch Mar 18 '18
Python 3.6
2
u/ChazR Mar 18 '18
Common Lisp
Haven't done one of these for a while. Also, haven't used Common Lisp in years. Verbose and inefficient.
2
u/[deleted] Mar 19 '18
Python 2.7. This should work for optional bonus 1, I think? I'm still pretty noobish at coding, so I'm trying to comment everything so I know what the hell I'm doing.
2
u/Aragami1408 Mar 19 '18
Using Rust:
2
u/waygie Mar 19 '18
Javascript
I made a range of A then looped range, removing both the first divisors of A and the divisor's quotient from range.
2
u/[deleted] Mar 20 '18
Python With bonus #1 in mind
Code:
Output:
2
u/Macaroni2552 Mar 23 '18
JavaScript with Optional #1
Console output:
Performance:
screenshot
Total time: 29.0 ms (Scripting)
Optional #1 Scripting time: 21.66 ms
Any suggestions to clean up / optimize my code is greatly appreciated. Also my first time using the performance tool in Chrome so feel free to critique me there.
Thanks,
mac
2
u/[deleted] Mar 24 '18 edited Mar 24 '18
First time programmer here, just got started using python, lmk what you think of this:
Python 3.6
It works, but idk whether I can make it more efficient or something? I know this thread is already 12 days old, but anything you tell me will be a huge help!
Edit: oh yeah, the solution for 345678 is:
2
u/Vanskie Mar 25 '18
Python 3:
2
u/Limpskinz Mar 26 '18
C
Return value for A=345678
2
u/sha3bani Apr 06 '18
C++ with Bonus 1
2
u/algoll Apr 09 '18 edited Apr 09 '18
for A=345678 my output is equal to:
my code in C++ without bonuses:
2
u/[deleted] Apr 29 '18
Python 3, bonus 1
2
u/TheShortOneEli May 28 '18 edited May 28 '18
TI Basic
2
u/sfalkson Jun 06 '18
python. Having trouble with the bonuses
2
u/gabeace Jun 06 '18 edited Jun 06 '18
C#
Returns bonus 1 in 10 milliseconds. I tried running large primes through it, thinking it would choke having to iterate through, finding nothing, and I'd want to put in a check for prime first, but actually it's still pretty fast even on the 1 trillionth prime (29,996,224,275,833), returns in 85 milliseconds.
Edit: would love any hint about where to even start with bonus 2. I'm no mathlete.
2
u/lorge_bot Jul 02 '18 edited Jul 02 '18
Python 3.6 (no bonus)
1
u/bruce3434 Mar 12 '18
Nim
1234567891011returns2
u/Gprime5 Mar 12 '18 edited Mar 13 '18
Python 3.6
Timings:
Main challenge + bonus 1
Bonus 2
2
u/svgwrk Mar 12 '18
Rust. Assumes that the ideal value is
sqrt(n) + sqrt(n). Starts withn.sqrt().floor()and works down from there to get a result.1
u/nthai Mar 12 '18
Mathematica
Output
First number is runtime in seconds, second number is the answer. Couldn't get the bonus#1 under 1 second unless I use the built-in prime factorization (
FactorInteger[]) and use the method in bonus#2.1
u/skeeto -9 8 Mar 12 '18
C just testing each number up through the square root of the input. I almost considered keeping a list of primes but realized the challenge isn't about prime factorization.
1
u/_VictorTroska_ Mar 12 '18 edited Mar 12 '18
Go
Edit
much more efficient version
Edit 2
Tests
1
u/rabuf Mar 12 '18 edited Mar 12 '18
This does not work for the bonuses.
|isresidueand is normally used asM|Nwhich returnsRfrom the equationN = Q*M+RwhereQis an integer. We use⍨(commute) to swap the order of the two operands. We don't really need this, it just saves some parenthesis.Fends up being a list of factors of the number. Finally we find the sum of the factor with its pair and return the minimum of all of them.Applying it to several numbers at the same time:
¨meanseachsoMinSumis applied to each of those parameters. I'm new to APL so I'm still trying to figure out how to get this to correctly execute without the¨when given an array instead of a scalar as input.MinSum @ TryAPL I forgot that TryAPL let you send links to people to specific lines of code. This one will produce the function
MinSumand then you can try it out.1
u/chunes 1 2 Mar 12 '18
Factor with bonuses 1 and 2:
Output:
1
u/popillol Mar 12 '18
Go / Golang Playground Link. Identical to /u/VictorTroska but using the
bigpackage for bonus 1Output
1
u/auxyz Mar 12 '18 edited Mar 17 '18
Python 3
Going for clarity and testability over efficiency here. Bonus one is doable, I haven't tried bonus two yet.
1
u/TiZ_EX1 Mar 12 '18 edited Mar 12 '18
Crystal. As usual for me, it's a CLI program. Pass in your numbers as args. It will ignore things that are not uints.
It seems to go pretty fast.
1
u/bogdanators Mar 12 '18 edited Mar 12 '18
Python3.6 I'm still new to programming but here is my solution code to the challenge above. Let me know if you guys have any question, I will try and get to the challenges in a little bit when I get time.
1
u/LegendK95 Mar 12 '18 edited Mar 12 '18
Haskell with both bonuses
Solves bonus 2 in 1 second (without giving it the prime factors).
1
u/Chomatic Mar 12 '18
Scala
The parenthesis aren't pleasant, but otherwise this is concise brute force solution that runs in O(sqrt(n)).
Output
1
u/neel9010 Mar 12 '18 edited Mar 12 '18
c#
1
u/ff8c00 Mar 12 '18
JavaScript Gist with bonus 1
1
u/jnazario 2 0 Mar 12 '18 edited Mar 13 '18
FSharp, EDITED to support bonus 1, a less naive solution than before and now using BigInt values
1
u/InSs4444nE Mar 13 '18 edited Mar 13 '18
Java
with bonus 1, awful and readable
Output
1
u/OutputStream Mar 13 '18
Feedback always welcomed! Solves Bonus 1 as well.
Go/Golang:
1
u/Yodi007 Mar 13 '18 edited Mar 13 '18
Output:
Bonus 1 in Rust. This is my first solution and I would love some feedback on my code!
1
u/pheipl Mar 13 '18 edited Mar 13 '18
Java 8
I'm no mathematician, so I can't tell what the best solution would be, this is what I've tried:
result = sqrt(n) + sqrt(n)1andresult = 1 + nEdit: If I really cared about performance, I'd do a check for prime before anything else.
Edit 2:
done with:
1
u/BSISJ7 Mar 13 '18 edited Oct 03 '18
Java 8 with bonus 1
Bonus 2
Output:
1
u/Scroph 0 0 Mar 13 '18
It's been a while. C solution with the first bonus :
Output :
1
u/Rock_Crusher Mar 13 '18
C#
Solves for Bonus 1 in much less than 1 second. Probably could be cleaned up a bit.
Bonus 1 Output:
1
u/monkeyapplez Mar 13 '18
Python
First time posting so let me know what you think! (Includes Bonus 1):
Output:
1
u/hube19 Mar 13 '18 edited Mar 13 '18
Python 3, with optional bonus 1 and 2.
This is my first time posting - any comments or suggestions are very welcome, and apologies if my submission doesn't conform to standards in any way!
The following code runs on the following logic. First, though unproven here it is taken as fact that the minimal sum is always the one comprising of one factor closest to the square root of the number (we never have to check for greater than the square root).
Every number input has at least the sum of itself +1, so use that as the default solution. Now split into the following two cases:
(a) no prime factors given. In this case, initialise a 'check-to' variable that is the square root (rounded up) of the input number. Then, in descending order, check (by integer step) if it is a factor, and if so, calculate the required sum. If it is less than the default sum, then replace it with the new sum, and break, because by the foregoing theorem it is the minimal sum.
(b) prime factors given. In this case, we wish to find the factor closest to the square root of the number. This involves taking different combinations of the prime factorisation, so use itertools to facilitate finding all the proper subsets of the prime factorisation (for this I've very slightly altered code from https://stackoverflow.com/questions/374626/how-can-i-find-all-the-subsets-of-a-set-with-exactly-n-elements, not sure if that's allowed!). Then take the product of all these subsets and choose the one closest to the square root. Then find it's other factor and sum them!
Solutions:
For Optional Bonus 1:
For Optional Bonus 2:
1
u/InSs4444nE Mar 13 '18 edited Mar 13 '18
C
second post
works with bonus 1
any advice would be cool, i suck at C but i would love to get better
Output
1
u/labajtg1 Mar 13 '18
I am a beginner trying to understand what the hell all of this means.
1
u/Narutoninjaqiu Mar 14 '18
C++ VERSION 1 BONUS 1
OUTPUT
I thought about it before going to bed and realized a lot of things I could have optimized, and so...
VERSION 2 BONUS 1
OUTPUT
1
u/primaryobjects Mar 14 '18
R
Gist | Demo
Output
1
u/PhantomDot1 Mar 14 '18
C# with bonus 1
1
u/multimetr Mar 14 '18 edited Mar 14 '18
Typescript Bonus 1
Output for 1234567891011:
1
u/PM_ME_SFW_STUFF Mar 14 '18 edited Mar 15 '18
Java
I've been looking through this sub for a while and have tried a few challenges, but this is the first one I've been able to complete. It doesn't handle the challenges*, but at least its functional. I'm a junior in high school and this is my first year in Computer Science, so sorry if it looks a bit messy. Critiques are welcome!
Edit: *bonus challenges
1
u/ju5tr3dd1t Mar 15 '18
JAVA
1
u/ckafi Mar 15 '18
Rust:
I'm a bit late and just learning rust. This should be pretty fast, but I'm worried about the i64 -> f64 -> i64 casting.
1
u/sku11cracker Mar 15 '18
Java (beginner) without bonus
I am currently in my first year of university and have no formal prior knowledge of programming. Please critique my work so I may learn. Thanks
1
u/UnPracticedProgramer Mar 15 '18
JAVA
1
u/[deleted] Mar 16 '18
C#
}
1
u/Xeonfobia Mar 16 '18 edited Mar 16 '18
Lua 5.2
1
u/all_ofv Mar 16 '18
Lua 5.3
if A = 345678 B + C = 3491
1
u/mr_zeroinfinity Mar 16 '18 edited Mar 16 '18
My first submission, feedback's are appreciated. edit 1 : formatting edit 2: added bonus 1
outputs:
1
u/SuperRonJon Mar 16 '18
My C++ solution for the main part without bonuses
1
u/x1729 Mar 17 '18 edited Mar 17 '18
Perl 6
Output
1
u/Jesus__H__Dicks Mar 17 '18
Python 3.6
1
u/MasterSnipes Mar 18 '18
C++11:
Outputs:
1
u/MogranFerman Mar 18 '18
Python:
Is it as optimal as possible? (works with bonus 1 as well)
1
u/radzio1993 Mar 18 '18 edited Mar 18 '18
C# (WPF): Github int liczba=Convert.ToInt32(LiczbaTextBox.Text); int i = 1; int sum=liczba; do{ if (liczba%i==0) { int a = i; int b = liczba / i; int tmp = a + b; sum= (tmp < sum) ? tmp : sum; } i++; }while(i!=liczba); MessageBox.Show(Convert.ToString(sum));
1
u/spoonsnoop Mar 19 '18
Java
1
u/whatevernuke Mar 20 '18 edited Mar 21 '18
C
Solution:
Output:
1
u/[deleted] Mar 21 '18 edited Mar 21 '18
Python 3.6 Code:
Output:
Appreciate any feedback.
1
u/InspirationByMoney Mar 21 '18
Rust
There's probably a more "rusty" way to do it but I'm still learning.
1
u/rsupak0811 Mar 22 '18 edited Mar 22 '18
Python
1
u/darklypure52 Mar 22 '18 edited Mar 22 '18
Java
any advice would be helpful.
1
u/MartusNorwegicus Mar 23 '18
C++
1
u/mateuszs Mar 23 '18
C#
OUTPUT
1
u/[deleted] Mar 23 '18 edited Mar 24 '18
Swift
I've been trying to learn how to program pretty casually for the last year or two and have been struggling with it not clicking and just not knowing how to implement everything I'm learning. This is my first submission and I'm proud to see it works and I believe everything I've learned is finally starting to stick! :D
Any suggestions on how I can clean this up would be greatly appreciated!
Edit 1.1: Now can deal with prime numbers without dying.
1
u/dYYYb Mar 23 '18
Python 3.6
Just started learning Python today so any suggestions are greatly appreciated :)
CODE
INPUT
OUTPUT
1
u/[deleted] Mar 23 '18
Python 3.6 with Optional #1
Output Near instantaneous for Optional #1
1
u/PanPirat Mar 24 '18
Scala, simple brute force:
1
u/AthosBlade Mar 24 '18 edited Mar 24 '18
C++
`
include <iostream>
using namespace std;
int getSolution(int number);
int main(int argc, char** argv) { int number; cout << "Input your number\n"; cin >> number; if(number>999999){ cout<<"Nunber is too big.\nProgram will now exit.\n"; return 0; } int solution = getSolution(number); cout << "Solution is " << solution << ".\n";
}
int getSolution(int number){ int solution = number; for(int i = number;i>0;i--){ if(number%i==0){ int temp = number/i; int min = temp + i; if(min<solution) solution = min; } } return solution; } `
1
u/[deleted] Mar 25 '18
JAVA
Solution for 345678:
1
u/Gregman Mar 25 '18 edited Mar 30 '18
ELIXIR (bonus 1)
Just started learning, please comment.
1
u/prais3thesun Mar 25 '18
Java
I'm a beginner so feedback is appreciated
When input = 1234567891011 the output is this
1
u/TheWulfson Mar 26 '18
I did mine in Linqpad C#
This works with Bonus 1 aswell
1
u/Daredoom Mar 26 '18
1
u/zetashift Mar 26 '18
Using Nim
1
u/Gibby2 Mar 26 '18 edited May 24 '22
ER RO EUEIED
1
u/GinoTitan Mar 26 '18
Python 3 with both bonuses
1
u/[deleted] Mar 30 '18
rust
Solves bonus 1 in ~50ms
1
u/mwpfinance Mar 30 '18
Python 3.6, no bonus (I'm super rusty)
1
u/daviegravee Mar 31 '18
Python 3.5 Works with Bonus 1. I'm going to bed soon, if I have time tomorrow i'll and make this more efficient for Bonus 2. I would greatly appreciate feedback on my solution.
1
u/BlaDrzz Apr 01 '18 edited Apr 01 '18
Here's our solution in Clojure
And in Haskell...
1
u/Tetsumi- 1 0 Apr 01 '18 edited Apr 01 '18
Racket with bonus 1.
If N is a perfect square, the result is
(squareroot N) * 2. Otherwise, the program finds the closest divisor from the imperfect square root then returnsdivisor + (N / divisor).+/u/CompileBot racket
Input:
1
u/juanchi35 Apr 02 '18 edited Apr 02 '18
Batch
No bonuses because Batch only handles 32 bit integers.
1
u/deamus9 Apr 03 '18 edited Apr 03 '18
sql code: with bonus.....
1
u/ConnerDavis Apr 05 '18
Python 3.6.3
1
u/elpoir Apr 05 '18 edited Apr 06 '18
JAVA
1
u/taterr_salad Apr 06 '18
Python 3.6: No bonus, still learning a bit, feedback is appreciated!
1
u/randomseller Apr 06 '18
Python 3.6, noob here, took me the entire afternoon to solve this, any feedback, good or bad, is more than welcome.
1
u/smurko12 Apr 07 '18
Python 3.6 First ever submission here. Still pretty new to programming in general. Would appreciate any feedback.
1
u/y_angelov Apr 09 '18
Written in Scala
1
u/Zembeck Apr 10 '18
Python 3.6. First ever python script! It took me a while to figure out the mathematics side and I know I've probably done it a really inefficient way so any feedback would be great.
1
u/AshCo_0 Apr 11 '18
Javascript : Never posted on here before, but hope to make it a thing. Would love to know if there is anything I can do to make this more efficient.
1
u/zahid3160 Apr 11 '18
Javascript with bonus 1
1
u/skawid Apr 20 '18
Rust
1
u/GreySkiesPinkShoes Apr 22 '18
C99, no bonus.
1
u/oProtistant Apr 30 '18
Python 3, no bonus. I am a beginner in Python and coding in general. My friend and I worked through this one.
1
u/hqv1 Apr 30 '18
C# with Linq, no bonus. Enumerable.Range only works with ints so bonuses wouldn't work it.
1
u/Nokthar May 10 '18
Go Bonus 1, works in less than a second, no Bonus 2. Bit of a long solution, any feedback appreciated.
1
u/[deleted] May 27 '18
C
1
u/[deleted] Jun 02 '18
1
u/[deleted] Jun 06 '18 edited Jun 06 '18
Rust
Works for challenge 1, no idea how to do challenge 2. Got some left over syntax from mucking around with functions. Edit: ceil() would be more thorough than round().
1
u/borislavvv Jun 14 '18 edited Jun 14 '18
Python 3.6, no bonus .. for now.
print(int_complexity(12))
12, 7
Also prime numbers are calculated for now(sum = prime + 1)
1
u/SwimmingYeti Jun 15 '18
Java
New to programming, so advice and suggestions much appreciated :)
Code:
import java.util.*;
public class IntegerComplexity1 {
}
Input: 345678
Output: 3491
1
u/koalakraft Jun 26 '18 edited Jun 26 '18
R with Bonus 1
Edit1: Optimised Function at the Bottom. Just kept the old one for reference.
Edit2: Hit CTRL + Return too early. :|
Takes about 1.05 seconds for the Bonus 1 Input. Could maybe make it faster if i left out my time check.
Solution for Bonus 1
Edit1: Optimised Version is now able to handle the Bonus 1 Input in 0.99 secs.
1
u/TheTapp Jul 03 '18
In C: I'm still very new to this so any feedback is greatly appreciated! Bonus 1 solved in 0.03125 seconds apparently, however I'm starting to think my time keeping may be wrong compared other people's times.
Bonus 1 output:
1
u/Strosel Aug 06 '18
in Go with bonus 1:
Output:
Edit: Fixed the formatting
1
u/voliver97 Aug 16 '18
Python 3.6
Done bonus 1. Have been trying hard with 2 but had to give up.
1
u/[deleted] Feb 15 '22
Python
small_pair(12345)
1
u/tomekanco Mar 12 '18 edited Mar 13 '18
Java
Bonus 1 1.2ms