New Immissions/Updates:
boundless - educate - edutalab - empatico - es-ebooks - es16 - fr16 - fsfiles - hesperian - solidaria - wikipediaforschools
- wikipediaforschoolses - wikipediaforschoolsfr - wikipediaforschoolspt - worldmap -

See also: Liber Liber - Libro Parlato - Liber Musica  - Manuzio -  Liber Liber ISO Files - Alphabetical Order - Multivolume ZIP Complete Archive - PDF Files - OGG Music Files -

PROJECT GUTENBERG HTML: Volume I - Volume II - Volume III - Volume IV - Volume V - Volume VI - Volume VII - Volume VIII - Volume IX

Ascolta ""Volevo solo fare un audiolibro"" su Spreaker.
CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
The five pillars puzzle - Wikipedia, the free encyclopedia

The five pillars puzzle

From Wikipedia, the free encyclopedia

The five pillars puzzle is a mechanical puzzle in which one is to try to remove a string from a structure of five threaded pillars. The following image illustrates this structure:

image:five_pillars_puzzle.png


[edit] A software solution

Apparently, there a general solution for this problem using a mutual recursion (Please note the number of each pillar in the image). The implementation is in C++ but it can be easly converted to any programming language.

 
#include <iostream> 
using namespace std; 


void printRange(int n) {
  if (n==1)
    cout << 1 << "\n"; 
  else 
    cout << n << ".." << 1 <<"\n"; 
}

void insert(int n); 

void release_(int c) {
  if(c==1) 
    return;  
  cout << "Thread through (upwards) ring number " << c << " (stick to the right)\n";
  insert(c-1); 
  release_(c-1); 
}

void release(int n) {
  release_(n); 
  cout << "Remove from ";
  printRange(n);
}

void insert_(int c, int n) {
  if(c==n)
    return;  
  cout << "Thread through (upwards) ring number " << c+1 << " (stick to the left)\n";
  release(c);
  insert_(c+1,n);
} 

void insert(int n) {
  cout << "Put over ";
  printRange(n);
  insert_(1,n);
}

int main() {
  int n; 
  while(true) {
    cout << "\nnumber of pillars? (0 = quit)  ";
    cin >> n ;
    if(n<1)
      break;
    cout << "insert "<<n<<":\n-------\n";
    insert(n); 
    cout << "\n\nrelease "<<n<<":\n-------\n";
    release(n); 
  }
}

[edit] Execution example

number of pillars? (0 = quit)  3
3
insert 3:
-------
Put over 3..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 3 (stick to the left)
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 2..1


release 3:
-------
Thread through (upwards) ring number 3 (stick to the right)
Put over 2..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 3..1

number of pillars? (0 = quit)  5
5
insert 5:
-------
Put over 5..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 3 (stick to the left)
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 2..1
Thread through (upwards) ring number 4 (stick to the left)
Thread through (upwards) ring number 3 (stick to the right)
Put over 2..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 3..1
Thread through (upwards) ring number 5 (stick to the left)
Thread through (upwards) ring number 4 (stick to the right)
Put over 3..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 3 (stick to the left)
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 2..1
Thread through (upwards) ring number 3 (stick to the right)
Put over 2..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 4..1


release 5:
-------
Thread through (upwards) ring number 5 (stick to the right)
Put over 4..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 3 (stick to the left)
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 2..1
Thread through (upwards) ring number 4 (stick to the left)
Thread through (upwards) ring number 3 (stick to the right)
Put over 2..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 3..1
Thread through (upwards) ring number 4 (stick to the right)
Put over 3..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 3 (stick to the left)
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 2..1
Thread through (upwards) ring number 3 (stick to the right)
Put over 2..1
Thread through (upwards) ring number 2 (stick to the left)
Remove from 1
Thread through (upwards) ring number 2 (stick to the right)
Put over 1
Remove from 5..1

number of pillars? (0 = quit)  0

[edit] Notes

  • Actually, the code can solve any intermediate stage by invoking the proper release_(...)/insert_(...) function.

Static Wikipedia (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2006 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia February 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu