Advertisement
iAnonGuy

AnonGuy's Programming Challenge [#4] - Solution

Feb 7th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.80 KB | None | 0 0
  1. # Ruby
  2. print "\nInput #1 -- "
  3. inputA = gets.chomp
  4. print "\nInput #2 -- "
  5. inputB = gets.chomp
  6. if inputA.downcase.delete(' ').chars.sort == inputB.downcase.delete(' ').chars.sort
  7.     puts "\nOutput   -- \"#{inputA}\" can be formed using \"#{inputB}\"!"
  8. else
  9.     puts "\nOutput   -- \"#{inputA}\" cannot be formed using \"#{inputB}\"!"
  10. end
  11.  
  12. # PHP
  13. =begin
  14. <?php
  15. $a = htmlentities($_GET['a']);
  16. $b = htmlentities($_GET['b']);
  17.  
  18. $inputA = str_replace(" ", "", strtolower($a));
  19. $inputB = str_replace(" ", "", strtolower($b));
  20.  
  21. if(isset($a, $b))
  22. {if(count_chars($inputA, 1)===count_chars($inputB, 1)){echo "$a can be formed using $b.";}
  23.  else {echo "$a is can't be formed using $b.";}}
  24. ?>
  25. =end
  26.  
  27. # JavaScript
  28. =begin
  29. function check(inputA, inputB)
  30. {if (inputA.toLowerCase().replace(/[^a-z\d]/g,'').split('').sort().join('')===inputB.toLowerCase().replace(/[^a-z\d]/g,'').split('').sort().join('')){return '"'+inputA+'" can be formed using "'+inputB+'"';}
  31. else {return '"'+inputA+'" can\'t be formed using '+inputB+'"';}}
  32. userInputA = prompt("Input #1 ~");
  33. userInputB = prompt("Input #2 ~");
  34. document.write(check(userInputA, userInputB));
  35. =end
  36.  
  37. # Python (Tonmoy Ahmed Dhrubo's Solution)
  38. =begin
  39. input1 = raw_input('\n1st input >> ')
  40. input2 = raw_input('\n2nd input >> ')
  41.  
  42. string1 = input1.lower()
  43. string2 = input2.lower()
  44.  
  45. string1 = string1.replace(' ', '')
  46. string2 = string2.replace(' ', '')
  47.  
  48. list1 = sorted(list(string1))
  49. list2 = sorted(list(string2))
  50.  
  51. if list1 == list2:
  52.     print('\n[+] ((%s)) can be formed using ((%s))') % (input1, input2)
  53.     print('\nThanks for the challenge')
  54.     print('\nRegards , Tonmoy Ahmed Dhrubo')
  55. else:
  56.     print('\n[+] ((%s)) can NOT be formed using ((%s))') % (input1, input2)
  57.     print('\nThanks for the challenge')
  58.     print('\nRegards , Tonmoy Ahmed Dhrubo')
  59. =end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement