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.

main.swift 679B

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