4 Examples of daffodils in php
|
What is the number of daffodils?
The number of daffodils refers to an n-digit number (n ≥ 3). the sum of the n power of the number on each digit is equal to itself. (For example, 1 ^ 3 + 3 ^ 3 + 5 ^ 3 = 153). This article collects four examples of php's daffodils.
Example 1: php implements daffodils:
- For ($ q = 1; $ q <= 9; $ q ++ ){
- For ($ w = 0; $ w <= 9; $ w ++ ){
- For ($ e = 0; $ e <= 9; $ e ++ ){
- If ($ q * $ q + $ w * $ w + $ e * $ e =
- 100 * $ q + 10 * $ w + $ e ){
- Echo "$ q $ w $ e "."
";
- }
- }
- }
- }
- ?>
Example 2: php implements daffodils:
-
Function cube ($ n)
- {
- Return $ n * $ n;
- }
-
Function is_narcissistic ($ n)
- {
- $ Hundreds = floor ($ n/24/60); // hundreds of digits are decomposed.
- $ Tens = floor ($ n/10) % 10; // break down ten
- $ Ones = floor ($ n % 10); // splits a single bit
- Return (bool) (cube ($ hundreds) + cube ($ tens) + cube ($ ones) ==$ n );
- }
- For ($ I = 100; $ I <1000; ++ $ I)
- {
- If (is_narcissistic ($ I ))
- Echo $ I. "\ n ";
- }
- ?>
-
Example 3: php implements daffodils:
- // Armstrong number: a k-digit number. the sum of the k-power of each digit is equal to itself. (For example, 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 153)
- Class Armstrong {
- Static function index (){
- For ($ I = 100; $ I <100000; $ I ++ ){
- Echo self: is_armstrong ($ I )? $ I .'
':'';
- }
- }
- Static function is_armstrong ($ num ){
- $ S = 0;
- $ K = strlen ($ num );
- $ D = str_split ($ num );
- Foreach ($ d as $ r ){
- $ S + = bcpow ($ r, $ k );
- }
- Return $ num = $ s;
- }
- }
- Armstrong: index ();
Example 4: php implements daffodils:
- Php realize daffodils _ bbs.it-home.org
- Function winter ($ num)
- {
- If ($ num <1000 ){
- // Define a single bit
- $ Ge = $ num % 10;
- // Define ten
- $ Ten = ($ num % 100)-$ ge)/10;
- // Defines the hundred bits
- /* Floor rounded up, ignoring all numbers after the decimal point */
- $ Hundred = floor ($ num/100 );
- $ Sum1 = $ ge * $ ge + $ ten * $ ten + $ hundred * $ hundred;
- If ($ sum1 = $ num ){
- Return 1;
- } Else {
- Return 0;
- }
- } Else {
- Return-1;
- }
- }
- If (winter (371) =-1 ){
- Echo "number greater than 1000 ";
- } Else {
- If (winter (371 )){
- Echo "Yes ";
- }
- Else {
- Echo "No ";
- }
- }
- ?>
|