vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Community Lounge (https://vborg.vbsupport.ru/forumdisplay.php?f=13)
-   -   This see who the smart ones are (https://vborg.vbsupport.ru/showthread.php?t=285492)

ForceHSS 07-13-2012 04:01 AM

This see who the smart ones are
 
Question: Given an unsorted array of integers, find any 3 numbers that will add up to 100. For example, if the array has -77, 55, 22, 0, 2, and 155, one answer would be -77, 22, and 155.

ForceHSS 07-15-2012 04:23 PM

Looks like no smart people here

Paul M 07-15-2012 04:43 PM

The smart ones avoided wasting their time on something they have no need of. ;)

BirdOPrey5 07-15-2012 05:12 PM

Step 1: Randomly pick 3 numbers from the array
Step 2: Do they add to 100?
If Yes, DONE.
If No, go to step 1.

What do I win?

ForceHSS 07-16-2012 03:36 AM

Quote:

Originally Posted by BirdOPrey5 (Post 2348380)
Step 1: Randomly pick 3 numbers from the array
Step 2: Do they add to 100?
If Yes, DONE.
If No, go to step 1.

What do I win?

I still don't see your answer. You have just given a question and answered yourself

BirdOPrey5 07-16-2012 09:38 AM

I gave the answer is pseudo-code. You didn't specify it needed to be in particular language. An algorithm is generally acceptable in computer science as anyone with a basic understanding of a language can easily convert it.

Azhrialilu 07-16-2012 10:27 AM

It involves numbers... I generally avoid anything involving numbers. Words are my thing. I can barely add up using a calculator :D

ForumsMods 07-17-2012 01:38 AM

It reminds me of college exercises and Facebook Hacker Cup.
PHP Code:

<?php

$array 
= array(-77552202155);
sort($array);

$i $j $k 0;
$number 100;
$found false;

foreach(
$array AS $i => $value)
{
    
$j $i 1;
    
$k count($array) - 1;

    while (
$j $k)
    {
        
$sum $array[$i] + $array[$j] + $array[$k];

        if (
$sum $number)
        {
            
$k--;
        }
        else if (
$sum $number)
        {
            
$j++;
        }
        else
        {
            
$found true;
            break 
2;
        }
    }
}

if (
$found)
{
    echo 
"It is possible. The numbers are: " $array[$i] . ", " $array[$j] . ", " $array[$k];
}
else
{
    echo 
"It is not possible.";
}


Shazz 07-17-2012 02:01 AM

Is it a homework question? :p

ForceHSS 07-18-2012 12:40 AM

Quote:

Originally Posted by Shazz (Post 2348824)
Is it a homework question? :p

It is for a job with very good pay. Was just seeing if anyone could work it out but have already been pmed with the correct answer and am now it talks with the member


All times are GMT. The time now is 08:43 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04869 seconds
  • Memory Usage 1,742KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete