Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Let's see how good /prog/ really is

Name: Anonymous 2012-10-26 13:44

Can you find the smallest number that fulfills the following criteria?

1. It can only contain digits of 3, 5 and 7
2. The sum of the digits can be divided by 3, 5 and 7 without remainder
3. The number can be divided by 3, 5 and 7 without remainder

Name: Anonymous 2012-10-26 13:46

357,753,537

Name: Anonymous 2012-10-26 13:50

\sum_{n=1}^{N} a_n = S
S % 3 = S % 5 = S % 7 = 0

is it jewfinity?

Name: Anonymous 2012-10-26 15:06

Assuming something stupid accidentally gave me this upper bound:

http://www.wolframalpha.com/input/?i=555555555555555555555555555555555555555555

Name: Anonymous 2012-10-26 15:26

I think 555555555555555555555555555555555555555555 is the smallest number that fulfils your homework's criteria, >>1-san.

Name: Anonymous 2012-10-26 16:56

>>3
die in a fire, cretin

Name: >>4 2012-10-26 17:31

>>5
That's nowhere near the answer, I bet. This does sound like it's real easy to bruteforce, though.

Some ideas:

- The last digit is a 5.
- The number is an odd multiple of 105.
- The number's digit sum is a multiple of 105.

Name: Anonymous 2012-10-26 18:10

product([], 1).
product([H|T], X) :- product(T, Y), X is H * Y.

divmod(N, N, Q, 0, A) :- succ(A, Q).
divmod(N, D, Q, N, Q) :- D > N.
divmod(N, D, Q, R, A) :- D < N, plus(T1, D, N), succ(A, A2), divmod(T1, D, Q, R, A2).

divmod(N, D, Q, R) :- divmod(N, D, Q, R, 0).

times(X, 1, P, R) :- plus(X, R, P), !.
times(X, Y, P, R) :- succ(T, Y), plus(X, R, A), times(X, T, P, A).

times(X, Y, P) :- nonnegative(X), nonnegative(Y), times(X, Y, P, 0).

nonnegative(0).
nonnegative(N) :-
        number(N) -> N > 0;
        nonnegative(M), N is M + 1.

power_of_ten(N, R) :- R is 10 ** N.

?- length(Digits, Length), Length > 0, subset(Digits, [3,5,7]), sum_list(Digits, Sum), divmod(Sum, 3, _, 0), divmod(Sum, 5, _, 0), divmod(Sum, 7, _, 0), reverse(Digits, Reversed), succ(X, Length), numlist(0, X, Xs), maplist(power_of_ten, Xs, PowersOfTen), maplist(times, Reversed, PowersOfTen, Ys), sum_list(Ys, N), divmod(N, 3, _, 0), divmod(N, 5, _, 0), divmod(N, 7, _, 0).

Name: Anonymous 2012-10-26 18:13

Smallest I've found so far: 33,577,577,777,777,775

Name: Anonymous 2012-10-26 18:15

>>9
Code I'm using to manually test: (yes, sepples)

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

const int arr[3] = {3, 5, 7};
const int LCM = 105;

int sumDigits(const vector<int> &v)
{
    int r = 0;
    for(int i = 0; i < (int)v.size(); ++i)
        r += v.at(i);

    return r;
}

void toVector(const string &s, vector<int> &v)
{
    for(int i = 0; i < (int)s.size(); ++i)
        v[i] = (int)(s.at(i) - '0');

    return;
}

long long vectorToNum(const vector<int> &v)
{
    long long r = 0;

    for(int i = (int)v.size() - 1, k = 0; i >= 0; --i, ++k)
        r += (long long)( (int)v.at(k) * pow(10.0, i) );

    return r;
}

bool validDigit(const int &n)
{
    return ( (n==arr[0]) || (n==arr[1]) || (n==arr[2]) );
}

bool validNumber(const vector<int> &v)
{
    int i, sum;
    long long n;

    //check #1
    for(i = 0; i < (int)v.size(); ++i)
        if( !validDigit((int)v.at(i)) ) return false;

    //check #2
    n = vectorToNum(v);
    cout << "n: " << n << endl;
    for(i = 0; i < 3; ++i)
    {
        if( (n % arr[i] != 0) ) return false;
    }
   
    //check #3
    sum = sumDigits(v);
    if( sum != LCM ) return false;

    return true;
}

int main()
{
    // smallest so far = 33577577777777775

    string ts = "33577577777777775";
    vector <int> tv ((int)ts.size());
    toVector(ts, tv);

    cout << "Number: " << ts << endl <<
        "Valid: " << validNumber(tv) << endl << endl;

    return 0;
}

Name: Anonymous 2012-10-26 18:23

I think this can be solved with a system of equations.

Let x = number of 3 digits
Let y = number of 5 digits
Let z = number of 7 digits

For mod 3: 2y + z = 0
For mod 5: 3x + 2z = 0
For mod 7: 3x + 5y = 0

and then you could probably minimize each variable, starting with z? Not sure though... I've yet to take Linear Algebra.

Name: Anonymous 2012-10-26 19:00

Stop helping OP with his homework.

Name: Anonymous 2012-10-26 19:21

>>12
what kind of school assigns a complex math riddle as HW?

Name: Anonymous 2012-10-26 19:32

>>7
- The last digit is a 5.
- The number is an odd multiple of 105.
- The number's digit sum is a multiple of 105.
No fucking shit.

Name: Anonymous 2012-10-26 19:33

>>13
Many, actually.

Name: Anonymous 2012-10-26 19:55

>>14
Yes shit.

Name: Anonymous 2012-10-26 20:01

starting from 1...no way to fuck this one up


$test_number = 1;
$winner_found = false;
$seconds = 130;

do {
   
    $digit_test = true;
    $sum_test = true;
    $division_test = true;
   
    $char_array = str_split($test_number);
   
    foreach($char_array as $value) {
        if($value != 3 && $value != 5 && $value != 7) {
            $digit_test = false;
            break;
        }
    }
   
    if($digit_test == true) {
       
        $sum = array_sum($char_array);
        if($sum % 3 != 0 || $sum % 5 != 0 || $sum % 7 != 0 ) {
            $sum_test = false;
        }
       
        if($sum_test == true) {
            if($test_number % 3 != 0 || $test_number % 5 != 0 || $test_number % 7 != 0 ) {
                $division_test = false;
            }
        }
    }
   
   
    if($digit_test == true && $sum_test == true && $division_test == true) {
        $winner_found = true;
    } else {
        $test_number++;
        set_time_limit($seconds);
    }
    echo $test_number . "\r\n";

} while($winner_found == false);

echo "winner:" . $test_number;

Name: Anonymous 2012-10-26 20:18

Brute force solution. The answer is indeed 33577577777777775.

#include <stdio.h>

/* this is a horrible coding practice. never do this */
static unsigned long long digit_sum = 0;

/* generates 357-digits-only numbers in ascending order */
unsigned long long next(unsigned long long n) {
    unsigned long long p = 10;
    while (1) {
        switch (n / p % 10) {
            case 3: digit_sum += 2; return (n + 2 * p);
            case 5: digit_sum += 2; return (n + 2 * p);
            case 7: digit_sum -= 4; n -= 4 * p;
        }
        p *= 10;
        if (p > n) { digit_sum += 3; return (n + 3 * p); }
    }
}

int main(void) {
    /* start where the digit sum is first 105 */
    /* this number was brute forced earlier */
    unsigned long long x = 33377777777777775;
    digit_sum = 105;
   
    while (1) {
        if (digit_sum == 105 && x % 105 == 0) {
            printf("%llu %llu\n", x, digit_sum);
            break;
        }
        x = next(x);
    }
    return 0;
}

Name: Anonymous 2012-10-26 20:23

>>17
PHP

Name: Anonymous 2012-10-26 20:33

>>17
that just crashed my web server, asshole...

now my wordpress and entire cloud is down

Name: Anonymous 2012-10-26 20:46

>>20
Cloud quality!

Name: Anonymous 2012-10-26 22:26

33,577,577,777,777,775 is the answer.

It is not humanly possible to get a value smaller than that.

Name: Anonymous 2012-10-26 22:37

>>22
-33577577777777775

Name: Anonymous 2012-10-26 22:56

>>23
XD

Name: Anonymous 2012-10-27 0:39

>>23
It can only contain digits of 3, 5 and 7

Name: Anonymous 2012-10-27 0:57

>>25
negative sign
digit

Name: Anonymous 2012-10-27 1:26

>>26
a basket can only contain apples... red and green
what about a grape- herp! it's not an apple- derp!

Name: Anonymous 2012-10-27 2:12

I suck at this my code won't work.
Anyone have any tips?


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int test_one(unsigned long long x);
int test_two(unsigned long long x);
int test_three(unsigned long long x);

int main() {
  unsigned long long i = (unsigned long long) 33577577777777775.0;

  do {
    if(test_one(i)) {
      i++;
      continue;
    }

    if(test_two(i)) {
      i++;
      continue;
    }

    if(test_three(i)) {
      i++;
      continue;
    }

    break;
  } while(1);

 printf("%lld\n", i);
 
}

int test_one(unsigned long long x) {
  do {
    switch(x % 10) {
      case 3:
      case 5:
      case 7:
        break;

      default:
        return(1);
    }
  } while(x/=10 > 1);

  return(0);
}

int test_two(unsigned long long x) {
  int sum = 0;
 
  do {
    sum += x % 10;
  } while(x/=10 > 1);

  return((sum%3) + (sum%5) + (sum%7));
}

int test_three(unsigned long long x) {
  return((x%3) + (x%5) + (x%7));
}

Name: Anonymous 2012-10-27 2:33

>>28
- why is the long a decimal?
- your 3 conditionals in the first do-while do the exact same goddamn thing
- the logic of test_one is all kinds of fucked up

Name: Anonymous 2012-10-27 2:41

>>29
Compiler wouldn't let me enter it without the decimal because it was too big. Had to cast it. Can you elaborate at all on the messed up logic?

Name: Anonymous 2012-10-27 4:02

>>30
Try
unsigned long long int i = 33577577777777775ULL;
instead newfriend.

Also use "%llu" instead of "%lld" since the former is for unsigned and the latter is for signed numbers.

Name: Anonymous 2012-10-27 4:05

>>10
SLOW AS FUCK

try javascript on for size

Name: Anonymous 2012-10-27 9:56

import Data.Digits

d = \z -> map ($z) (map (\x y -> mod y x == 0) [3,5,7])
f = and . map (`elem` [3,5,7]) . digits 10
g = and . d . sum . digits 10

r = head . filter (\x -> f x && g x) $ [105,315..]

main = print r

Name: Anonymous 2012-10-27 17:05

>>33
What's the answer?

Name: Anonymous 2012-10-27 17:11

>>34
Timeout.

Name: Anonymous 2012-10-27 17:53

:D

Name: Anonymous 2012-10-27 19:31

The real challenge would be finding the smallest prime that satisfies those three conditions.

Name: Anonymous 2012-10-27 19:36

>>37
how could a prime number be divisible 3, 5 or 7...

Name: Anonymous 2012-10-27 19:36

>>37
hurrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

Name: Anonymous 2012-10-27 19:43

>>38
that's why it's so hard lol

>>39
 rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrruh

Name: Anonymous 2012-10-27 20:08

>>37
>>40
challenge implies that it's possible

Name: Anonymous 2012-10-27 22:55

>>40
Nice backpedaling, not even joking.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List