Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
634B

  1. func memory_generateConstPlayfield(
  2. _ n: Int
  3. ) -> [Int: Int] {
  4. var idGroups = [Int: Int]()
  5. var id = 0
  6. for gid in stride(from: 0, to: n, by: 1) {
  7. idGroups[id] = gid
  8. id += 1
  9. idGroups[id] = gid
  10. id += 1
  11. }
  12. return idGroups
  13. }
  14. func test_memory_generateConstPlayfield() -> String {
  15. let idGroups = memory_generateConstPlayfield(2)
  16. if (
  17. idGroups.count == 4 &&
  18. idGroups[0] == 0 &&
  19. idGroups[1] == 0 &&
  20. idGroups[2] == 1 &&
  21. idGroups[3] == 1
  22. ) {
  23. return "OK: memory_generateConstPlayfield"
  24. }
  25. return "ERR: memory_generateConstPlayfield"
  26. }
  27. print(test_memory_generateConstPlayfield())