相关疑难解决方法(0)

Code Golf:浪潮

挑战

按字符计数的最短代码,用于从输入字符串生成波形.

通过提升(第1行)较高字符并使(第1行)降低较低字符来生成波.相等的字符保持在同一行(没有提升或降级).

输入仅由小写字符和数字组成,字母被认为高于数字.

测试用例:

Input:
    1234567890qwertyuiopasdfghjklzxcvbnm

Output:
                                 z
                                l x v n
                               k   c b m
                              j
                             h
                            g
                   y   p s f
                  t u o a d
               w r   i
            9 q e
           8 0
          7
         6
        5
       4
      3
     2
    1

Input:
    31415926535897932384626433832795028841971693993751058209749445923078164062862

Output:
                9 9   8 6 6
         9 6   8 7 3 3 4 2 4  8   9   88
    3 4 5 2 5 5     2       33 3 7 5 2  4 9   9 99 …
Run Code Online (Sandbox Code Playgroud)

language-agnostic code-golf rosetta-stone

41
推荐指数
11
解决办法
6203
查看次数

Code Golf: Seven Segments

The challenge

The shortest code by character count to generate seven segment display representation of a given hex number.

Input

Input is made out of digits [0-9] and hex characters in both lower and upper case [a-fA-F] only. There is no need to handle special cases.

Output

输出将是输入的七段表示,使用这些ASCII面:

  _       _   _       _   _   _   _   _   _       _       _   _  
 | |   |  _|  _| |_| |_  |_    | |_| |_| |_| |_  |    _| |_  |_  
 |_| …
Run Code Online (Sandbox Code Playgroud)

language-agnostic code-golf rosetta-stone

36
推荐指数
9
解决办法
4698
查看次数

PHP Morse代码转换器

我正在用PHP写一个基本的莫尔斯电码转换器,可以将一个字符串转换成莫尔斯电码。它使用关联数组,foreach循环和for循环。它起作用,除了出于某种原因,它在每个转换的字符之后输出与“ 0”等效的摩尔斯电码。我不知道0的来源。如果我从关联数组中删除0,就没有问题,但是我也希望能够转换数字。如果有人能够给我一些反馈,将不胜感激。

这是代码:

<?php
$string = "dog";
$string_lower = strtolower($string);
$assoc_array = array(
    "a"=>".-",
    "b"=>"-...", 
    "c"=>"-.-.", 
    "d"=>"-..", 
    "e"=>".", 
    "f"=>"..-.", 
    "g"=>"--.", 
    "h"=>"....", 
    "i"=>"..", 
    "j"=>".---", 
    "k"=>"-.-", 
    "l"=>".-..", 
    "m"=>"--", 
    "n"=>"-.", 
    "o"=>"---", 
    "p"=>".--.", 
    "q"=>"--.-", 
    "r"=>".-.", 
    "s"=>"...", 
    "t"=>"-", 
    "u"=>"..-", 
    "v"=>"...-", 
    "w"=>".--", 
    "x"=>"-..-", 
    "y"=>"-.--", 
    "z"=>"--..", 
    "0"=>"-----",
    "1"=>".----", 
    "2"=>"..---", 
    "3"=>"...--", 
    "4"=>"....-", 
    "5"=>".....", 
    "6"=>"-....", 
    "7"=>"--...", 
    "8"=>"---..", 
    "9"=>"----.",
    "."=>".-.-.-",
    ","=>"--..--",
    "?"=>"..--..",
    "/"=>"-..-.",
    " "=>" ");
    for($i=0;$i<strlen($string_lower);$i++){
        foreach($assoc_array as $letter => $code){
            if($letter == $string_lower[$i]){
                echo "$code<br/>";
            }
        }
    }
?>
Run Code Online (Sandbox Code Playgroud)

php arrays loops converter morse-code

5
推荐指数
1
解决办法
3241
查看次数