Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. import UIKit
  2.  
  3. var str = "Hello, playground"
  4.  
  5. var aString = "1";
  6. var anInt = 1;
  7. var aFloat = 1.001;
  8.  
  9. let constString: String = "2";
  10. let constInt: Int = 2;
  11. let constFloat: Float = 2.002;
  12.  
  13. let constStringConc1: String = "\(aString) \(constString) \(aFloat)";
  14. let constStringConc2: String = aString + " " + constString + " " + String( aFloat );
  15.  
  16. var array = ["normal array"];
  17. var associationDictionary = [Int]();
  18.  
  19. array.append("second argument");
  20. associationDictionary.append(3);
  21.  
  22. var lottoRes = [String: [Int]]();
  23. lottoRes["29-11-14"] = [4, 5, 21, 30, 31, 49];
  24. lottoRes["27-11-14"] = [5, 8, 10, 19, 23, 40];
  25.  
  26. var associationDictionary2 = [Character: Int]();
  27. associationDictionary2[Character("a")] = 1;
  28. associationDictionary2["b"] = 2;
  29. associationDictionary2["c"] = 3;
  30.  
  31. var przes: Int = 65;
  32. var associationDictionary3 = [Character: Int]();
  33.  
  34. for i in 0...25 {
  35. associationDictionary3[Character(UnicodeScalar(UInt8(i+przes)))] = i;
  36. }
  37.  
  38. print(associationDictionary3);
  39.  
  40. for (date, numbers) in lottoRes {
  41. print("Losowanie dnia \(date):");
  42. for number in numbers {
  43. print("- \(number)");
  44. }
  45. }
  46.  
  47. func NWD(_ l1: Int, _ l2: Int) -> Int {
  48. let mod = l1 % l2;
  49. if( mod != 0 ) {
  50. return NWD(l2, mod);
  51. } else {
  52. return l2;
  53. }
  54. }
  55.  
  56. let nwd1 = NWD(1, 2);
  57. let nwd2 = NWD(10, 5);
  58.  
  59. func returnKrotka(_ l1: Int, _ l2: Int) -> (Int, Int, Int) {
  60. let nwd = NWD(l1, l2);
  61. return (nwd, l1/nwd, l2/nwd);
  62. }
  63.  
  64. let krotka1 = returnKrotka(1, 2);
  65. let krotka2 = returnKrotka(10, 5);
  66. let krotka3 = returnKrotka(100, 50);
  67.  
  68. print( "\(returnKrotka(3, 9).0) \(returnKrotka(3, 9).1) \(returnKrotka(3, 9).2) " );
  69. print( "\(krotka3.0) \(krotka3.1) \(krotka3.2) " );
  70.  
  71. func gaderyPoluki(_ inputChar: Character) -> Character {
  72. switch inputChar {
  73. case Character("G"):
  74. return Character("A");
  75. case Character("D"):
  76. return Character("E");
  77. case Character("R"):
  78. return Character("Y");
  79. case Character("P"):
  80. return Character("O");
  81. case Character("L"):
  82. return Character("U");
  83. case Character("K"):
  84. return Character("I");
  85. default:
  86. return inputChar;
  87. }
  88. }
  89.  
  90. var res = gaderyPoluki("G");
  91. res = gaderyPoluki("D");
  92. res = gaderyPoluki("R");
  93. res = gaderyPoluki("P");
  94. res = gaderyPoluki("L");
  95. res = gaderyPoluki("K");
  96.  
  97. func cipher(_ toCipher: String, _ cipherFunc: (Character) -> Character) -> String {
  98. var upper: String = toCipher.uppercased();
  99. var upperChars: [String]() = upper.split(separator: "");
  100. var ciphered: String = "";
  101. for i in 0...upperChars.count {
  102. var char = Character( upperChars[i] );
  103. ciphered.append( String( cipherFunc( char ) ) );
  104. }
  105. return ciphered;
  106. }
  107.  
  108. var toCipher: String = "gaderypoluki";
  109. var ciphered = cipher( toCipher, gaderyPoluki(_:));
  110.  
  111. extension String {
  112.  
  113. var length: Int {
  114. return count
  115. }
  116.  
  117. subscript (i: Int) -> String {
  118. return self[i ..< i + 1]
  119. }
  120.  
  121. func substring(fromIndex: Int) -> String {
  122. return self[min(fromIndex, length) ..< length]
  123. }
  124.  
  125. func substring(toIndex: Int) -> String {
  126. return self[0 ..< max(0, toIndex)]
  127. }
  128.  
  129. subscript (r: Range<Int>) -> String {
  130. let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
  131. upper: min(length, max(0, r.upperBound))))
  132. let start = index(startIndex, offsetBy: range.lowerBound)
  133. let end = index(start, offsetBy: range.upperBound - range.lowerBound)
  134. return String(self[start ..< end])
  135. }
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement