Latest Articles
 by awuehr on 11-10-2008 in Tips & Tricks by Village Idiot on 11-04-2008 in Classes & Objects by codefreek on 10-23-2008 in Basic by wiifanatic on 09-12-2008 in Security & Permissions by drewbee on 07-03-2008 in Tips & Tricks
 IRC Channel
 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
 08-19-2009, 02:56 PM #21 (permalink) The Contributor     Join Date: Mar 2009 Location: US Posts: 76 Thanks: 0 Cant use echo :) __________________ My Portfolio - Work - Need freelance Work? I've been developing 5 years now, and I learn something new everyday
 08-19-2009, 03:13 PM #22 (permalink) Moderateur          Join Date: Apr 2007 Posts: 1,393 Thanks: 5 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.
 08-19-2009, 03:19 PM #23 (permalink) The Addict     Join Date: Jun 2008 Posts: 335 Thanks: 2 I can't believe implode escaped me! Good one Salathe. __________________ My Blog
 08-19-2009, 03:24 PM #24 (permalink) Moderateur          Join Date: Apr 2007 Posts: 1,393 Thanks: 5 My first thought went to array_map just like yours, so had to think of an alternative and implode was it.
The Contributor

Join Date: Feb 2009
Posts: 73
Thanks: 30
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.

 08-19-2009, 04:25 PM #26 (permalink) The Contributor     Join Date: Mar 2009 Location: US Posts: 76 Thanks: 0 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
The Contributor

Join Date: Feb 2009
Posts: 73
Thanks: 30

Quote:
 Originally Posted by ioan1k 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.

The Contributor

Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0

Quote:
 Originally Posted by hello-world 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

 08-19-2009, 09:02 PM #29 (permalink) The Contributor     Join Date: Feb 2009 Posts: 73 Thanks: 30 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 ???
 08-19-2009, 09:07 PM #30 (permalink) The Addict     Join Date: Jun 2008 Posts: 335 Thanks: 2 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
 08-19-2009, 10:08 PM #31 (permalink) Moderateur          Join Date: Apr 2007 Posts: 1,393 Thanks: 5 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.

Join Date: Jun 2008
Posts: 335
Thanks: 2

Quote:
 Originally Posted by Salathe 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

 08-20-2009, 01:30 AM #33 (permalink) how quixotic are you?     Join Date: Dec 2007 Location: Lapeer, MI Posts: 445 Thanks: 37 Would this work? PHP Code: ``` http://www.dingocode.com My Website > http://www.evanbot.com

Join Date: Jun 2008
Posts: 335
Thanks: 2

Quote:
 Originally Posted by ETbyrne Would this work? PHP Code: ```

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

 08-21-2009, 01:59 PM #35 (permalink) The Addict     Join Date: Jun 2008 Posts: 335 Thanks: 2 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
 08-21-2009, 02:31 PM #36 (permalink) Moderateur          Join Date: Apr 2007 Posts: 1,393 Thanks: 5 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: ```
 08-25-2009, 02:27 PM #37 (permalink) Wizard       Join Date: Sep 2007 Posts: 1,299 Thanks: 17 Are you sure you encoded it right? It comes out as gibberish when converted to ascii or anything else. __________________
The Wanderer

Join Date: Sep 2007
Posts: 7
Thanks: 0

Quote:
 Originally Posted by Village Idiot 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(\$encodedMsg, base64_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?
__________________

 08-26-2009, 11:19 AM #39 (permalink) Super Moderator       Join Date: Sep 2007 Location: Near you. Posts: 791 Thanks: 241 I like scrambled eggs because they are so deliciouse and they make me faint. You asked for a hint, enjoy ;) -CF __________________ Codefreek's - News Letter, Tech, & some random ramblings
 09-28-2009, 06:16 PM #40 (permalink) The Contributor     Join Date: Mar 2009 Location: US Posts: 76 Thanks: 0 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

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

 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 OffTrackbacks 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 07:34 PM.