Author Topic: Re: Let's play a game, pals.  (Read 3684 times)

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
Re: Let's play a game, pals.
« on: 19 August 2005, 17:02 »
I figured that no one cared for this thread. It seems that I was incorrect. Next challenge:

Fill an n by n array in the following manner:



For example, suppose that n = 3. Your program should create the following array:

[[1 2 3]
 [8 9 4]
 [7 6 5]]

solemnwarning

  • Member
  • **
  • Posts: 747
  • Kudos: 338
    • http://www.solemnwarning.net
Re: Let's play a game, pals.
« Reply #1 on: 19 August 2005, 19:42 »
Code: [Select]
#!/usr/bin/perl

print "n? ";
$n = ;
chomp($n);

if($n == "3") {
  open(TEMP, ">/tmp/array");
  print TEMP "1 2 3\n";
  print TEMP "8 9 4\n";
  print TEMP "7 6 5";
  close(TEMP);
  open(TEMP, "  @array = ;
  close(TEMP);
}

#The array is @array

is this what you mean?
-----BEGIN GEEK CODE BLOCK-----
 Version: 3.1
 GCS/CM d- s+:+ a--- C++ UL++++>$ P+ L+++ !E W++ !N !o !K-- w !O !M !V PS+ PE- !Y !PGP !t !5 !X !R tv b+ DI+ !D G e- h !r y-
 ------END GEEK CODE BLOCK------

KernelPanic

  • VIP
  • Member
  • ***
  • Posts: 1,878
  • Kudos: 222
Re: Let's play a game, pals.
« Reply #2 on: 19 August 2005, 20:01 »
Quote from: solemnwarning

is this what you mean?


 :rolleyes:
Contains scenes of mild peril.

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: Let's play a game, pals.
« Reply #3 on: 19 August 2005, 22:19 »
for any positive integer x,

x + (x+1) = (x+1)^2 - x^2

example:
6 + 7 = 49 - 36

try it, it works.

I made this up all by myself.

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: Let's play a game, pals.
« Reply #4 on: 19 August 2005, 22:23 »
I don't understand how to navigate through the square maze :(

Making an array is easy enough, I guess.  But I don't see the pattern in the circular motion.

Laukev7

  • VIP
  • Member
  • ***
  • Posts: 2,834
  • Kudos: 495
Re: Let's play a game, pals.
« Reply #5 on: 19 August 2005, 23:19 »
It's simple, worker201.

 
Code: [Select]
1 -> 2 -> 3
    |
    V
 8 -> 9 4
 ^ |
  | V
 7 <- 6 <- 5
 


 or for n=4

 
Code: [Select]
1 -> 2 -> 3 -> 4
  |
    V
12-> 13-> 14       5
  ^  | |
  | V V
 11       16<- 15       6
 ^  |
  |  V
 10<- 9 <- 8 <- 7
« Last Edit: 19 August 2005, 23:33 by Laukev7 »

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: Let's play a game, pals.
« Reply #6 on: 19 August 2005, 23:34 »
That's even more confusing (an ascii art issue)

Laukev7

  • VIP
  • Member
  • ***
  • Posts: 2,834
  • Kudos: 495
Re: Let's play a game, pals.
« Reply #7 on: 19 August 2005, 23:49 »

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: Let's play a game, pals.
« Reply #8 on: 20 August 2005, 00:29 »
Oh, ok.  I kinda get it now.

Nobody post an answer to this, because I want to take a couple days to figure it out.

KernelPanic

  • VIP
  • Member
  • ***
  • Posts: 1,878
  • Kudos: 222
Re: Let's play a game, pals.
« Reply #9 on: 20 August 2005, 00:37 »
Quote from: worker201
Oh, ok.  I kinda get it now.

Nobody post an answer to this, because I want to take a couple days to figure it out.


Yes, me too.
Contains scenes of mild peril.

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: Let's play a game, pals.
« Reply #10 on: 20 August 2005, 01:08 »
learning a language to create and populate the arrays looks like the tricky part...

Pathos

  • Member
  • **
  • Posts: 518
  • Kudos: 416
Re: Let's play a game, pals.
« Reply #11 on: 20 August 2005, 04:57 »
It shouldn't take longer than 2 mins to work out the strategy to do it.
It can be very tricky so just set small goals that show your strategy is working.

Think Recursively... What it being repeated?
Then you just need to work out the base steps and how to implement the recursion.

I didn't use an actual 2d dimensional array, I simulated one with a 1d array (n*n) if that helps.

solemnwarning

  • Member
  • **
  • Posts: 747
  • Kudos: 338
    • http://www.solemnwarning.net
Re: Let's play a game, pals.
« Reply #12 on: 20 August 2005, 17:02 »
i already posted answer
-----BEGIN GEEK CODE BLOCK-----
 Version: 3.1
 GCS/CM d- s+:+ a--- C++ UL++++>$ P+ L+++ !E W++ !N !o !K-- w !O !M !V PS+ PE- !Y !PGP !t !5 !X !R tv b+ DI+ !D G e- h !r y-
 ------END GEEK CODE BLOCK------

muzzy

  • Member
  • **
  • Posts: 391
  • Kudos: 409
    • http://muzzy.net/
Re: Let's play a game, pals.
« Reply #13 on: 20 August 2005, 18:21 »
oh c'mon. there are lots of trivial solutions to this spiral thing. you can just write code to do it the way you'd do it on paper.

i suppose i could write a solution for you, but i don't want to spoil the fun if you want to solve it on your own :)

also, recursion isn't the best approach imo, i'd go for a simple state machine with iteration.

KernelPanic

  • VIP
  • Member
  • ***
  • Posts: 1,878
  • Kudos: 222
Re: Let's play a game, pals.
« Reply #14 on: 21 August 2005, 00:29 »
This is very kludgy, and done in bash. (Doesn't format the results properly)
Please don't laugh!  :rolleyes:


When I finish my degree I will be better.
Honest. :D

[verwijderd door de beheerder]
« Last Edit: 21 August 2005, 00:38 by KernelPanic »
Contains scenes of mild peril.