TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-19-2009, 02:56 PM   #21 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

Cant use echo :)
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
Old 08-19-2009, 03:13 PM   #22 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Thanks ioan1k, I've changed it to use printf... which feels silly because there's not much brain involved in finding an alternative to echo/print.
Salathe is offline  
Reply With Quote
Old 08-19-2009, 03:19 PM   #23 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

I can't believe implode escaped me! Good one Salathe.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-19-2009, 03:24 PM   #24 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

My first thought went to array_map just like yours, so had to think of an alternative and implode was it.
Salathe is offline  
Reply With Quote
Old 08-19-2009, 04:01 PM   #25 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default Ean 13

Challege 6 (EAN 13)

This was my first challenge in school.I have completed this challenge in 2 hours. Because I had no idea of VB.net
So here it is.
Quote:
Step One: From the right to left, start with odd position, assign the odd/even position to each digit.

101742256780.
( the odd numbers are 0
Step Two: Sum all digits in odd position and multiply the result by 3.

Step Three: Sum all digits in even position. (1+1+4+2+6+8)=22

Step Four: Sum the results of step three and four: 63+22=85

Step Five: Divide the result of step four by 10. The check digit is the number which adds the remainder to 10. In our case, divide 85 by 10 we get the remainder 5. The check digit then is the result of 10-5=5.
Example: 101742256780
step 2: (0+7+2+5+7+0)*3=63
step 3: (1+1+4+2+6+8)=22
step 4: 63+22=85
step 5:
85 by 10 we get the remainder 5. The check digit then is the result of 10-5=5.
hello-world is offline  
Reply With Quote
Old 08-19-2009, 04:25 PM   #26 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

php Code:
$number = 101742256780;

// STEP 1
$split = preg_split('//', $number, -1, PREG_SPLIT_NO_EMPTY);
$a = 0;
$even = array();
$odd = array();
foreach ($split as $k => $v) {
    if ($a % 2) {
        $odd[] = (int) $v;
    } else {
        $even[] = (int)  $v;
    }
    $a++;
}

// STEP 2
$oddsum = 0;
foreach ($odd as $k => $v) {
    $oddsum += $v;
}
$oddsum = $oddsum * 3;

// STEP 3
$evensum = 0;
foreach ($even as $k => $v) {
    $evensum += $v;
}

// STEP 4
$sumall = ($evensum + $oddsum) / 10;
$final = $sumall - (substr($sumall, strpos($sumall, '.') + 1, 1));
echo 'Check Digit : ' . $final;

Hows that
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
Old 08-19-2009, 06:43 PM   #27 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

Quote:
Originally Posted by ioan1k View Post

Hows that
I am sorry. It is not about odd/even numbers. It is about odd/even postions.

From the right to left, start with odd position, assign the odd/even position to each digit.

Lets take this number 101742256780 as an example.

From right to left:
101742256780
The first odd position 0 , the second 7 , the third 5 and so on.
Here again this numbers which are in [] are odds.
1[0]1[7]4[2]2[5]6[7]8[0].


Step Two: Sum all digits in odd position (not odd numbers)and multiply the result by 3.

Step Three: Sum all digits in even position. (1+1+4+2+6+8)=22

Step Four: Sum the results of step three and four: 63+22=85

Step Five: Divide the result of step four by 10. The check digit is the number which adds the remainder to 10. In our case, divide 85 by 10 we get the remainder 5. The check digit then is the result of 10-5=5.
hello-world is offline  
Reply With Quote
Old 08-19-2009, 06:50 PM   #28 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

Quote:
Originally Posted by hello-world View Post
I am sorry. It is not about odd/even numbers. It is about odd/even postions.

From the right to left, start with odd position, assign the odd/even position to each digit.

Lets take this number 101742256780 as an example.

From right to left:
101742256780
The first odd position 0 , the second 7 , the third 5 and so on.
Here again this numbers which are in [] are odds.
1[0]1[7]4[2]2[5]6[7]8[0].


Step Two: Sum all digits in odd position (not odd numbers)and multiply the result by 3.

Step Three: Sum all digits in even position. (1+1+4+2+6+8)=22

Step Four: Sum the results of step three and four: 63+22=85

Step Five: Divide the result of step four by 10. The check digit is the number which adds the remainder to 10. In our case, divide 85 by 10 we get the remainder 5. The check digit then is the result of 10-5=5.
This is what I did
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
Old 08-19-2009, 09:02 PM   #29 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default


SOLVED

That was the best.

only the last step.

It is 85 /10 the remainder will be 5 . And 10 -5 is 5

next Challenge ???
hello-world is offline  
Reply With Quote
Old 08-19-2009, 09:07 PM   #30 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Thought to post it again as it's hard to see on my solution to another challenge post..

Challenge 5 (Salathe: added challenge number so we can keep track))

Construct your a looping method to mimic for using only variables inside the scope of the function ( no global keyword )

( I don't expect the break keyword to be respected, that would be a slight more difficult )
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-19-2009, 10:08 PM   #31 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Maybe I'm just tired but earlier today the challenge 5 description didn't make any sense, and now it still doesn't. Would you mind rephrasing it and/or correcting the broken English, Enfernikus?

Last edited by Salathe : 08-19-2009 at 10:50 PM.
Salathe is offline  
Reply With Quote
Old 08-19-2009, 11:33 PM   #32 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
Maybe I'm just tired but earlier today the challenge 5 description didn't make any sense, and now it still doesn't. Would you mind rephrasing it and/or correcting the broken English, Enfernikus?
Certainly, sorry for the misunderstanding. Essentially the task is to mimic the for loop

php Code:
for( $i = 0; $i < 10; ++$i )
{
   //What ever code you want here
}

WITHOUT using any other loops or global variables.

P.S. Sorry if my English has it's mistakes, it's not my native tongue.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-20-2009, 01:30 AM   #33 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Would this work?

PHP Code:
<?php

function myloop($x=0)
{
  if(
$x 10)
  {
    echo 
$x;
    
$x++;
    
myloop($x);
  }
}

myloop();
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 08-20-2009, 01:49 AM   #34 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
Would this work?

PHP Code:
<?php

function myloop($x=0)
{
  if(
$x 10)
  {
    echo 
$x;
    
$x++;
    
myloop($x);
  }
}

myloop();

Nay, I have the solution I wrote up on my work computer at the office I'll post it, I was looking for a more complete and versatile answer. But I suppose that will do the trick as well for something simplistic.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-21-2009, 01:59 PM   #35 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

For the purpose of wanting to see this go on I'll just post the reply to my own challenge and say we move on to one that's less convoluted; suppose I can charge up my English to the confusion hah.

Use:
php Code:
$d = array('foo', 'rootof', 'doaine', 'fofid');
Loop($d, 0, 10, function(&$value, &$i){
    if( $i == 0 )
        $value = 'This is cool';
       
    if( $i == 3 )
        $value = 'This is the last element?';
});

print_r($d);

Function:
php Code:
function Loop( Array &$data, $from, $to, Closure $callback)
{
    static $count;
    if( $count == 0 )
    {
        $count = $from;
        $callback($data[$count], $count);
        ++$count;
        Loop($data, $from, $to, $callback);
    }
   
    if( $count < $to && array_key_exists($count, $data))
    {
        $callback($data[$count], $count);
        ++$count;
        Loop($data, $from, $to, $callback);
    }
}
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-21-2009, 02:31 PM   #36 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Challenge 7

Let me open by saying, I've no idea if this one will be super-easy or impossible. The hint in the code should provide a useful starting point. OK on with the challenge.

Given the mystical code below, implement the function challenge7 so as to output the encoded, hidden message. Only the insides of the function (denoted by the "your code here" comment) can be modified, no other parts of the script. The resulting message will be 22 characters in length, containing only valid ASCII characters and will constitute a short, plain-English sentence like one might post in this forum.

PHP Code:
<?php

function challenge7($message) {
    
// Your code here
}

ob_start('challenge7'); 
// Hint: Base 64
echo '
  ============
  US 06ID cgcn
  R hcnl5bn Vw
  IGdu cm8 gVg
  ============
'
;
ob_end_flush();
Salathe is offline  
Reply With Quote
Old 08-25-2009, 02:27 PM   #37 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Are you sure you encoded it right? It comes out as gibberish when converted to ascii or anything else.
__________________

Village Idiot is offline  
Reply With Quote
Old 08-25-2009, 10:52 PM   #38 (permalink)
The Wanderer
 
aSAP's Avatar
 
Join Date: Sep 2007
Posts: 7
Thanks: 0
aSAP is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
Are you sure you encoded it right? It comes out as gibberish when converted to ascii or anything else.
Same with my efforts but I am no expert on decoding.

PHP Code:
<?php

function challenge7($message) {
    
$encodedMsg '
  ============
  US 06ID cgcn
  R hcnl5bn Vw
  IGdu cm8 gVg
  ============
'
;
  return (
str_replace($encodedMsgbase64_decode($encodedMsg), $message));
}
ob_start('challenge7'); 
// Hint: Base 64
echo '
  ============
  US 06ID cgcn
  R hcnl5bn Vw
  IGdu cm8 gVg
  ============
'
;
ob_end_flush(); 

?>
Outputs:
Code:
Q-: 7 rtaryynup gnro V
I also tried a bunch of different alterations of the encoded string. Any more hints you can give?
__________________
aSAP is offline  
Reply With Quote
Old 08-26-2009, 11:19 AM   #39 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

I like scrambled eggs because they are so deliciouse and they make me faint.

You asked for a hint,
enjoy ;)

-CF
codefreek is offline  
Reply With Quote
Old 09-28-2009, 06:16 PM   #40 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

Everyone give up on posting a challenge?

Here is a new one ...

Decrypt the following string

Code:
dc:f5:16:77:f2:b6:99:7b
:e4:fc:88:e2:c0:80:44:e8
:6d:26:3e:b5:d2:8e:1f:f5
:3e:f5:44:cf:6a:bd:f0:9e
:44:d0:6a:a0:24:3e:f4:d7
Hint ... the result is 32 bytes long

This is composed of a encrypting Hybrid algorithm using various encryption methods, I doubt that this is crackable (but that is the challenge)

Challenge Level: Advanced
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Oriented Programming DizzyD General 2 02-25-2009 03:43 AM
how many programming languages do you know fluently? sarmenhb General 12 12-10-2008 06:26 AM
If a programming language was a boat… Wildhoney The Lounge 9 04-05-2008 07:24 AM
The speed of programming Devels General 1 02-01-2008 10:56 PM
12 common programming mistakes to avoid sunilbhatia79 General 0 11-16-2007 05:59 PM


All times are GMT. The time now is 10:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design